feat(identity): isolate auth routes by host

This commit is contained in:
Jesse_Chen
2026-07-21 17:38:29 +08:00
parent 8121add692
commit cf42430244
8 changed files with 561 additions and 3 deletions
@@ -0,0 +1,35 @@
import { toNextJsHandler } from "better-auth/next-js";
import { getIdentityAuthServices } from "@/modules/identity/auth";
import { readIdentityConfig } 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> {
const config = readIdentityConfig(process.env);
if (config.provider !== "self-hosted") {
return new Response("Not found", { status: 404 });
}
const services = getIdentityAuthServices();
const handlers = createHostIsolatedAuthHandlers(config, {
user: toNextJsHandler(services.user),
admin: toNextJsHandler(services.admin),
});
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);
}