@@ -102,17 +102,20 @@ type KindeCallbacks = {
102102 onEvent ?: EventTypes ;
103103} ;
104104
105+ type KindeAuthConfig = {
106+ domain : string | undefined ;
107+ clientId : string | undefined ;
108+ scopes ?: string ;
109+ enhancedSecurity ?: boolean ;
110+ } ;
111+
105112export const KindeAuthProvider = ( {
106113 children,
107114 config,
108115 callbacks,
109116} : {
110117 children : React . ReactNode ;
111- config : {
112- domain : string | undefined ;
113- clientId : string | undefined ;
114- scopes ?: string ;
115- } ;
118+ config : KindeAuthConfig ;
116119 callbacks ?: KindeCallbacks ;
117120} ) => {
118121 const domain = config . domain ;
@@ -225,40 +228,61 @@ export const KindeAuthProvider = ({
225228 { tokenEndpoint : `${ domain } /oauth2/token` } ,
226229 ) ;
227230
231+ const enhancedSecurity = config . enhancedSecurity || false ;
228232 if ( exchangeCodeResponse . idToken ) {
229- const idTokenValidationResult = await validateToken ( {
230- token : exchangeCodeResponse . idToken ,
231- domain : domain ,
232- } ) ;
233+ if ( enhancedSecurity ) {
234+ const idTokenValidationResult = await validateToken ( {
235+ token : exchangeCodeResponse . idToken ,
236+ domain : domain ,
237+ } ) ;
233238
234- if ( idTokenValidationResult . valid ) {
235- storage . setSessionItem (
239+ if ( idTokenValidationResult . valid ) {
240+ await storage . setSessionItem (
241+ StorageKeys . idToken ,
242+ exchangeCodeResponse . idToken ,
243+ ) ;
244+ } else {
245+ console . error (
246+ `Invalid id token` ,
247+ idTokenValidationResult . message ,
248+ ) ;
249+ }
250+ } else {
251+ await storage . setSessionItem (
236252 StorageKeys . idToken ,
237253 exchangeCodeResponse . idToken ,
238254 ) ;
239- } else {
240- console . error ( `Invalid id token` , idTokenValidationResult . message ) ;
241255 }
242256 }
243257
244- const accessTokenValidationResult = await validateToken ( {
245- token : exchangeCodeResponse . accessToken ,
246- domain : domain ,
247- } ) ;
248- if ( accessTokenValidationResult . valid ) {
249- storage . setSessionItem (
250- StorageKeys . accessToken ,
251- exchangeCodeResponse . accessToken ,
252- ) ;
253- setIsAuthenticated ( true ) ;
254- } else {
255- console . error (
256- `Invalid access token` ,
257- accessTokenValidationResult . message ,
258- ) ;
258+ if ( exchangeCodeResponse . accessToken ) {
259+ if ( enhancedSecurity ) {
260+ const accessTokenValidationResult = await validateToken ( {
261+ token : exchangeCodeResponse . accessToken ,
262+ domain : domain ,
263+ } ) ;
264+ if ( accessTokenValidationResult . valid ) {
265+ await storage . setSessionItem (
266+ StorageKeys . accessToken ,
267+ exchangeCodeResponse . accessToken ,
268+ ) ;
269+ setIsAuthenticated ( true ) ;
270+ } else {
271+ console . error (
272+ `Invalid access token` ,
273+ accessTokenValidationResult . message ,
274+ ) ;
275+ }
276+ } else {
277+ await storage . setSessionItem (
278+ StorageKeys . accessToken ,
279+ exchangeCodeResponse . accessToken ,
280+ ) ;
281+ setIsAuthenticated ( true ) ;
282+ }
259283 }
260284
261- storage . setSessionItem (
285+ await storage . setSessionItem (
262286 StorageKeys . refreshToken ,
263287 exchangeCodeResponse . refreshToken ,
264288 ) ;
0 commit comments