File tree Expand file tree Collapse file tree 4 files changed +62
-1
lines changed Expand file tree Collapse file tree 4 files changed +62
-1
lines changed Original file line number Diff line number Diff line change @@ -269,3 +269,6 @@ export {
269269 ChainIcon ,
270270 type ChainIconProps ,
271271} from "../react/web/ui/prebuilt/Chain/icon.js" ;
272+
273+ // Utils
274+ export { getLastAuthProvider } from "../react/web/utils/storage.js" ;
Original file line number Diff line number Diff line change 11import type { AsyncStorage } from "../../../utils/storage/AsyncStorage.js" ;
22import type { AuthArgsType } from "../../../wallets/in-app/core/authentication/types.js" ;
33
4- const LAST_AUTH_PROVIDER_STORAGE_KEY = "lastAuthProvider" ;
4+ export const LAST_AUTH_PROVIDER_STORAGE_KEY = "lastAuthProvider" ;
55
66export async function setLastAuthProvider (
77 authProvider : AuthArgsType [ "strategy" ] ,
Original file line number Diff line number Diff line change 1+ import { describe , expect , it , vi } from "vitest" ;
2+ import { webLocalStorage } from "../../../utils/storage/webStorage.js" ;
3+ import { LAST_AUTH_PROVIDER_STORAGE_KEY } from "../../core/utils/storage.js" ;
4+ import { getLastAuthProvider } from "./storage.js" ;
5+
6+ vi . mock ( "../../../utils/storage/webStorage.js" , ( ) => ( {
7+ webLocalStorage : {
8+ getItem : vi . fn ( ) . mockResolvedValueOnce ( "mockStrategy" ) ,
9+ } ,
10+ } ) ) ;
11+
12+ describe ( "getLastAuthProvider" , ( ) => {
13+ it ( "should return the last authentication provider strategy if it exists" , async ( ) => {
14+ const mockStrategy = "mockStrategy" ;
15+ webLocalStorage . getItem = vi . fn ( ) . mockResolvedValueOnce ( mockStrategy ) ;
16+
17+ const result = await getLastAuthProvider ( ) ;
18+ expect ( result ) . toBe ( mockStrategy ) ;
19+ } ) ;
20+
21+ it ( "should return null if no authentication provider strategy is found" , async ( ) => {
22+ webLocalStorage . getItem = vi . fn ( ) . mockResolvedValueOnce ( null ) ;
23+
24+ const result = await getLastAuthProvider ( ) ;
25+ expect ( result ) . toBeNull ( ) ;
26+ } ) ;
27+
28+ it ( "should call webLocalStorage.getItem with the correct key" , async ( ) => {
29+ await getLastAuthProvider ( ) ;
30+ expect ( webLocalStorage . getItem ) . toHaveBeenCalledWith (
31+ LAST_AUTH_PROVIDER_STORAGE_KEY ,
32+ ) ;
33+ } ) ;
34+ } ) ;
Original file line number Diff line number Diff line change 1+ import { webLocalStorage } from "../../../utils/storage/webStorage.js" ;
2+ import { getLastAuthProvider as getLastAuthProviderCore } from "../../core/utils/storage.js" ;
3+
4+ /**
5+ * Retrieves the last authentication provider used from local storage.
6+ *
7+ * This function is designed to work only in a browser environment, as it relies on
8+ * the `webLocalStorage` API, which is not available in non-browser contexts.
9+ *
10+ * @returns {Promise<AuthArgsType["strategy"] | null> } A promise that resolves to the last
11+ * authentication provider strategy used, or `null` if none is found.
12+ *
13+ * @example
14+ * ```typescript
15+ * import { getLastAuthProvider } from "thirdweb/react";
16+ *
17+ * const lastAuthProvider = await getLastAuthProvider();
18+ * ```
19+ *
20+ * @utils
21+ */
22+ export async function getLastAuthProvider ( ) {
23+ return getLastAuthProviderCore ( webLocalStorage ) ;
24+ }
You can’t perform that action at this time.
0 commit comments