Edge Function - User authentication from Bearer - how to?

Hello,
I am trying to identify the caller of an Edge Function, but I systematically get a "null" value.
Here is what I do:
  • On the client side (Flutter), once the user has signed in, I am invoking the function```FunctionResponse? res; final String? accessToken = Supabase.instance.client.auth.session()?.accessToken; try { res = await Supabase.instance.client.functions.invoke( 'ef_authentication_test', body: { "action": "action", "data": { "hello": "worled", }, }, headers: {'Authorization': 'Bearer $accessToken'}, ); TraceHelper.logE('[SupabaseHelper::invokeFunction] -- Response', error: res); } catch (e) { TraceHelper.logE('[SupabaseHelper::invokeFunction] -- Exception', error: e); }```The call invocation works, the <accessToken> exists.
At the level of the Edge Function, I am running the following:
export const supabaseClient = createClient(
  // Supabase API URL - env var exported by default when deployed.
  'https://KEY.supabase.co',
  // Supabase API ANON KEY - env var exported by default when deployed.
  '<ANON KEY>'
);

export function supabaseUser(req:Request) {
  // Get the authorization header from the request.
  const authHeader = req.headers?.get('Authorization')?.replace("Bearer ", "") || "";
  console.log(`Authorization: ${authHeader}`);
  
  supabaseClient.auth.setAuth(authHeader);

  console.log(`User: ${supabaseClient.auth.user()}`);

  return supabaseClient.auth.user();
};

The <authHeader> corresponds to the <accessToken> from the client side.

The <User> I am getting is always NULL. => I need to get this to validate the requestor.

Could anybody tell me what I am doing wrong?

Thanks in advance,
Was this page helpful?