mirror of
https://github.com/hay-kot/homebox.git
synced 2025-08-05 09:10:26 +00:00
fix session clearing on error
This commit is contained in:
parent
ed1230e17d
commit
29f2f7bcfe
2 changed files with 6 additions and 1 deletions
|
@ -34,6 +34,7 @@ export function useUserApi(): UserClient {
|
|||
requests.addResponseInterceptor(logger);
|
||||
requests.addResponseInterceptor(r => {
|
||||
if (r.status === 401) {
|
||||
console.error("unauthorized request, invalidating session");
|
||||
authCtx.invalidateSession();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -2,10 +2,14 @@ export default defineNuxtRouteMiddleware(async () => {
|
|||
const ctx = useAuthContext();
|
||||
const api = useUserApi();
|
||||
|
||||
if (!ctx.isAuthorized()) {
|
||||
return navigateTo("/");
|
||||
}
|
||||
|
||||
if (!ctx.user) {
|
||||
const { data, error } = await api.user.self();
|
||||
if (error) {
|
||||
navigateTo("/");
|
||||
return navigateTo("/");
|
||||
}
|
||||
|
||||
ctx.user = data.item;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue