Closed k-nearest-neighbor closed 1 month ago
This was due to passing the header wrong
const supabase = createClient(supabaseUrl, supabaseAnonKey, {
global: {headers: {authorization_header}}
});
// Should be:
const supabase = createClient(supabaseUrl, supabaseAnonKey, {
global: {headers: {Authorization: authorization_header}}
});
Bug report
Description
Running locally, I'm following https://supabase.com/docs/guides/functions/auth and the github example https://github.dev/supabase/supabase/blob/master/examples/edge-functions/supabase/functions/select-from-table-with-auth-rls/index.ts
When doing
const response = await supabase.auth.getUser(token)
there is aresponse.error
:It looks like the supabase client is sending the request to the api server and getting the response "Bad request", and then excepting when attempting to parse it as JSON.
My main concern is why is it getting "Bad request"? / this is blocking me. It must be something about my setup but I haven't been able to find it.
But it's also worth noticing potential bugs with the supabase client and/or server:
To Reproduce
supabase start
supabase functions serve --inspect-mode brk
(optionally)const supabaseUrl = Deno.env.get('SUPABASE_URL'); // this is 'http://kong:8000' const supabaseAnonKey = Deno.env.get('SUPABASE_ANON_KEY'); // this is set correctly
Deno.serve(async (req) => { console.log('corsHeaders: ', corsHeaders) if (req.method === 'OPTIONS') { return new Response('ok', { headers: corsHeaders }) }
const authorization = req.headers.get('Authorization'); if (!authorization) { return new Response( JSON.stringify({ error:
No authorization header passed
}), { status: 500, headers: { 'Content-Type': 'application/json' }, } ); }const supabase = createClient(supabaseUrl, supabaseAnonKey, { global: {headers: {authorization}} });
const token = authorization.replace('Bearer ', '');
const response = await supabase.auth.getUser(token); console.log('response.error: ', response.error);
...
AuthUnknownError: Unexpected token 'B', "Bad request " is not valid JSON at handleError (fetch.js:34:15) ...
─────────────────────────┼──────────────────┼───────────── supabase/postgres │ 15.6.1.115 │ 15.6.1.115 supabase/gotrue │ v2.162.1 │ v2.162.1 postgrest/postgrest │ v12.2.3 │ v12.2.3 supabase/realtime │ v2.30.34 │ - supabase/storage-api │ v1.11.7 │ v1.11.7 supabase/edge-runtime │ v1.58.3 │ - supabase/studio │ 20240729-ce42139 │ - supabase/postgres-meta │ v0.83.2 │ - supabase/logflare │ 1.4.0 │ - supabase/supavisor │ 1.1.56 │ -