Files
temetro/frontend/lib/auth-client.ts
T
Khalid Abdi 403e0e38e9 frontend: runtime backend URL (LAN), voice dictation, version + update UI
Resolve the backend URL from the current host at runtime (lib/backend-url.ts)
so one build works on localhost and any clinic LAN IP without a rebuild; used
by the API client, auth client, and socket. Wire the AI-chat mic to the Web
Speech API with graceful fallback. Add a Settings "About & updates" panel
(current/latest version, update command, shareable network address) and an
optional dismissible update banner.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 21:34:30 +03:00

31 lines
1.0 KiB
TypeScript

import {
organizationClient,
usernameClient,
} from "better-auth/client/plugins";
import { createAuthClient } from "better-auth/react";
import { ac, roles } from "@/lib/access";
import { resolveBackendUrl } from "@/lib/backend-url";
// The backend (Express + Better Auth) is a separate origin. The client appends
// `/api/auth` to this base URL and always sends credentials so the session
// cookie set by the backend is included on every request. The base URL is
// derived from the current host (see lib/backend-url.ts) so login works over
// localhost and the clinic LAN alike.
export const authClient = createAuthClient({
baseURL: resolveBackendUrl(),
// usernameClient enables signIn.username(...) so admin-provisioned staff can
// log in with a username; organizationClient powers clinics + RBAC.
plugins: [usernameClient(), organizationClient({ ac, roles })],
});
export const {
signIn,
signUp,
signOut,
useSession,
useActiveOrganization,
useListOrganizations,
organization,
} = authClient;