spot2gether-frontend/src/middlewares/auth.ts
2022-09-30 20:59:08 +02:00

19 lines
380 B
TypeScript

import { useApi } from "@/Api";
import type {
NavigationGuardNext,
RouteLocationNormalized,
Router,
} from "vue-router";
type Context = {
from: RouteLocationNormalized;
to: RouteLocationNormalized;
next: NavigationGuardNext;
router: Router;
};
export const auth = ({ next }: Context) => {
if (!useApi()?.isAuthorized()) next({ name: "auth" });
else next();
};