fix: auth retry
This commit is contained in:
1 parent
fbbd7b52e3
commit
bbae7abaf5
3 files changed
+17
-7
No files matched your search
+11
-2
@@ -1,8 +1,11 @@
|
||||
import { useCallback } from 'react';
|
||||
import { isServer } from '@tanstack/react-query';
|
||||
import { atom, useAtomValue, useSetAtom } from 'jotai';
|
||||
import Cookies from 'js-cookie';
|
||||
|
||||
const sessionAtom = atom<string | undefined>(Cookies.get('session') as string);
|
||||
const sessionAtom = atom<string | undefined>(
|
||||
(isServer ? Cookies.get('session') : localStorage.getItem('session')) as string
|
||||
);
|
||||
|
||||
export const useSession = () => useAtomValue(sessionAtom);
|
||||
|
||||
@@ -11,7 +14,13 @@ export const useSetSession = () => {
|
||||
|
||||
return useCallback(
|
||||
(session: string | undefined) => {
|
||||
typeof session === 'string' ? Cookies.set('session', session) : Cookies.remove('session');
|
||||
if (typeof session === 'string') {
|
||||
localStorage.setItem('session', session);
|
||||
Cookies.set('session', session);
|
||||
} else {
|
||||
localStorage.removeItem('session');
|
||||
Cookies.remove('session');
|
||||
}
|
||||
setSession(session);
|
||||
},
|
||||
[setSession]
|
||||
|
||||
Reference in new issue
Block a user