promote(GRO-2586): dev → uat — CORS origin allowlist enforcement (#220)
promote(GRO-2586): dev → uat — CORS origin allowlist enforcement
This commit is contained in:
+4
-2
@@ -3,6 +3,7 @@ import { Hono } from "hono";
|
||||
import { logger } from "hono/logger";
|
||||
import { cors } from "hono/cors";
|
||||
import { getAuth, initAuth, getActiveProviders } from "./lib/auth.js";
|
||||
import { enforceAuthCors } from "./lib/auth-cors.js";
|
||||
import { clientsRouter } from "./routes/clients.js";
|
||||
import { petsRouter } from "./routes/pets.js";
|
||||
import { servicesRouter } from "./routes/services.js";
|
||||
@@ -200,9 +201,10 @@ api.use("*", resolveStaffMiddleware);
|
||||
// Better-Auth handler — mounted as sub-app to handle all /api/auth/* routes
|
||||
// authMiddleware and resolveStaffMiddleware both skip /api/auth/ paths
|
||||
const authRouter = new Hono();
|
||||
authRouter.all("/*", (c) => {
|
||||
authRouter.all("/*", async (c) => {
|
||||
try {
|
||||
return getAuth().handler(c.req.raw);
|
||||
const res = await getAuth().handler(c.req.raw);
|
||||
return enforceAuthCors(c.req.header("origin"), TRUSTED_ORIGINS, res);
|
||||
} catch {
|
||||
return c.json({ error: "Authentication not configured" }, 503);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user