before_user_created Auth Hook Returns "Invalid payload sent to hook" Error When Rejecting User Creation

Open
#2,235 16 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
go, javascript

Research direction

Start by reproducing the before_user_created hook with the documented HTTP 400 JSON response and compare it with the working HTTP 200 path. Trace the auth hook response handling to find where the rejection payload becomes "Invalid payload sent to hook"; done means rejected signups return the custom error message without the unexpected_failure response.

Written by the indexing model from the issue text.

Description

bug

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

The before_user_created auth hook returns an "Invalid payload sent to hook" error when attempting to reject user account creation with a properly formatted HTTP 400 response. Instead of processing the rejection with the custom error message, Supabase returns an unexpected failure error.

To Reproduce

Steps to reproduce the behavior:

  1. Set up a before_user_created auth hook in your Supabase project dashboard
  2. Configure it to point to a custom API endpoint (e.g., using ngrok for local development)
  3. Create an endpoint that conditionally rejects signups with this response:
    return response
      .status(400)
      .set('Content-Type', 'application/json')
      .json({
        error: {
          message: 'Signups from this email domain are not allowed.',
          http_code: 400,
        },
      });
    
  4. Attempt to create a user account that should trigger the rejection logic
  5. Observe the error response from Supabase

Expected behavior

When the auth hook returns HTTP 400 with the proper error payload format, Supabase should:

  • Prevent the account creation
  • Return the custom error message specified in the hook response
  • Handle the rejection gracefully without throwing an "Invalid payload" error

Screenshots

Error response received:

{
  "code": "unexpected_failure",
  "message": "Invalid payload sent to hook"
}

System information

  • OS: [Various - issue occurs on server side]
  • Browser: N/A (affects API calls)
  • Version of supabase-js: NA
  • Version of Node.js: NA

Additional context

  • The API endpoint is successfully receiving requests from Supabase (confirmed via server logs)
  • The API responds with the exact JSON format as documented
  • When returning HTTP 200 with an empty body, account creation proceeds without issues
  • This suggests the hook connectivity is working, but error handling for HTTP 400 responses is broken
  • The same issue has been reported by other users (@Entropei)
  • Hook URL is accessible and properly configured in the Supabase dashboard

The problem specifically occurs when trying to reject user creation - the success path works fine, but the rejection path fails with an unhelpful error message that doesn't match the documentation.

Dominant language
Go
Stars
2.6k
Forks
764
Avg merge
5d 3h
Merged PRs (30d)
39

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from supabase/auth

All issues in supabase/auth

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.