© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•2mo ago•
26 replies
LukeZ

Before User Created Hook works only manually

auth🤷otherSolved🟢SQL
I have a function which checks if a user with an email is allowed to signup. However, this function works correctly when I run it manually with a valid email, but not when I use
supabase.auth.signUp
supabase.auth.signUp
in my sveltekit app.
Manually, it returns
{}
{}
but when a user really tries to sign up, it returns
Signups from this email (<redacted>) are not allowed.
Signups from this email (<redacted>) are not allowed.
for the same email.

Any idea why?

The function in question:
DECLARE
  user_email text;
  allowed int;
BEGIN
  user_email := (event -> 'user' ->> 'email');

  -- if no email provided, deny
  IF user_email IS NULL THEN
    RETURN jsonb_build_object(
      'error', jsonb_build_object(
        'message', 'No email provided in signup event.',
        'http_code', 400
      )
    );
  END IF;

  SELECT COUNT(*) INTO allowed
  FROM public.allowed_users au
  WHERE lower(au.email) = lower(user_email);

  IF allowed > 0 THEN
    -- empty object indicates success for Supabase Auth hook
    RETURN '{}'::jsonb;
  END IF;

  RETURN jsonb_build_object(
    'error', jsonb_build_object(
      'message', format('Signups from this email (%s) are not allowed.', user_email),
      'http_code', 403
    )
  );
END;
DECLARE
  user_email text;
  allowed int;
BEGIN
  user_email := (event -> 'user' ->> 'email');

  -- if no email provided, deny
  IF user_email IS NULL THEN
    RETURN jsonb_build_object(
      'error', jsonb_build_object(
        'message', 'No email provided in signup event.',
        'http_code', 400
      )
    );
  END IF;

  SELECT COUNT(*) INTO allowed
  FROM public.allowed_users au
  WHERE lower(au.email) = lower(user_email);

  IF allowed > 0 THEN
    -- empty object indicates success for Supabase Auth hook
    RETURN '{}'::jsonb;
  END IF;

  RETURN jsonb_build_object(
    'error', jsonb_build_object(
      'message', format('Signups from this email (%s) are not allowed.', user_email),
      'http_code', 403
    )
  );
END;
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Before User Created Hook id differs from actual created ID
SupabaseSSupabase / help-and-questions
8mo ago
After User Created Hook
SupabaseSSupabase / help-and-questions
3w ago
before_user_created auth hook not working as documented
SupabaseSSupabase / help-and-questions
5mo ago
Supabase Auth Hook (before-user-created): can I access the Origin header without using Edge Function
SupabaseSSupabase / help-and-questions
3w ago