forked from mirrors/homebox
feat: change auth to use cookies (#301)
* frontend cookie implementation * accept cookies for authentication * remove auth store * add self attr
This commit is contained in:
parent
bd321af29f
commit
12975ce26e
9 changed files with 204 additions and 86 deletions
|
@ -1,15 +1,13 @@
|
|||
import { useAuthStore } from "~~/stores/auth";
|
||||
|
||||
export default defineNuxtRouteMiddleware(async () => {
|
||||
const auth = useAuthStore();
|
||||
const ctx = useAuthContext();
|
||||
const api = useUserApi();
|
||||
|
||||
if (!auth.self) {
|
||||
if (!ctx.user) {
|
||||
const { data, error } = await api.user.self();
|
||||
if (error) {
|
||||
navigateTo("/");
|
||||
}
|
||||
|
||||
auth.$patch({ self: data.item });
|
||||
ctx.user = data.item;
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue