Files
Jyotisha/frontend/src/app/api/auth/[...all]/route.ts
T
linmeng 248e1b8a07
Deploy staging to test server / deploy (push) Successful in 3m16s
fix: unify staging admin access
2026-07-29 11:28:15 +08:00

38 lines
1.0 KiB
TypeScript

import { toNextJsHandler } from "better-auth/next-js";
import { getIdentityAuthServices } from "@/modules/identity/auth";
import {
isSelfHostedIdentityEnabled,
readSelfHostedIdentityConfig,
} from "@/modules/identity/config";
import {
createHostIsolatedAuthHandlers,
type IdentityAuthHandlers,
} from "@/modules/identity/host";
export const dynamic = "force-dynamic";
async function dispatch(
method: keyof IdentityAuthHandlers,
request: Request,
): Promise<Response> {
if (!isSelfHostedIdentityEnabled(process.env)) {
return new Response("Not found", { status: 404 });
}
const config = readSelfHostedIdentityConfig(process.env);
const services = getIdentityAuthServices();
const handlers = createHostIsolatedAuthHandlers(config, {
user: toNextJsHandler(services.user),
});
return handlers[method](request);
}
export function GET(request: Request): Promise<Response> {
return dispatch("GET", request);
}
export function POST(request: Request): Promise<Response> {
return dispatch("POST", request);
}