localStorage

This commit is contained in:
ACoolName 2023-12-29 13:39:44 +02:00
parent 8fb9337270
commit b8cebf8c5c
2 changed files with 3 additions and 3 deletions

View File

@ -82,14 +82,14 @@ console.log(process.env)
export function ApiWrapper(p: { children: ReactNode}) {
const {children} = p
const token = localStorage.get('token')
const token = localStorage.getItem('token')
if (token) {
api.defaults.headers.common.Authorization = `Bearer ${token}`;
}
const [apiAuthenticated, setApiAuthenticated] = useState(Boolean(token))
if (!apiAuthenticated) {
localStorage.remove('token')
localStorage.removeItem('token')
}
const path = useLocation()
return (<apiAuthenticatedContext.Provider value={[apiAuthenticated, setApiAuthenticated]}>

View File

@ -41,7 +41,7 @@ export function LoginPage(props: {}) {
fetchToken(username, password, Boolean(data.get('remember'))).then(
(token) => {
api.defaults.headers.common.Authorization = `Bearer ${token}`;
localStorage.set('token', token)
localStorage.setItem('token', token)
setApiAuthenticated(true)
},
(error) => {