forked from mirrors/homebox
fix: cookie-auth-issues (#365)
* fix session clearing on error * use singleton context to manage user state * implement remember-me functionality * fix errors * fix more errors
This commit is contained in:
parent
ed1230e17d
commit
faed343eda
24 changed files with 175 additions and 89 deletions
|
@ -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