Skip to content

Functions createClient issue when using legacy tokens in local docker #4754

@MathieuUrstein

Description

@MathieuUrstein

Bug report

Describe the bug

After updating supabase from 2.67 to 2.72 the createClient function in edge functions (documented here) fails locally. Still works in production though.

By failing here is the console error message: TypeError: Key for the ES256 algorithm must be of type CryptoKey. Received an instance of Uint8Array.

To reproduce

  • Start a local docker version of supabase 2.72 or later
  • Try creating a supabase client like so:
export const supabaseAdmin = createClient(
  Deno.env.get("SUPABASE_URL") || "",
  Deno.env.get("SUPABASE_SERVICE_ROLE_KEY") || ""
)
const getSupabaseUserClient = (request: Request) =>
  createClient(
    Deno.env.get("SUPABASE_URL") || "",
    Deno.env.get("SUPABASE_ANON_KEY") || "",
    // Create client with Auth context of the user that called the function.
    {
      global: {
        headers: { Authorization: request.headers.get("Authorization") },
      },
    }
  )

Deno.serve(async (request: Request) => {
   getSupabaseUserClient(request)
   supabaseAdmin()
})
  • run the function and you should have the error

My guess is that the default provided environment variables like SUPABASE_SERVICE_ROLE_KEY or SUPABASE_ANON_KEY have been updated but are now not compatible with supabase-js.

I've also seen a new documentation here but it does not seem to talk about impersonated clients.

Might be related to supabase/supabase#42037

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions