changed cookie to localstorage
This commit is contained in:
parent
5ab29611f8
commit
8fb9337270
@ -82,14 +82,14 @@ console.log(process.env)
|
|||||||
|
|
||||||
export function ApiWrapper(p: { children: ReactNode}) {
|
export function ApiWrapper(p: { children: ReactNode}) {
|
||||||
const {children} = p
|
const {children} = p
|
||||||
const token = Cookies.get('token')
|
const token = localStorage.get('token')
|
||||||
if (token) {
|
if (token) {
|
||||||
api.defaults.headers.common.Authorization = `Bearer ${token}`;
|
api.defaults.headers.common.Authorization = `Bearer ${token}`;
|
||||||
|
|
||||||
}
|
}
|
||||||
const [apiAuthenticated, setApiAuthenticated] = useState(Boolean(token))
|
const [apiAuthenticated, setApiAuthenticated] = useState(Boolean(token))
|
||||||
if (!apiAuthenticated) {
|
if (!apiAuthenticated) {
|
||||||
Cookies.remove('token', { path: '/', domain: 'games.acooldomain.co' })
|
localStorage.remove('token')
|
||||||
}
|
}
|
||||||
const path = useLocation()
|
const path = useLocation()
|
||||||
return (<apiAuthenticatedContext.Provider value={[apiAuthenticated, setApiAuthenticated]}>
|
return (<apiAuthenticatedContext.Provider value={[apiAuthenticated, setApiAuthenticated]}>
|
||||||
|
@ -41,7 +41,7 @@ export function LoginPage(props: {}) {
|
|||||||
fetchToken(username, password, Boolean(data.get('remember'))).then(
|
fetchToken(username, password, Boolean(data.get('remember'))).then(
|
||||||
(token) => {
|
(token) => {
|
||||||
api.defaults.headers.common.Authorization = `Bearer ${token}`;
|
api.defaults.headers.common.Authorization = `Bearer ${token}`;
|
||||||
Cookies.set('token', token)
|
localStorage.set('token', token)
|
||||||
setApiAuthenticated(true)
|
setApiAuthenticated(true)
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user