@@ -6,13 +6,7 @@ import {
66 UpdateType
77} from '@powersync/web' ;
88
9- import {
10- SupabaseClient ,
11- createClient ,
12- FunctionsHttpError ,
13- FunctionsRelayError ,
14- FunctionsFetchError
15- } from '@supabase/supabase-js' ;
9+ import { createClient , SupabaseClient } from '@supabase/supabase-js' ;
1610
1711export type SupabaseConfig = {
1812 supabaseUrl : string ;
@@ -53,25 +47,22 @@ export class SupabaseConnector extends BaseObserver<SupabaseConnectorListener> i
5347 }
5448
5549 async fetchCredentials ( ) {
56- const { data, error } = await this . client . functions . invoke ( 'powersync-auth-anonymous' , {
57- method : 'GET'
58- } ) ;
59-
60- if ( error instanceof FunctionsHttpError ) {
61- const errorMessage = await error . context . json ( ) ;
62- console . log ( 'Supabase edge function returned an error' , errorMessage ) ;
63- } else if ( error instanceof FunctionsRelayError ) {
64- console . log ( 'Supabase edge function: Relay error:' , error . message ) ;
65- } else if ( error instanceof FunctionsFetchError ) {
66- console . log ( 'Supabase edge function: Fetch error:' , error . message ) ;
50+ let {
51+ data : { session }
52+ } = await this . client . auth . getSession ( ) ;
53+ if ( session == null ) {
54+ const { data, error } = await this . client . auth . signInAnonymously ( ) ;
55+ if ( error ) {
56+ throw error ;
57+ }
58+ session = data . session ;
6759 }
68- if ( error ) {
69- throw error ;
60+ if ( session == null ) {
61+ throw new Error ( `Failed to get Supabase session` ) ;
7062 }
71-
7263 return {
73- endpoint : data . powersync_url ,
74- token : data . token
64+ endpoint : this . config . powersyncUrl ,
65+ token : session . access_token
7566 } ;
7667 }
7768
0 commit comments