backend: version + network endpoints, LAN-friendly CORS/origins

Add public GET /api/version (current version + GitHub-release update check,
cached, fail-soft) and GET /api/network (detected LAN addresses). Accept
localhost/private-LAN origins in CORS and Better Auth trusted origins via a
shared isAllowedOrigin helper, so staff can reach the app over the clinic
network. The seed-demo.ts fake test data is removed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Khalid Abdi
2026-06-26 21:34:19 +03:00
parent 6bd81bd7dd
commit 2454bb4c2b
6 changed files with 193 additions and 2 deletions
+13 -1
View File
@@ -9,6 +9,7 @@ import * as authSchema from "./db/schema/auth.js";
import { env } from "./env.js";
import { ac, roles } from "./lib/access.js";
import { sendEmail } from "./lib/email.js";
import { isAllowedOrigin } from "./lib/origins.js";
const WEEK = 60 * 60 * 24 * 7;
const DAY = 60 * 60 * 24;
@@ -17,7 +18,18 @@ export const auth = betterAuth({
appName: "temetro",
baseURL: env.BETTER_AUTH_URL,
secret: env.BETTER_AUTH_SECRET,
trustedOrigins: [env.FRONTEND_URL],
// Trust the configured frontend origin plus localhost/LAN hosts so staff can
// sign in over the network (mirrors CORS; see src/lib/origins.ts). Reflecting
// the request's own origin (when allowed) keeps Better Auth's CSRF check happy
// without a per-deployment rebuild.
trustedOrigins: (request) => {
const origins = [env.FRONTEND_URL];
const origin = request?.headers.get("origin");
if (origin && isAllowedOrigin(origin) && !origins.includes(origin)) {
origins.push(origin);
}
return origins;
},
database: drizzleAdapter(db, {
provider: "pg",