SupabaseS
Supabase12mo ago
Az3K

Edge Functions & JWT Claims Auth Hook timeouts

Hello, I'm currently implementing an edge functions which is being called as an auth hook to get custom claims.

The code is working fine currently, but I would like to also update the user/app metadata in the supabase db for the users and when I try to call the supabase auth admin to update the user by id, it always timeouts, the logs shows that the hook took more than 5 seconds every single time I try to update and it's impossible to have great error handling, as the edge function is being called, logs are showing up to the supabase auth admin call, then timeouts so I have no idea why it can timeout.

In the Auth log in supabase dashboard, I always get : 422: Failed to reach hook within maximum time of 5.000000 seconds

And in the Postgres logs I get:
process 65551 acquired ShareLock on transaction 1346 after 2707.894 ms
process 65551 still waiting for ShareLock on transaction 1346 after 1000.072 ms
connection authorized: user=supabase_auth_admin database=postgres
And they corresponds to the UPDATE query made my the updateUserById call.


Here is the code snippet:
Admin client
  const supabaseClient = createClient(
    Deno.env.get("SUPABASE_URL") ?? "",
    Deno.env.get("SUPABASE_SERVICE_ROLE_KEY") ?? "",
    {
      auth: {
        autoRefreshToken: false,
        persistSession: false
    }}
  );

...

const { data: user, error } = await supabaseClient.auth.admin.updateUserById(
  user_id,
  { app_metadata: { subscription: subscription } }
)


Thank you.
Was this page helpful?