Skip to content

Commit

Permalink
Reveal license information in currentUser
Browse files Browse the repository at this point in the history
  • Loading branch information
dfahlander committed Aug 9, 2023
1 parent 60abec6 commit fc5c316
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
21 changes: 21 additions & 0 deletions addons/dexie-cloud/src/authentication/authenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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, {
Expand Down
6 changes: 6 additions & 0 deletions addons/dexie-cloud/src/db/entities/UserLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions libs/dexie-cloud-common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fc5c316

Please sign in to comment.