11 lines
448 B
TypeScript
11 lines
448 B
TypeScript
|
import { defineNuxtRouteMiddleware, navigateTo, useFetch } from "nuxt/app";
|
||
|
|
||
|
export default defineNuxtRouteMiddleware(async (to, from) => {
|
||
|
// FIXME: Check authorisation in another way (401 unauthorised) instead querying api directly
|
||
|
const me = await useFetch("/api/users/me", {});
|
||
|
|
||
|
if (!me.error.value) return;
|
||
|
if (process.client) console.log(me.error.value);
|
||
|
return navigateTo({ path: "/login", query: { redirect: to.fullPath } });
|
||
|
});
|