SupabaseS
Supabase5mo ago
Daniel

Edge function giving Invalid JWT

I setup a new project to try out the new JWT tokens and keys.

I'm using this in my flutter app:
Future<void> setupEverything() async {
  String username = randomString(8, alphanumeric: true);
  final String password = randomString(8, alphanumeric: true);

  // The username will be the name of the new schema

  print("Creating new user");
  // If this fails, let's just assume it's because the username already exists,
  // so let's retry it;
  final AuthResponse signUpRes = await retry(
    () => Supabase.instance.client.auth.signUp(
      email: '$username@astralbase.ai', // Fake email
      password: password,
    ),
    onRetry: (p0) {
      print(p0);
      print("Generating new username");
      username = randomString(8, alphanumeric: true);
    },
  );

  // Signing into user
  final signInRes = await Supabase.instance.client.auth.signInWithPassword(
    email: '$username@astralbase.ai',
    password: password,
  );

  print("Creating schema + other things");

  await Supabase.instance.client.rpc('create_schema');

  print("Exposing new schema");

  final exposeSchemaRes = await Supabase.instance.client.functions.invoke('expose-custom-schema');
  print(exposeSchemaRes.data);
}


This is super quick and dirty just to test things out. But the issue is that when I deploy the edge function without --no-verify-wt, I get an error response
DartError: FunctionException(status: 401, details: {code: 401, message: Invalid JWT}, reasonPhrase: )


When I go onto the UI and test the function, using service or anon role, things work.

I'm not exactly sure what I'm doing wrong. When I initialize supabase, I'm using the new
sp_publishable
key for the anonKey.
Was this page helpful?