15 lines
442 B
TypeScript
15 lines
442 B
TypeScript
import { authSession, requireAuth } from "@wrnexus/auth";
|
|
import type { Middleware } from "@wrnexus/core";
|
|
import { auth } from "../lib/auth.ts";
|
|
|
|
const hydrate = authSession(auth);
|
|
const accountGuard = requireAuth({ loginPath: "/sign-in" });
|
|
|
|
const middleware: Middleware = async (ctx, next) => {
|
|
return hydrate(ctx, () =>
|
|
ctx.url.pathname.startsWith("/account") ? accountGuard(ctx, next) : next(),
|
|
);
|
|
};
|
|
|
|
export default middleware;
|