mirror of
https://github.com/hay-kot/homebox.git
synced 2024-12-22 14:56:31 +00:00
faed343eda
* fix session clearing on error * use singleton context to manage user state * implement remember-me functionality * fix errors * fix more errors
17 lines
336 B
TypeScript
17 lines
336 B
TypeScript
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) {
|
|
return navigateTo("/");
|
|
}
|
|
|
|
ctx.user = data.item;
|
|
}
|
|
});
|