homebox/frontend/middleware/auth.ts
Hayden 12975ce26e
feat: change auth to use cookies (#301)
* frontend cookie implementation

* accept cookies for authentication

* remove auth store

* add self attr
2023-02-17 21:57:21 -09:00

13 lines
267 B
TypeScript

export default defineNuxtRouteMiddleware(async () => {
const ctx = useAuthContext();
const api = useUserApi();
if (!ctx.user) {
const { data, error } = await api.user.self();
if (error) {
navigateTo("/");
}
ctx.user = data.item;
}
});