You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
14 lines
446 B
14 lines
446 B
const PUBLIC_PATHS = ["/", "/index", "/login", "/register"];
|
|
|
|
export default defineNuxtRouteMiddleware(async (to) => {
|
|
if (PUBLIC_PATHS.includes(to.path)) return;
|
|
|
|
try {
|
|
const res = await $fetch<{ code: number }>("/api/auth/me");
|
|
if (res.code !== 0) {
|
|
return navigateTo("/login?redirect=" + encodeURIComponent(to.fullPath));
|
|
}
|
|
} catch {
|
|
return navigateTo("/login?redirect=" + encodeURIComponent(to.fullPath));
|
|
}
|
|
});
|
|
|