From 132237b52feacb37cb7f86519f75eebf9fb6b4fd Mon Sep 17 00:00:00 2001 From: Tal Date: Thu, 21 Nov 2024 11:34:46 +0200 Subject: [PATCH] fix: tenantId in new auth with Auth0 (#2569) --- keep-ui/auth.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/keep-ui/auth.ts b/keep-ui/auth.ts index eab94b875..159de7439 100644 --- a/keep-ui/auth.ts +++ b/keep-ui/auth.ts @@ -197,12 +197,20 @@ const config = { } return true; }, - jwt: async ({ token, user, account }): Promise => { + jwt: async ({ token, user, account, profile }): Promise => { if (account && user) { let accessToken: string | undefined; + let tenantId: string | undefined = user.tenantId; + let role: string | undefined = user.role; // Ensure we always have an accessToken if (authType == AuthType.AUTH0) { accessToken = account.id_token; + if ((profile as any)?.keep_tenant_id) { + tenantId = (profile as any).keep_tenant_id; + } + if ((profile as any)?.keep_role) { + role = (profile as any).keep_role; + } } else { accessToken = user.accessToken || account.access_token || account.id_token; @@ -212,8 +220,8 @@ const config = { } token.accessToken = accessToken; - token.tenantId = user.tenantId; - token.role = user.role; + token.tenantId = tenantId; + token.role = role; if (authType === AuthType.KEYCLOAK) { token.refreshToken = account.refresh_token;