From 029ccc19dbd2834528d6ea02a17713e212c7f6a2 Mon Sep 17 00:00:00 2001 From: p-stam001 Date: Wed, 19 Nov 2025 10:21:42 +0900 Subject: [PATCH 1/3] feat: update store function for web version --- lib/KindeAuthProvider.tsx | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/KindeAuthProvider.tsx b/lib/KindeAuthProvider.tsx index fc6fbb3..5f4295c 100644 --- a/lib/KindeAuthProvider.tsx +++ b/lib/KindeAuthProvider.tsx @@ -16,6 +16,8 @@ import { } from "@kinde/js-utils"; import { ExpoSecureStore, + LocalStorage, + MemoryStorage, mapLoginMethodParamsForUrl, PromptTypes, setActiveStorage, @@ -32,7 +34,11 @@ import { revokeAsync, TokenTypeHint, } from "expo-auth-session"; -import { openAuthSessionAsync, openBrowserAsync } from "expo-web-browser"; +import { + openAuthSessionAsync, + openBrowserAsync, + maybeCompleteAuthSession, +} from "expo-web-browser"; import { createContext, useEffect, @@ -52,6 +58,7 @@ import { KindeAuthHook } from "./useKindeAuth"; import { JWTDecoded, jwtDecoder } from "@kinde/jwt-decoder"; import Constants from "expo-constants"; import { decode, encode } from "base-64"; +import { Platform } from "react-native"; export const KindeAuthContext = createContext( undefined, ); @@ -63,6 +70,10 @@ if (typeof global !== "undefined") { global.atob = decode; } +if (Platform.OS === "web" && typeof window !== "undefined") { + maybeCompleteAuthSession(); +} + export type ErrorProps = { error: string; errorDescription: string; @@ -136,10 +147,25 @@ export const KindeAuthProvider = ({ const [isStorageReady, setIsStorageReady] = useState(false); useEffect(() => { + const getStorageInstance = async (): Promise => { + if (Platform.OS === "web") { + if (typeof window !== "undefined" && typeof window.localStorage !== "undefined") { + return new LocalStorage(); + } + + console.warn( + "[Kinde] Falling back to in-memory storage; session data will not persist between reloads.", + ); + return new MemoryStorage(); + } + + const ExpoStore = await ExpoSecureStore.default(); + return new ExpoStore(); + }; + const initializeStorage = async () => { try { - const ExpoStore = await ExpoSecureStore.default(); - const storageInstance = new ExpoStore(); + const storageInstance = await getStorageInstance(); setActiveStorage(storageInstance); setStorage(storageInstance); setIsStorageReady(true); From b4d9240e5d3b7340cf5f1fed7ab499d9de9eee76 Mon Sep 17 00:00:00 2001 From: p-stam001 Date: Wed, 19 Nov 2025 18:04:44 +0900 Subject: [PATCH 2/3] fix: localstorage test --- lib/KindeAuthProvider.tsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/KindeAuthProvider.tsx b/lib/KindeAuthProvider.tsx index 5f4295c..31475b6 100644 --- a/lib/KindeAuthProvider.tsx +++ b/lib/KindeAuthProvider.tsx @@ -149,12 +149,23 @@ export const KindeAuthProvider = ({ useEffect(() => { const getStorageInstance = async (): Promise => { if (Platform.OS === "web") { - if (typeof window !== "undefined" && typeof window.localStorage !== "undefined") { - return new LocalStorage(); + if (typeof window !== "undefined") { + if (typeof window !== "undefined") { + try { + // Test localStorage access (can throw in private browsing) + window.localStorage.setItem("__kinde_test__", "test"); + window.localStorage.removeItem("__kinde_test__"); + return new LocalStorage(); + } catch (e) { + console.warn( + "[Kinde] localStorage unavailable (private browsing or restricted cookies); falling back to in-memory storage." + ); + } + } } console.warn( - "[Kinde] Falling back to in-memory storage; session data will not persist between reloads.", + "[Kinde] Using in-memory storage; session data will not persist between reloads and is less secure than native SecureStore.", ); return new MemoryStorage(); } From 831dbedd199ed8cc59634808721b6d82055f0bb7 Mon Sep 17 00:00:00 2001 From: p-stam001 Date: Wed, 19 Nov 2025 19:51:04 +0900 Subject: [PATCH 3/3] fix: douplicated issue --- lib/KindeAuthProvider.tsx | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/KindeAuthProvider.tsx b/lib/KindeAuthProvider.tsx index 31475b6..1756bfb 100644 --- a/lib/KindeAuthProvider.tsx +++ b/lib/KindeAuthProvider.tsx @@ -150,17 +150,15 @@ export const KindeAuthProvider = ({ const getStorageInstance = async (): Promise => { if (Platform.OS === "web") { if (typeof window !== "undefined") { - if (typeof window !== "undefined") { - try { - // Test localStorage access (can throw in private browsing) - window.localStorage.setItem("__kinde_test__", "test"); - window.localStorage.removeItem("__kinde_test__"); - return new LocalStorage(); - } catch (e) { - console.warn( - "[Kinde] localStorage unavailable (private browsing or restricted cookies); falling back to in-memory storage." - ); - } + try { + // Test localStorage access (can throw in private browsing) + window.localStorage.setItem("__kinde_test__", "test"); + window.localStorage.removeItem("__kinde_test__"); + return new LocalStorage(); + } catch (e) { + console.warn( + "[Kinde] localStorage unavailable (private browsing or restricted cookies); falling back to in-memory storage." + ); } }