mirror of
https://github.com/temetro/temetro.git
synced 2026-07-26 11:58:14 +00:00
1ecbd16404
Connects the UI-only app to the new backend over Better Auth + a small patient API client, replacing the in-memory fixture and placeholder identity. - Better Auth React client (lib/auth-client.ts) + shared access-control roles; API client (lib/api-client.ts) sending credentials cross-origin. - Designed (auth) route group: login, signup, verify-email, forgot/reset password, clinic onboarding, and accept-invite. - proxy.ts (this Next's renamed middleware) optimistic redirect + an authoritative client AppAuthGuard requiring a session and active clinic. - Real identity in nav-user (useSession + sign out); the unused team switcher repurposed as an organization (clinic) switcher; Care-team settings tab manages members and invitations. - lib/patients.ts now calls the org-scoped API (types unchanged); patients table and create/edit dialog updated for async create/update. - next.config: standalone output + Dockerfile for containerized runs. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import type { NextRequest } from "next/server";
|
|
|
|
// Better Auth session cookie names (plain in dev, __Secure- prefixed over
|
|
// HTTPS). The authoritative check happens client-side (AppAuthGuard) and on the
|
|
// API; this is an optimistic redirect to avoid flashing the app when clearly
|
|
// signed out.
|
|
const SESSION_COOKIES = [
|
|
"better-auth.session_token",
|
|
"__Secure-better-auth.session_token",
|
|
];
|
|
|
|
export function proxy(request: NextRequest) {
|
|
const hasSession = SESSION_COOKIES.some((name) =>
|
|
request.cookies.has(name),
|
|
);
|
|
|
|
if (!hasSession) {
|
|
const url = request.nextUrl.clone();
|
|
url.pathname = "/login";
|
|
url.search = "";
|
|
return NextResponse.redirect(url);
|
|
}
|
|
|
|
return NextResponse.next();
|
|
}
|
|
|
|
export const config = {
|
|
// Run on all routes except the auth pages, Next internals and static assets.
|
|
matcher: [
|
|
"/((?!login|signup|verify-email|forgot-password|reset-password|onboarding|accept-invite|_next/static|_next/image|favicon.ico|temetro-logo.png|avatars).*)",
|
|
],
|
|
};
|