From c440f917a4a3c5ecfe7a82abd39de811230aec09 Mon Sep 17 00:00:00 2001 From: Dave Berner Date: Thu, 6 Jun 2024 10:12:27 +1000 Subject: [PATCH] feat: add options to always force refresh --- src/createKindeClient.ts | 18 +++++++++++------- src/types.ts | 4 ++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/createKindeClient.ts b/src/createKindeClient.ts index 34aa36d..811583e 100644 --- a/src/createKindeClient.ts +++ b/src/createKindeClient.ts @@ -27,7 +27,8 @@ import type { KindeState, KindeUser, OrgOptions, - RedirectOptions + RedirectOptions, + GetTokenOptions } from './types'; const createKindeClient = async ( @@ -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}); } @@ -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 () => { diff --git a/src/types.ts b/src/types.ts index cd5b805..8c877e9 100644 --- a/src/types.ts +++ b/src/types.ts @@ -88,6 +88,10 @@ export type AuthOptions = { authUrlParams?: object; }; +export type GetTokenOptions = { + isForceRefresh?: boolean; +}; + export type RedirectOptions = OrgOptions & AuthOptions & { prompt?: string;