[+] Automatically invalidate token on expiry

pull/14/head
Azalea 2024-02-21 17:42:42 -05:00
parent cac2f49b06
commit 79a078fb70
1 changed files with 9 additions and 0 deletions

View File

@ -45,6 +45,15 @@ export async function post(endpoint: string, params: any, init?: RequestInitWith
...init
}).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')
})