* refactor: move to tanstack start * refactor: auth flow & volumes * refactor: repo & snapshot details * refactor: backups, create repo, volumes * refactor: create volume & restore snapshot * refactor: notifications * refactor: settings * refactor: breadcrumbs * fix: ts issues * refactor: prod deployment * fix: import css production * refactor: nitro build * refactor: winston -> consola * fix: memory leak is sse events cleanup * fix: cli usage * chore: remove rr routes file * refactor: pr feedbacks * refactor: patch api client to have a global client per call * refactor: pr feedbacks * fix(dockerfile): add explicit port * fix(e2e): healthcheck under /api
29 lines
861 B
TypeScript
29 lines
861 B
TypeScript
import { createMiddleware } from "@tanstack/react-start";
|
|
import { redirect } from "@tanstack/react-router";
|
|
import { auth } from "~/server/lib/auth";
|
|
import { getRequestHeaders } from "@tanstack/react-start/server";
|
|
import { authService } from "~/server/modules/auth/auth.service";
|
|
|
|
export const authMiddleware = createMiddleware().server(async ({ next, request }) => {
|
|
const headers = getRequestHeaders();
|
|
const session = await auth.api.getSession({ headers });
|
|
|
|
const isAuthRoute = ["/login", "/onboarding"].includes(new URL(request.url).pathname);
|
|
|
|
if (!session?.user?.id && !isAuthRoute) {
|
|
const hasUsers = await authService.hasUsers();
|
|
if (!hasUsers) {
|
|
throw redirect({ to: "/onboarding" });
|
|
}
|
|
|
|
throw redirect({ to: "/login" });
|
|
}
|
|
|
|
if (session?.user?.id) {
|
|
if (isAuthRoute) {
|
|
throw redirect({ to: "/" });
|
|
}
|
|
}
|
|
|
|
return next();
|
|
});
|