fix: handle UNAUTHORIZED responses by clearing session and reloading
This commit is contained in:
@@ -16,9 +16,16 @@ export async function gql<T = unknown>(
|
||||
body: JSON.stringify({ query, variables }),
|
||||
})
|
||||
|
||||
const json = await res.json()
|
||||
const json = await res.json()
|
||||
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)
|
||||
}
|
||||
return json.data as T
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user