- packages/supabase: signIn/signUp/OAuth/reset/updatePassword/signOut wrappers with a closed AuthFailure kind, fetch/update own profile, own platform roles - migration 20261011100000: practice_name, professional_title, siret (format-checked, column grants); pgTAP 009; database.types regenerated - config.toml: TOTP enroll/verify on, [auth.external.google|apple] via env(), wildcard redirect URLs - app config: authProviders (APP_AUTH_PROVIDERS / VITE_AUTH_PROVIDERS), entrypoint env.js, DEPLOY table - TODO: Step 7 plan
116 lines
3.5 KiB
TypeScript
116 lines
3.5 KiB
TypeScript
/// <reference types="vite/client" />
|
|
import type { OAuthProvider, SupabaseConnection } from '@faunosteo/supabase'
|
|
|
|
/**
|
|
* Runtime application config.
|
|
* Resolution order:
|
|
* 1. window.__APP_CONFIG__ (injected by docker/entrypoint.sh)
|
|
* 2. import.meta.env.VITE_* (build-time Vite defines)
|
|
* 3. Hard-coded defaults
|
|
*/
|
|
export interface AppConfig {
|
|
siteName: string
|
|
brandName: string
|
|
footerName: string
|
|
tagline: string
|
|
/** null = no backend configured; the app keeps its local-only behaviour. */
|
|
supabase: SupabaseConnection | null
|
|
/** OAuth buttons to show on the auth screens; the server must enable the same providers. */
|
|
authProviders: OAuthProvider[]
|
|
}
|
|
|
|
/** Shape written by docker/entrypoint.sh (flat strings, empty = unset). */
|
|
export interface RuntimeConfig {
|
|
siteName?: string
|
|
brandName?: string
|
|
footerName?: string
|
|
tagline?: string
|
|
supabaseUrl?: string
|
|
supabaseAnonKey?: string
|
|
/** Comma-separated: "google,apple". */
|
|
authProviders?: string
|
|
}
|
|
|
|
declare global {
|
|
interface Window {
|
|
__APP_CONFIG__?: RuntimeConfig
|
|
}
|
|
}
|
|
|
|
const DEFAULTS: Omit<AppConfig, 'supabase' | 'authProviders'> = {
|
|
siteName: 'Faunosteo',
|
|
brandName: 'Faunosteo',
|
|
footerName: 'Faunosteo',
|
|
tagline: 'Outils pour ostéopathes animaliers',
|
|
}
|
|
|
|
/** Empty strings from env.js or Vite count as "not set". */
|
|
function nonEmpty(value: string | undefined): string | undefined {
|
|
return value && value.trim() !== '' ? value : undefined
|
|
}
|
|
|
|
/** Both settings are required; one without the other is a misconfiguration. */
|
|
export function resolveSupabaseConnection(
|
|
url: string | undefined,
|
|
anonKey: string | undefined,
|
|
): SupabaseConnection | null {
|
|
const cleanUrl = nonEmpty(url)
|
|
const cleanKey = nonEmpty(anonKey)
|
|
if (cleanUrl && cleanKey) return { url: cleanUrl, anonKey: cleanKey }
|
|
if ((cleanUrl || cleanKey) && import.meta.env.DEV) {
|
|
console.warn(
|
|
'[config] supabaseUrl and supabaseAnonKey must be set together; Supabase disabled',
|
|
)
|
|
}
|
|
return null
|
|
}
|
|
|
|
const KNOWN_PROVIDERS: readonly string[] = ['google', 'apple']
|
|
|
|
/** "google, apple" → ['google', 'apple']; unknown names are dropped (warned in DEV). */
|
|
export function resolveAuthProviders(
|
|
raw: string | undefined,
|
|
): OAuthProvider[] {
|
|
const names = (nonEmpty(raw) ?? '')
|
|
.split(',')
|
|
.map((name) => name.trim().toLowerCase())
|
|
.filter((name) => name !== '')
|
|
const known = names.filter((name): name is OAuthProvider =>
|
|
KNOWN_PROVIDERS.includes(name),
|
|
)
|
|
if (known.length !== names.length && import.meta.env.DEV) {
|
|
console.warn(`[config] unknown auth provider in "${raw}"; ignored`)
|
|
}
|
|
return [...new Set(known)]
|
|
}
|
|
|
|
export function resolveConfig(runtime: RuntimeConfig = {}): AppConfig {
|
|
return {
|
|
siteName:
|
|
runtime.siteName ??
|
|
import.meta.env.VITE_APP_SITE_NAME ??
|
|
DEFAULTS.siteName,
|
|
brandName:
|
|
runtime.brandName ??
|
|
import.meta.env.VITE_APP_BRAND_NAME ??
|
|
DEFAULTS.brandName,
|
|
footerName:
|
|
runtime.footerName ??
|
|
import.meta.env.VITE_APP_FOOTER_NAME ??
|
|
DEFAULTS.footerName,
|
|
tagline:
|
|
runtime.tagline ?? import.meta.env.VITE_APP_TAGLINE ?? DEFAULTS.tagline,
|
|
supabase: resolveSupabaseConnection(
|
|
runtime.supabaseUrl ?? import.meta.env.VITE_SUPABASE_URL,
|
|
runtime.supabaseAnonKey ?? import.meta.env.VITE_SUPABASE_ANON_KEY,
|
|
),
|
|
authProviders: resolveAuthProviders(
|
|
runtime.authProviders ?? import.meta.env.VITE_AUTH_PROVIDERS,
|
|
),
|
|
}
|
|
}
|
|
|
|
export const appConfig: AppConfig = resolveConfig(
|
|
typeof window !== 'undefined' ? window.__APP_CONFIG__ : undefined,
|
|
)
|