File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
src/contexts/RoflAppBackendAuth Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -12,13 +12,26 @@ export function RoflAppBackendAuthProvider({ children }: { children: ReactNode }
1212 const { signMessageAsync } = useSignMessage ( )
1313 const chainId = useChainId ( )
1414
15- const [ token , setToken ] = useState < string | null > ( null )
15+ const [ token , _setToken ] = useState < string | null > (
16+ // TODO: possibly already expired or from another account. Currently detected by useInterval within a few seconds.
17+ window . localStorage . getItem ( 'jwt' )
18+ )
1619 const [ isLoading , setIsLoading ] = useState ( false )
1720 const [ error , setError ] = useState < string | null > ( null )
1821
1922 const { refetch : refetchNonce } = useGetNonce ( isConnected ? address : undefined )
2023 const { mutateAsync : loginMutationAsync } = useLogin ( )
2124
25+ const setToken = ( token : string | null ) => {
26+ _setToken ( token )
27+ try {
28+ if ( token ) window . localStorage . setItem ( 'jwt' , token )
29+ else window . localStorage . removeItem ( 'jwt' )
30+ } catch {
31+ // Ignore failures like Safari incognito
32+ }
33+ }
34+
2235 const getSiweMessage = useCallback ( ( address : `0x${string } `, nonce : string , chainId : number ) : string => {
2336 const domain = PROD ? window . location . hostname : 'dev.rofl.app'
2437 const uri = `https://${ domain } `
You can’t perform that action at this time.
0 commit comments