Skip to content

Commit

Permalink
Do not authorize again
Browse files Browse the repository at this point in the history
  • Loading branch information
WietseWind committed Nov 19, 2022
1 parent 9db10a0 commit 968447d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class XummPkceThread extends EventEmitter {
private jwt?: string;

private resolved = false;
private resolvedSuccessfully?: boolean;
private resolvePromise?: (result: ResolvedFlow) => void;
private rejectPromise?: (error: Error) => void;
private promise?: Promise<ResolvedFlow>;
Expand Down Expand Up @@ -329,6 +330,10 @@ export class XummPkceThread extends EventEmitter {
}

public async authorize() {
// Do not authorize twice
if (this.resolvedSuccessfully) {
return this.promise;
}
this.resolved = false;
if (!this.mobileRedirectFlow && !this.autoResolvedFlow) {
const url = this.authorizeUrl();
Expand Down Expand Up @@ -382,6 +387,7 @@ export class XummPkceThread extends EventEmitter {
const resolved = resolve(_);
this.resolved = true;
log("Xumm Sign in RESOLVED");
this.resolvedSuccessfully = true;
this.emit("success");
return resolved;
};
Expand All @@ -405,6 +411,7 @@ export class XummPkceThread extends EventEmitter {
public logout() {
try {
this.resolved = false;
this.resolvedSuccessfully = undefined;
this.autoResolvedFlow = undefined;
this.options.storage?.removeItem("XummPkceJwt");
} catch (e) {
Expand Down

0 comments on commit 968447d

Please sign in to comment.