Skip to content

Commit

Permalink
Merge pull request #66 from kinde-oss/feat/force-refresh-token
Browse files Browse the repository at this point in the history
Add options to getToken always force refresh
  • Loading branch information
DanielRivers authored Jun 6, 2024
2 parents 560ffd3 + c440f91 commit 1a6b7bb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/createKindeClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import type {
KindeState,
KindeUser,
OrgOptions,
RedirectOptions
RedirectOptions,
GetTokenOptions
} from './types';

const createKindeClient = async (
Expand Down Expand Up @@ -195,10 +196,13 @@ const createKindeClient = async (
}
};

const getTokenType = async (tokenType: storageMap) => {
const getTokenType = async (
tokenType: storageMap,
options: GetTokenOptions
) => {
const token = store.getItem(storageMap.token_bundle) as KindeState;

if (!token) {
if (!token || options.isForceRefresh) {
return await useRefreshToken({tokenType});
}

Expand All @@ -214,12 +218,12 @@ const createKindeClient = async (
}
};

const getToken = async () => {
return await getTokenType(storageMap.access_token);
const getToken = async (options: GetTokenOptions) => {
return await getTokenType(storageMap.access_token, options);
};

const getIdToken = async () => {
return await getTokenType(storageMap.id_token);
const getIdToken = async (options: GetTokenOptions) => {
return await getTokenType(storageMap.id_token, options);
};

const isAuthenticated = async () => {
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ export type AuthOptions = {
authUrlParams?: object;
};

export type GetTokenOptions = {
isForceRefresh?: boolean;
};

export type RedirectOptions = OrgOptions &
AuthOptions & {
prompt?: string;
Expand Down

0 comments on commit 1a6b7bb

Please sign in to comment.