SupabaseS
Supabase4mo ago
tomi

Invalid API Key Next.js

Hello all,

I'm trying to setup an 'invite by emai' function in my Next.js app with Supabase auth (admin) from @supabase-js but I keep getting the error:
Error [AuthApiError]: Invalid API Key

I don't believe this to be true as all my CRUD functions run properly on the same DB. I would also like to add that this only happens when I try to connect to the auth client. When I use the login/sign in from supabase auth (not admin), I don't get this. I've tried pasting both the service role and secret key directly into my function (bypassing the env), but I get the same error.

The relevant code is:
import { createClient } from "@supabase/supabase-js";
  const supabase = createClient(
    DB_URL,
    SECRET_KEY / SERVICE_ROLE_KEY,
    {
      auth: {
        persistSession: false,
        autoRefreshToken: false,
      },
    }
  );
  const { data, error } = await supabase.auth.admin.inviteUserByEmail(email, {
    data: {
      role: role,
    },
    redirectTo: "/auth/confirm",
  });


I'd really appreciate any help here.
Was this page helpful?