From caaea253ed910291c75ab542f498e27a5dbbbed6 Mon Sep 17 00:00:00 2001 From: Peter Phanouvong Date: Mon, 28 Oct 2024 11:36:35 +1100 Subject: [PATCH 1/2] types: fix permission types and userOrg default value --- src/config/{index.js => index.ts} | 16 ++++++++++------ types.d.ts | 4 ++-- 2 files changed, 12 insertions(+), 8 deletions(-) rename src/config/{index.js => index.ts} (90%) diff --git a/src/config/index.js b/src/config/index.ts similarity index 90% rename from src/config/index.js rename to src/config/index.ts index cec9bb2f..8bd9d4cf 100644 --- a/src/config/index.js +++ b/src/config/index.ts @@ -1,10 +1,8 @@ import {version} from '../utils/version'; import {removeTrailingSlash} from '../utils/removeTrailingSlash'; +import {KindeState} from '../../types'; -/** - * @type {import('../../types').KindeState} - */ -const initialState = { +const initialState: KindeState = { accessToken: null, idToken: null, isAuthenticated: false, @@ -12,7 +10,7 @@ const initialState = { organization: null, permissions: [], user: null, - userOrganizations: [], + userOrganizations: null, getAccessToken: () => null, getBooleanFlag: () => null, getClaim: () => null, @@ -26,7 +24,13 @@ const initialState = { getToken: () => null, getUser: () => null, getUserOrganizations: () => null, - refreshData: () => null + refreshData: () => null, + accessTokenEncoded: null, + accessTokenRaw: null, + idTokenRaw: null, + idTokenEncoded: null, + getAccessTokenRaw: () => null, + getIdTokenRaw: () => null }; const SESSION_PREFIX = 'pkce-verifier'; diff --git a/types.d.ts b/types.d.ts index 004ac4b2..ca82e245 100644 --- a/types.d.ts +++ b/types.d.ts @@ -303,7 +303,7 @@ export type KindeState = { isAuthenticated: boolean | null; isLoading: boolean | null; organization: KindeOrganization; - permissions: KindePermissions; + permissions: KindePermissions | []; user: { id: string; email: string | null; @@ -337,7 +337,7 @@ export type KindeState = { getPermission: ( key: string ) => {isGranted: boolean; orgCode: string | null} | null; - getPermissions: () => KindePermissions; + getPermissions: () => KindePermissions | []; getStringFlag: ( code: string, defaultValue: string From a29e63c160242f977b22774866933ec215555bcb Mon Sep 17 00:00:00 2001 From: Peter Phanouvong Date: Wed, 13 Nov 2024 10:47:38 +1100 Subject: [PATCH 2/2] chore:specific union type for permissions --- types.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types.d.ts b/types.d.ts index ca82e245..60bb6a3b 100644 --- a/types.d.ts +++ b/types.d.ts @@ -303,7 +303,7 @@ export type KindeState = { isAuthenticated: boolean | null; isLoading: boolean | null; organization: KindeOrganization; - permissions: KindePermissions | []; + permissions: KindePermissions | {permissions: []; orgCode: null}; user: { id: string; email: string | null; @@ -337,7 +337,7 @@ export type KindeState = { getPermission: ( key: string ) => {isGranted: boolean; orgCode: string | null} | null; - getPermissions: () => KindePermissions | []; + getPermissions: () => KindePermissions | {permissions: []; orgCode: null}; getStringFlag: ( code: string, defaultValue: string