mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-01-04 03:48:03 -05:00
25 lines
750 B
TypeScript
25 lines
750 B
TypeScript
import { createClient } from 'common/supabase/utils'
|
|
import { ENV_CONFIG } from 'common/envs/constants'
|
|
|
|
let currentToken: string | undefined
|
|
|
|
export function initSupabaseClient() {
|
|
// console.debug('Initializing supabase client', ENV_CONFIG.supabaseInstanceId, ENV_CONFIG.supabaseAnonKey)
|
|
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()
|