@@ -67,11 +67,8 @@ def __init__(
6767
6868 self .supabase_url = supabase_url
6969 self .supabase_key = supabase_key
70- self ._auth_token = {
71- "Authorization" : f"Bearer { supabase_key } " ,
72- }
73- options .headers .update (self ._get_auth_headers ())
7470 self .options = options
71+ options .headers .update (self ._get_auth_headers ())
7572 self .rest_url = f"{ supabase_url } /rest/v1"
7673 self .realtime_url = f"{ supabase_url } /realtime/v1" .replace ("http" , "ws" )
7774 self .auth_url = f"{ supabase_url } /auth/v1"
@@ -102,9 +99,7 @@ async def create(
10299 supabase_key : str ,
103100 options : Union [ClientOptions , None ] = None ,
104101 ):
105- client = cls (supabase_url , supabase_key , options )
106- client ._auth_token = await client ._get_token_header ()
107- return client
102+ return cls (supabase_url , supabase_key , options )
108103
109104 def table (self , table_name : str ) -> AsyncRequestBuilder :
110105 """Perform a table operation.
@@ -147,7 +142,6 @@ def rpc(
147142 @property
148143 def postgrest (self ):
149144 if self ._postgrest is None :
150- self .options .headers .update (self ._auth_token )
151145 self ._postgrest = self ._init_postgrest_client (
152146 rest_url = self .rest_url ,
153147 headers = self .options .headers ,
@@ -160,21 +154,19 @@ def postgrest(self):
160154 @property
161155 def storage (self ):
162156 if self ._storage is None :
163- headers = self ._get_auth_headers ()
164- headers .update (self ._auth_token )
165157 self ._storage = self ._init_storage_client (
166158 storage_url = self .storage_url ,
167- headers = headers ,
159+ headers = self . options . headers ,
168160 storage_client_timeout = self .options .storage_client_timeout ,
169161 )
170162 return self ._storage
171163
172164 @property
173165 def functions (self ):
174166 if self ._functions is None :
175- headers = self . _get_auth_headers ()
176- headers . update ( self ._auth_token )
177- self . _functions = AsyncFunctionsClient ( self . functions_url , headers )
167+ self . _functions = AsyncFunctionsClient (
168+ self . functions_url , self .options . headers
169+ )
178170 return self ._functions
179171
180172 # async def remove_subscription_helper(resolve):
@@ -248,26 +240,17 @@ def _init_postgrest_client(
248240 )
249241
250242 def _create_auth_header (self , token : str ):
251- return {
252- "Authorization" : f"Bearer { token } " ,
253- }
243+ return f"Bearer { token } "
254244
255245 def _get_auth_headers (self ) -> Dict [str , str ]:
256246 """Helper method to get auth headers."""
257247 return {
258248 "apiKey" : self .supabase_key ,
259- "Authorization" : f"Bearer { self .supabase_key } " ,
249+ "Authorization" : self .options .headers .get (
250+ "Authorization" , self ._create_auth_header (self .supabase_key )
251+ ),
260252 }
261253
262- async def _get_token_header (self ):
263- try :
264- session = await self .auth .get_session ()
265- access_token = session .access_token
266- except Exception as err :
267- access_token = self .supabase_key
268-
269- return self ._create_auth_header (access_token )
270-
271254 def _listen_to_auth_events (
272255 self , event : AuthChangeEvent , session : Union [Session , None ]
273256 ):
@@ -279,7 +262,7 @@ def _listen_to_auth_events(
279262 self ._functions = None
280263 access_token = session .access_token if session else self .supabase_key
281264
282- self ._auth_token = self ._create_auth_header (access_token )
265+ self .options . headers [ "Authorization" ] = self ._create_auth_header (access_token )
283266
284267
285268async def create_client (
0 commit comments