From fc5c316d544dda3c023019ee4af4fc3231e9db72 Mon Sep 17 00:00:00 2001 From: dfahlander Date: Wed, 9 Aug 2023 11:50:03 +0200 Subject: [PATCH] Reveal license information in currentUser --- .../src/authentication/authenticate.ts | 21 +++++++++++++++++++ .../dexie-cloud/src/db/entities/UserLogin.ts | 6 ++++++ libs/dexie-cloud-common/src/types.ts | 4 ++++ 3 files changed, 31 insertions(+) diff --git a/addons/dexie-cloud/src/authentication/authenticate.ts b/addons/dexie-cloud/src/authentication/authenticate.ts index ebcb10904..3a7256592 100644 --- a/addons/dexie-cloud/src/authentication/authenticate.ts +++ b/addons/dexie-cloud/src/authentication/authenticate.ts @@ -118,6 +118,17 @@ export async function refreshAccessToken( login.accessTokenExpiration = response.accessTokenExpiration ? new Date(response.accessTokenExpiration) : undefined; + login.claims = response.claims; + login.license = { + type: response.userType, + status: response.claims.license, + } + if (response.evalDaysLeft != null) { + login.license.evalDaysLeft = response.evalDaysLeft; + } + if (response.userValidUntil != null) { + login.license.validUntil = new Date(response.userValidUntil); + } return login; } @@ -174,6 +185,16 @@ async function userAuthenticate( context.email = response2.claims.email; context.name = response2.claims.name; context.claims = response2.claims; + context.license = { + type: response2.userType, + status: response2.claims.license, + } + if (response2.evalDaysLeft != null) { + context.license.evalDaysLeft = response2.evalDaysLeft; + } + if (response2.userValidUntil != null) { + context.license.validUntil = new Date(response2.userValidUntil); + } if (response2.alerts && response2.alerts.length > 0) { await interactWithUser(userInteraction, { diff --git a/addons/dexie-cloud/src/db/entities/UserLogin.ts b/addons/dexie-cloud/src/db/entities/UserLogin.ts index e5e08fddd..093f75ca9 100644 --- a/addons/dexie-cloud/src/db/entities/UserLogin.ts +++ b/addons/dexie-cloud/src/db/entities/UserLogin.ts @@ -7,6 +7,12 @@ export interface UserLogin { claims: { [claimName: string]: any; } + license: { + type: 'demo' | 'eval' | 'prod'; + status: 'ok' | 'expired' | 'deactivated'; + validUntil?: Date; + evalDaysLeft?: number; + } lastLogin: Date; accessToken?: string; accessTokenExpiration?: Date; diff --git a/libs/dexie-cloud-common/src/types.ts b/libs/dexie-cloud-common/src/types.ts index b5814cc3d..d38b0eac8 100644 --- a/libs/dexie-cloud-common/src/types.ts +++ b/libs/dexie-cloud-common/src/types.ts @@ -50,12 +50,16 @@ export interface TokenFinalResponse { type: 'tokens'; claims: { sub: string; + license: 'ok' | 'expired' | 'deactivated'; [claimName: string]: any; }; accessToken: string; accessTokenExpiration: number; refreshToken?: string; refreshTokenExpiration?: number | null; + userType: 'demo' | 'eval' | 'prod'; + evalDaysLeft?: number; + userValidUntil?: number; alerts?: { type: 'warning' | 'info'; messageCode: string;