Files
Compass/web/lib/supabase/db.ts
Okechi Jones-Williams b18a6d7ff3 [Onboarding Flow] Added database checks to the onboarding flow (#34)
* Fixed Type errors

* Organizing testing utilities

* Added Database checks to the onboarding flow

* Updated Onboarding flow
Changed type ChildrenExpectation so that it can be used for database verification

* Added compatibility page setup
Added more compatibility questions

* Fix

* .

* Fix: Typo

* Fix: Faker usernames can no longer generate symbols

* Fix: Changed how work area is verified

* .

* .

* Fix: Trying to work in headed mode

* Fix: Change back to headless

* Fix: Added timeout after workArea selection

* .

* Clean e2e

* Improve E2E setup

* Prettier

* Log

* Fix: should pull test account from unique identifier like email, username or id; not the display name

* Source env vars in playwright directly

* Clean e2e data

* Clean test account id to be the same for email and username

* Fix import warning

* Add error handling

* Add log

* Temp remove env load

* Update

* Add logs and safeguards against using remote supabase during e2e tests

* Fix playwright report path in C@

* Remove locale log

* Check if userInformationFromDb loading with name instead of username was the issue

* Remove login log

* Check if initial work area names were the issue

* Ignore if no files found

* Cache Firebase emulators in CI

* Reload env vars in playwright

* It did not break tests...

* Clean verifyWorkArea

* Add caching for node modules in CI

* Add caching for node modules in CI (2)

* Do not raise if emulator not running during db seed

* Do not raise if using firebase emulator

* Fix supabase cache in CI

* Add Cache Playwright browsers in CI

* Fix

* Test cache

* Turn off unused supabase services to speed things up

* Back to good one

* Set CI=true

* api is required for client connection

* Add safeguards for missing supabase env vars

* Remove echo

* Remove supabase cache

---------

Co-authored-by: Martin Braquet <martin.braquet@gmail.com>
2026-03-01 01:25:56 +01:00

49 lines
1.7 KiB
TypeScript

import {ENV_CONFIG} from 'common/envs/constants'
import {createClient} from 'common/supabase/utils'
let currentToken: string | undefined
export function initSupabaseClient() {
// Prefer explicit env overrides when available (useful for local Supabase via Docker)
const urlOverride = process.env.NEXT_PUBLIC_SUPABASE_URL || process.env.SUPABASE_URL
const anonKeyOverride = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || process.env.SUPABASE_ANON_KEY
if (urlOverride && anonKeyOverride) {
console.log('Initializing Supabase client (env URL override)', {urlOverride, anonKeyOverride})
return createClient(urlOverride, anonKeyOverride)
} else if (process.env.NEXT_PUBLIC_ISOLATED_ENV) {
throw new Error(
`You are running isolated tests (NEXT_PUBLIC_ISOLATED_ENV=true), so you do not want to call the remote supabase. ${{
urlOverride,
anonKeyOverride,
}}`,
)
}
if (urlOverride || anonKeyOverride) {
console.warn(
'Supabase env override is partially set. Both URL and ANON_KEY are required. Falling back to ENV_CONFIG.',
)
}
// Default: use instanceId and anon key from ENV_CONFIG
// Note: createClient accepts either instanceId or full URL
// console.debug('Initializing Supabase client', ENV_CONFIG.supabaseInstanceId)
return createClient(ENV_CONFIG.supabaseInstanceId, ENV_CONFIG.supabaseAnonKey)
}
export function updateSupabaseAuth(token?: string) {
if (currentToken != token) {
currentToken = token
if (token == null) {
// db['rest'].headers['Authorization']
db['realtime'].setAuth(null)
} else {
db['rest'].headers['Authorization'] = `Bearer ${token}`
db['realtime'].setAuth(token)
}
}
}
export const db = initSupabaseClient()