From 40da39d92930ec0fdb64c5bd7b1635f9b4b74790 Mon Sep 17 00:00:00 2001 From: "@greweb" Date: Thu, 18 Jul 2024 17:16:34 +0200 Subject: [PATCH] fix(trustchain): invalid jwt token if trustchain/memberCredentials changes (#7358) --- libs/trustchain/src/sdk.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libs/trustchain/src/sdk.ts b/libs/trustchain/src/sdk.ts index 64150af656e8..a8aa6987dc7a 100644 --- a/libs/trustchain/src/sdk.ts +++ b/libs/trustchain/src/sdk.ts @@ -38,8 +38,6 @@ import { TrustchainEjected, TrustchainNotAllowed } from "./errors"; export class SDK implements TrustchainSDK { private context: TrustchainSDKContext; - private jwt: JWT | undefined = undefined; - private deviceJwt: JWT | undefined = undefined; private lifecycle?: TrustchainLifecycle; constructor(context: TrustchainSDKContext, lifecyle?: TrustchainLifecycle) { @@ -47,12 +45,19 @@ export class SDK implements TrustchainSDK { this.lifecycle = lifecyle; } + private jwt: JWT | undefined = undefined; + private jwtHash = ""; withAuth( trustchain: Trustchain, memberCredentials: MemberCredentials, job: (jwt: JWT) => Promise, policy?: AuthCachePolicy, ): Promise { + const hash = trustchain.rootId + " " + memberCredentials.pubkey; + if (this.jwtHash !== hash) { + this.jwt = undefined; + this.jwtHash = hash; + } return genericWithJWT( jwt => { this.jwt = jwt; @@ -64,6 +69,7 @@ export class SDK implements TrustchainSDK { ); } + private deviceJwt: JWT | undefined = undefined; withDeviceAuth( transport: Transport, job: (jwt: JWT) => Promise,