fix: handle UNAUTHORIZED responses by clearing session and reloading
This commit is contained in:
@@ -18,7 +18,14 @@ export async function gql<T = unknown>(
|
|||||||
|
|
||||||
const json = await res.json()
|
const json = await res.json()
|
||||||
if (json.errors?.length) {
|
if (json.errors?.length) {
|
||||||
|
if (json.errors[0].message === 'UNAUTHORIZED') {
|
||||||
|
localStorage.removeItem('token')
|
||||||
|
localStorage.removeItem('username')
|
||||||
|
window.location.href = '/'
|
||||||
|
}
|
||||||
throw new Error(json.errors[0].message)
|
throw new Error(json.errors[0].message)
|
||||||
}
|
}
|
||||||
return json.data as T
|
return json.data as T
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user