mirror of
https://github.com/hay-kot/homebox.git
synced 2025-08-06 09:30:29 +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(logger);
|
||||||
requests.addResponseInterceptor(r => {
|
requests.addResponseInterceptor(r => {
|
||||||
if (r.status === 401) {
|
if (r.status === 401) {
|
||||||
|
console.error("unauthorized request, invalidating session");
|
||||||
authCtx.invalidateSession();
|
authCtx.invalidateSession();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,10 +2,14 @@ export default defineNuxtRouteMiddleware(async () => {
|
||||||
const ctx = useAuthContext();
|
const ctx = useAuthContext();
|
||||||
const api = useUserApi();
|
const api = useUserApi();
|
||||||
|
|
||||||
|
if (!ctx.isAuthorized()) {
|
||||||
|
return navigateTo("/");
|
||||||
|
}
|
||||||
|
|
||||||
if (!ctx.user) {
|
if (!ctx.user) {
|
||||||
const { data, error } = await api.user.self();
|
const { data, error } = await api.user.self();
|
||||||
if (error) {
|
if (error) {
|
||||||
navigateTo("/");
|
return navigateTo("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.user = data.item;
|
ctx.user = data.item;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue