supabase / supabase-js

An isomorphic Javascript client for Supabase. Query your Supabase database, subscribe to realtime events, upload and download files, browse typescript examples, invoke postgres functions via rpc, invoke supabase edge functions, query pgvector.
https://supabase.com
MIT License
2.89k stars 223 forks source link

"This endpoint requires a Bearer token" on auth.admin.signOut #892

Closed emersonlaurentino closed 7 months ago

emersonlaurentino commented 7 months ago

Bug report

Describe the bug

I'm using Hono and Deno, so I create a router /logout in order to sign out the logged user, but when I access the route, I receive a error from auth.admin.signOut with this message:

{
    "name": "AuthApiError",
    "message": "This endpoint requires a Bearer token",
    "status": 401
}

This is the code that I'm using:

auth.get("/logout", async (c) => {
  const Authorization = c.req.header("Authorization")!;
  const supabaseClient = createClient(SUPABASE_URL ?? "", SUPABASE_KEY ?? "", {
    global: { headers: { Authorization } },
  });
  const { error } = await supabaseClient.auth.admin.signOut(Authorization);
  if (error) {
    c.status(error.status ?? 500);
    return c.json(error);
  }
  return c.json({ success: true });
});

I checked if the c.req.header("Authorization") returns the Bearer token, and yes, returns correctly.

System information