fix: handle UNAUTHORIZED responses by clearing session and reloading

This commit is contained in:
Björn Blomberg
2026-04-10 18:56:26 +02:00
parent 772a01c9be
commit 41dc1d9988

View File

@@ -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
}