feat: enhance error handling for unauthorized API calls
Implements automatic token removal and redirection to login upon 401 error status, improving user experience and security.
This commit is contained in:
parent
d8c92aa7a1
commit
05eb3bfca3
@ -7,6 +7,10 @@ export function useAPI(api: string, options?: object): Promise<unknown> {
|
||||
Authorization: `Bearer ${localStorage.getItem('SinkSiteToken') || ''}`,
|
||||
},
|
||||
})).catch((error) => {
|
||||
if (error?.status === 401) {
|
||||
localStorage.removeItem('SinkSiteToken')
|
||||
navigateTo('/dashboard/login')
|
||||
}
|
||||
if (error?.data?.statusMessage) {
|
||||
toast(error?.data?.statusMessage)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user