Fix local login flow, add new auth epic
Some checks failed
CI / backend-tests (push) Failing after 31s
CI / frontend-tests (push) Successful in 29s

This commit is contained in:
2026-03-21 11:06:53 +01:00
parent 0d6174067e
commit f7731b0497
10 changed files with 194 additions and 7 deletions

View File

@@ -2,14 +2,32 @@ import { createClient, type SupabaseClient } from '@supabase/supabase-js'
const supabaseUrl = import.meta.env['VITE_SUPABASE_URL'] ?? ''
const supabaseAnonKey = import.meta.env['VITE_SUPABASE_ANON_KEY'] ?? ''
const isLocalDev = supabaseUrl.includes('localhost')
// supabase-js hardcodes /auth/v1 as the auth path prefix, but GoTrue
// serves at the root when accessed directly (no API gateway).
// This custom fetch strips the prefix for local dev.
function localGoTrueFetch(
input: RequestInfo | URL,
init?: RequestInit,
): Promise<Response> {
const url = input instanceof Request ? input.url : String(input)
const rewritten = url.replace('/auth/v1/', '/')
if (input instanceof Request) {
return fetch(new Request(rewritten, input), init)
}
return fetch(rewritten, init)
}
function createSupabaseClient(): SupabaseClient {
if (!supabaseUrl || !supabaseAnonKey) {
// Return a stub client for tests/dev without Supabase configured
// Uses port 9999 to match local GoTrue container
return createClient('http://localhost:9999', 'stub-key')
}
return createClient(supabaseUrl, supabaseAnonKey)
return createClient(supabaseUrl, supabaseAnonKey, {
...(isLocalDev && {
global: { fetch: localGoTrueFetch },
}),
})
}
export const supabase = createSupabaseClient()