diff --git a/frontend/layouts/default.vue b/frontend/layouts/default.vue index a65f7e3..1d87350 100644 --- a/frontend/layouts/default.vue +++ b/frontend/layouts/default.vue @@ -1,10 +1,70 @@ - + + diff --git a/frontend/layouts/home.vue b/frontend/layouts/home.vue deleted file mode 100644 index 9f0adc7..0000000 --- a/frontend/layouts/home.vue +++ /dev/null @@ -1,69 +0,0 @@ - - - diff --git a/frontend/middleware/auth.ts b/frontend/middleware/auth.ts new file mode 100644 index 0000000..f67fa01 --- /dev/null +++ b/frontend/middleware/auth.ts @@ -0,0 +1,15 @@ +import { useAuthStore } from "~~/stores/auth"; + +export default defineNuxtRouteMiddleware(async () => { + const auth = useAuthStore(); + const api = useUserApi(); + + if (!auth.self) { + const { data, error } = await api.user.self(); + if (error) { + navigateTo("/"); + } + + auth.$patch({ self: data.item }); + } +}); diff --git a/frontend/pages/home.vue b/frontend/pages/home.vue index c3a4819..8bf0a54 100644 --- a/frontend/pages/home.vue +++ b/frontend/pages/home.vue @@ -5,8 +5,9 @@ import { useLocationStore } from "~~/stores/locations"; definePageMeta({ - layout: "home", + middleware: ["auth"], }); + useHead({ title: "Homebox | Home", }); @@ -15,15 +16,6 @@ const auth = useAuthStore(); - if (auth.self === null) { - const { data, error } = await api.user.self(); - if (error) { - navigateTo("/"); - } - - auth.$patch({ self: data.item }); - } - const itemsStore = useItemStore(); const items = computed(() => itemsStore.items); diff --git a/frontend/pages/item/[id]/edit.vue b/frontend/pages/item/[id]/edit.vue index 8ffcba6..35daf29 100644 --- a/frontend/pages/item/[id]/edit.vue +++ b/frontend/pages/item/[id]/edit.vue @@ -6,7 +6,7 @@ import { capitalize } from "~~/lib/strings"; definePageMeta({ - layout: "home", + middleware: ["auth"], }); const route = useRoute(); diff --git a/frontend/pages/item/[id]/index.vue b/frontend/pages/item/[id]/index.vue index 5c9c938..ae22d0c 100644 --- a/frontend/pages/item/[id]/index.vue +++ b/frontend/pages/item/[id]/index.vue @@ -3,7 +3,7 @@ import { ItemAttachment } from "~~/lib/api/types/data-contracts"; definePageMeta({ - layout: "home", + middleware: ["auth"], }); const route = useRoute(); diff --git a/frontend/pages/item/new.vue b/frontend/pages/item/new.vue index 4762c1c..a1a6584 100644 --- a/frontend/pages/item/new.vue +++ b/frontend/pages/item/new.vue @@ -1,6 +1,6 @@