Skip to content

Commit

Permalink
Catch expired ping
Browse files Browse the repository at this point in the history
  • Loading branch information
WietseWind committed Nov 9, 2022
1 parent 73cc139 commit d6f7729
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,24 @@ export class XummPkce extends EventEmitter {

if (existingJwt?.jwt && typeof existingJwt.jwt === "string") {
const sdk = new XummSdkJwt(existingJwt.jwt);
sdk.ping().then(async (pong) => {
/**
* Pretend mobile so no window.open is triggered
*/
if (pong?.jwtData?.sub) {
// Yay, user still signed in, JWT still valid!
this.autoResolvedFlow = Object.assign(existingJwt, { sdk });
this.emit("retrieved");
} else {
sdk
.ping()
.then(async (pong) => {
/**
* Pretend mobile so no window.open is triggered
*/
if (pong?.jwtData?.sub) {
// Yay, user still signed in, JWT still valid!
this.autoResolvedFlow = Object.assign(existingJwt, { sdk });
this.emit("retrieved");
} else {
this.logout();
}
})
.catch((e) => {
// That didn't work
this.logout();
}
});
});
}
} catch (e) {
// Do nothing
Expand Down

0 comments on commit d6f7729

Please sign in to comment.