2025-11-24 01:00:50 +01:00
|
|
|
import { createAuthClient } from 'better-auth/svelte';
|
2026-05-20 00:49:39 +01:00
|
|
|
import { env } from '$env/dynamic/public';
|
2026-03-09 11:18:22 +01:00
|
|
|
import { ssoClient } from '@better-auth/sso/client';
|
2025-11-24 01:00:50 +01:00
|
|
|
|
2026-05-20 00:49:39 +01:00
|
|
|
// Browser: same-origin `/api` via the Cloudflare Worker, so auth cookies
|
|
|
|
|
// stay host-only on whichever domain the user is currently on
|
|
|
|
|
// (app.classroomio.com, <org>.classroomio.school, or a BYOD domain).
|
|
|
|
|
// SSR: `authClient`'s methods aren't called server-side — the dashboard uses
|
|
|
|
|
// `authServerClient` for that — but Better Auth's constructor still validates
|
|
|
|
|
// the baseURL with `new URL(...)`, so we hand it the public API URL as a
|
|
|
|
|
// placeholder. PRIVATE_SERVER_URL is deliberately not used here: it's the
|
|
|
|
|
// internal Render hostname, never reachable from a browser.
|
|
|
|
|
const baseURL =
|
|
|
|
|
typeof window !== 'undefined' ? `${window.location.origin}/api` : env.PUBLIC_SERVER_URL || 'http://localhost:3002';
|
|
|
|
|
|
2025-11-24 01:00:50 +01:00
|
|
|
export const authClient = createAuthClient({
|
2026-05-20 00:49:39 +01:00
|
|
|
baseURL,
|
2025-11-24 01:00:50 +01:00
|
|
|
fetchOptions: {
|
|
|
|
|
credentials: 'include' // Include cookies in requests
|
2026-03-09 11:18:22 +01:00
|
|
|
},
|
|
|
|
|
plugins: [
|
|
|
|
|
ssoClient({
|
|
|
|
|
domainVerification: {
|
|
|
|
|
enabled: true
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
]
|
2025-11-24 01:00:50 +01:00
|
|
|
});
|