[F] Fix token invalidation

pull/17/head
Azalea 2024-03-03 12:24:20 -05:00
parent 279bcbfeab
commit c0437e55eb
1 changed files with 6 additions and 8 deletions

View File

@ -64,14 +64,6 @@ export async function post(endpoint: string, params: any, init?: RequestInitWith
}).catch(e => {
console.error(e)
// If 400 invalid token is caught, should invalidate the token and redirect to signin
if (e.message === 'Invalid token') {
// Invalidate token
localStorage.removeItem('token')
// Redirect to signin
window.location.href = '/'
}
throw new Error('Network error')
})
@ -79,6 +71,12 @@ export async function post(endpoint: string, params: any, init?: RequestInitWith
const text = await res.text()
console.error(`${res.status}: ${text}`)
// If 400 invalid token is caught, should invalidate the token and redirect to signin
if (text === 'Invalid token') {
localStorage.removeItem('token')
window.location.href = '/'
}
// Try to parse as json
let json
try {