diff --git a/package.json b/package.json index e61a8de..ccfc794 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xumm-oauth2-pkce", - "version": "2.7.7", + "version": "2.7.8", "description": "Xumm JS SDK for client side only OAuth2 PKCE (implicit flow) auth.", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -9,7 +9,7 @@ "clean": "rm -rf dist", "build": "tsc", "buildsample": "mkdir -p ./sample/dist; cp ./dist/browser.min.js ./sample/dist/", - "serve": "npm run build && npm run browserify && serve -C -n -p 3001 ./", + "serve": "npm run build && npm run browserify && serve -C -n -p 3002 ./", "watch": "tsc -w", "inspect": "clear && npm run build && node --inspect dist/samples/sample.js", "browserify": "browserify --standalone XummPkce -r ./dist/index.js:XummPkce |sed 's/\\(exports.XummPkce = XummPkce;\\)/\\1 module.exports = XummPkce;/g' > dist/browser.js && npm run minify", diff --git a/src/index.ts b/src/index.ts index 7a15e04..a9eb852 100644 --- a/src/index.ts +++ b/src/index.ts @@ -95,7 +95,7 @@ export class XummPkceThread extends EventEmitter { private jwt?: string; - private ping?: Promise; + private ping?: ReturnType; private resolved = false; private resolvedSuccessfully?: boolean; private resolvePromise?: (result: ResolvedFlow) => void; @@ -176,7 +176,7 @@ export class XummPkceThread extends EventEmitter { if (existingJwt?.jwt && typeof existingJwt.jwt === "string") { const sdk = new XummSdkJwt(existingJwt.jwt); - this.ping = sdk.ping(); + this.ping = sdk.ping() this.ping .then(async (pong) => { /** @@ -185,8 +185,8 @@ export class XummPkceThread extends EventEmitter { if (pong?.jwtData?.sub) { // Yay, user still signed in, JWT still valid! this.autoResolvedFlow = Object.assign(existingJwt, { sdk }); - this.emit("retrieved"); await this.authorize(); + this.emit("retrieved"); } else { this.logout(); } @@ -420,16 +420,15 @@ export class XummPkceThread extends EventEmitter { } public async authorize() { - if (this.options.rememberJwt) { - await Promise.race([this.ping, this.eventPromises.loggedout.promise]); - } - // Do not authorize twice if (this.resolvedSuccessfully) { return this.promise; } - + this.resolved = false; + + await this.ping + if (!this.mobileRedirectFlow && !this.autoResolvedFlow) { const url = this.authorizeUrl(); const popup = window.open(