Security basics
"Error running hook URI" in Supabase: why nobody can sign in
"Error running hook URI" means a Supabase Auth hook failed, so sign-in or sign-up fails for everyone. Where the real error is, and the safe fix.

In short
- "Error running hook URI" means Supabase Auth called one of your hooks, the call failed, and Auth turned the sign-in or sign-up away. After the colon is the address it called. A pg-functions:// address is a function in your own database.
- The real reason is in the Auth logs, on the entry that says "Hook errored out". For a Postgres function it is usually a permission: Auth runs the hook as supabase_auth_admin, a role that cannot touch your public schema until you grant it.
- Grant that role what the hook needs and nothing more. Making the function security definer, switching Row Level Security off on the table it reads, or deleting the signature check from an Edge Function also clears the error, because each one lets strangers in as well.
Nobody can sign in to your app, or new accounts can no longer be created. You built it with Lovable, Bolt, v0, Cursor, Claude Code or Replit, and the error on screen, or in the browser console, reads something like this:
Error running hook URI: pg-functions://postgres/public/custom_access_token_hook
There are three quick ways to make it go away: make the function
security definer, switch Row Level Security off on the table it reads, or
delete the signature check from the hook's Edge Function. Each one works by
letting more callers in. Supabase's own hooks page recommends against the first,
and the other two open a door that has nothing to do with signing in.
Picture Supabase Auth, the part of Supabase that signs people in, as the front
desk of your app's building. With a hook switched on, the desk makes a phone
call before it hands anyone a badge. It rings the number you gave it, reads out
who is standing there, and waits for an answer. Error running hook URI is the
desk's note that the call failed, with the number it dialled after the colon.
Until a call goes through, nobody gets a badge.
What does "Error running hook URI" mean?
It means Auth called one of your hooks, the call failed, and Auth refused the request it was in the middle of. A hook is your own code that Auth runs at a fixed point: before it issues a sign-in token, before it creates a new user, or in place of sending its own email.
Your app receives a reply like this one, with status 500:
{
"code": 500,
"error_code": "unexpected_failure",
"msg": "Error running hook URI: pg-functions://postgres/public/custom_access_token_hook"
}
The address after the colon tells you what kind of hook it was.
pg-functions://postgres/<schema>/<function> is an internal line to a function
in your own database. https://… is an outside line, usually to a Supabase Edge
Function. In Supabase Auth's source, this exact message is what a failure gets
when it carries no message of its own. In practice that is a Postgres function:
an HTTP hook that fails almost always says something more specific, and the
table further down lists those.
Where is the real error?
In the Auth logs, on an entry that says Hook errored out. Auth writes the
failure there with the hook's address and the underlying error, and sends your
app only the address.
- Try one sign-in or sign-up, let it fail, and note the time.
- In your Supabase dashboard, open Logs, then the Auth logs, and find
Hook errored outat that moment. Its error field is the reason. - For a Postgres function, open the Postgres logs at the same time. The line there names the function, the table or the permission.
Reading those two logs side by side works the same way as for the sign-up trigger that fails with "Database error saving new user".
Which hook failed, and what does it stop?
Your dashboard shows which hooks are switched on, under Authentication, then Hooks. Each one stops something different:
| Hook | When Auth calls it | What fails while it is broken |
|---|---|---|
| Custom Access Token | Each time a new sign-in token is created | Every sign-in, and sessions that need a fresh token |
| Before User Created | Before every new account | Every sign-up |
| Send Email | Each time Auth sends an email | Confirmation, magic link and password reset emails |
| Send SMS | Each time Auth sends a text | Phone sign-in and SMS codes |
| MFA Verification Attempt and Password Verification Attempt | On each code or password check (Teams and Enterprise plans) | The check it guards |
The fastest way to let people back in is to switch the hook off on that same page. Read what it was doing first. A Before User Created hook that blocked some sign-ups, by email domain or by network, stops blocking them. A claim that the Custom Access Token hook added, such as a role, disappears from every token, and any rule that reads it treats everybody as not having it.
A Postgres hook fails when Auth's role is not allowed in
Auth makes the call as its own database role, supabase_auth_admin, and
Supabase's hooks page says that role "does not have permissions to the public
schema". So a function that works when you run it in the SQL editor can still
fail when Auth calls it. When this is the cause, the Postgres log line reads
permission denied for followed by a schema, a function or a table.
The other causes, by the same log:
- The function is not where the address says. It was renamed, dropped, or created in another schema. The address names the schema and the function.
- The function raised an error. A
raise exceptionwritten to refuse somebody reaches your app as the same vague message. To refuse on purpose, return an error object, as Supabase's examples do:jsonb_build_object('error', jsonb_build_object('message', 'Signups from this email domain are not allowed.', 'http_code', 403)). Auth passes that message and status to your app. - It ran out of time. Auth's source gives a Postgres hook two seconds. The
log says
canceling statement due to statement timeout.
The fix for the permission is Supabase's own, with your function's name in it:
grant usage on schema public to supabase_auth_admin;
grant execute
on function public.custom_access_token_hook
to supabase_auth_admin;
revoke execute
on function public.custom_access_token_hook
from authenticated, anon, public;
If the function reads a table of yours, such as a user_roles table, Auth's
role needs that too. With Row Level Security on, it also needs a policy, or the
table answers it with no rows. That one may cause no error at all: the hook runs
as if the table were empty, and the role you meant to add never reaches the
token.
grant select on table public.user_roles to supabase_auth_admin;
create policy "Auth can read roles for the token hook"
on public.user_roles
for select
to supabase_auth_admin
using (true);
The policy names Auth's role and no other, so your app's own requests see the table exactly as they did before.
The quick fixes that let strangers in
Each one clears the error by letting more callers through than Auth. Only the desk should be able to dial the hook's number.
security definer on the function. It makes the function run with its
owner's privileges, and a function created in the dashboard is owned by
postgres. Supabase's hooks page recommends against it for hooks. Its Row Level
Security page goes further: "A security definer function in an exposed schema
is callable over the Data API with the creator's privileges", and public is
exposed by default. Postgres lets every role execute a new function until someone revokes
it, which is what the revoke above is for. Left in place, anybody holding the
key in your app can call /rest/v1/rpc/custom_access_token_hook with another
user's id and read back what would go into that user's token.
Row Level Security switched off on the table the hook reads. Supabase's
documentation says a table in an exposed schema without it "is readable and
writable by any role with a grant on it", and that some projects still grant
anon and authenticated by default. The anon role is the one behind the key
that ships inside your app. On
such a project, a roles table left writable lets anyone with that key give
themselves the admin role.
Whether a table answers a visitor with no login can be seen from outside. Our free scan asks each table your app names how many rows a visitor with no login can count, reads only the number, and takes about 20 seconds with no account: scan your app.
An HTTP hook names its own problem
An https:// hook fails with messages that say what went wrong, read from
Supabase Auth's source. Read the message your app received before anything else.
| The message starts with | What happened |
|---|---|
Hook requires authorization token | Your endpoint answered 401. On an Edge Function, JWT verification is still on. |
Invalid payload sent to hook | Your endpoint answered 400, for example when its own signature check failed. |
Unexpected status code returned from hook: | Any other status, such as 403 or 500, followed by the number. |
Failed to reach hook within maximum time of | No answer within five seconds. |
Failed to reach hook after maximum retries | The address could not be reached on any of three attempts. |
Invalid Content-Type or Invalid JSON response | A 200 answer without Content-Type: application/json. |
Service currently unavailable due to hook | A 429 or 503 answer with no retry-after header. |
Error generating signatures | The hook's secret is not in the v1,whsec_… shape Supabase generates. |
Hook requires authorization token. Supabase's Edge Function docs say a
function requires a valid JWT, a signed token, in its authorization header by
default. Auth's hook call sends none, because a hook often runs before anybody
is signed in, so the function refuses it. Supabase's hooks page says to switch
JWT verification off for a hook's function: --no-verify-jwt, or
verify_jwt = false in its config.
Your own error message never appears. Auth reads the error from your
function's body only when the status is 200 or 202. The HTTP example on
Supabase's Before User Created page refuses a sign-up with status 400, and on
Auth's current code that arrives as Invalid payload sent to hook, with the
message lost. Answer a refusal with 200 and the error inside the body:
return new Response(
JSON.stringify({ error: { message: 'Please sign up with a company email address.', http_code: 403 } }),
{ status: 200, headers: { 'Content-Type': 'application/json' } },
)
Keep the signature check on an HTTP hook
It is the only check the function has left. Supabase's own warning about
switching JWT verification off is that it "will allow anyone to invoke your Edge
Function without a valid JWT". From then on, the function knows a call came from
Auth only because the call is signed with the hook's secret, the
v1,whsec_… value from the Auth Hooks page, and the function checks the
signature before doing anything:
import { Webhook } from 'https://esm.sh/standardwebhooks@1.0.0'
Deno.serve(async (req) => {
const payload = await req.text()
const secret = Deno.env.get('SEND_EMAIL_HOOK_SECRET').replace('v1,whsec_', '')
const wh = new Webhook(secret)
const data = wh.verify(payload, Object.fromEntries(req.headers))
// only now act on data
})
When wh.verify throws, check first that the secret stored with the function
is the one on the Auth Hooks page, and copy it again if not. Deleting the check
also makes the error go away, and it turns the function into a public address. Supabase's Send Email example mails the
address in the payload with a link built from the payload, so without the check
it sends whatever a stranger posts to it, to whoever they choose, from your
sending address.
Keep the secret where you would keep a password: in the function's secrets,
set with supabase secrets set, and never in your app's code or a repository.
Moving a key out of your app and into a function
covers where it belongs, and
the same mistake on a Stripe webhook
ends with a stranger telling your app a payment went through.
Keeping sign-in working after the next change
A hook depends on grants, a table and a secret, and any of them can change after today. The quick fixes above are also one edit away for whoever touches the project next, and a roles table left writable can be changed by anybody holding your app's key.
Reeve Monitor keeps checking from outside:
- the full security check every hour, including how many rows a visitor with no login can count in the tables your app names
- an alert the day a re-scan grades your app lower than the one before
- whether the app is up, every 60 seconds
Reeve Care keeps a copy of your Supabase database:
- an encrypted copy on a schedule, on Reeve's own storage in the EU, outside your Supabase account
- each copy verified before it counts, by counting the rows in every table
- your uploaded files as well, once you connect a Storage credential
- a one-click restore, with a safety copy of the current state taken first
- everything Monitor does
The free scan shows what a visitor with no login can count in your tables today. About 20 seconds, and no account.
Scan your app free in 20 seconds
What to do now
What to do
- Read the address after the colon.
pg-functions://is a function in your database,https://is an outside endpoint. - Find
Hook errored outin the Auth logs at the moment of a failed sign-in, then the Postgres line beside it. - For a Postgres hook, grant
supabase_auth_adminusage on the schema, execute on the function and select on its tables, add a policy for it, and revoke execute fromanon,authenticatedandpublic. - Refuse a request by returning an error object, with status 200 from an HTTP hook.
- Deploy an HTTP hook's function with JWT verification off and keep
wh.verifyas the first thing it does. - Never fix it with
security definer, Row Level Security switched off or the signature check deleted.
If you are not sure what a stranger can read in your tables today, scan your app and start with the table your hook reads.
FAQ
What does "Error running hook URI" mean in Supabase?
Supabase Auth called a hook you switched on, the call failed, and Auth refused the request it was handling, usually a sign-in or a sign-up. The address after the colon is the hook it called. Auth puts the actual error in its own log under "Hook errored out" and sends your app only the address, so the reason is in the Auth logs.
Why does my custom_access_token_hook fail with permission denied?
Auth runs a Postgres hook as the supabase_auth_admin role, and Supabase says that role has no permissions in the public schema until you grant them. Grant it usage on the schema, execute on the function and select on each table the function reads, then add a policy for it on any of those tables that has Row Level Security on.
Can I make my Auth hook function security definer?
Supabase's hooks page recommends against it, because a function created that way in the dashboard runs with the postgres role's privileges. Its Row Level Security page adds that a security definer function in an exposed schema such as public is callable over the Data API with those privileges. Grant supabase_auth_admin what it needs instead.
Why does my HTTP hook show "Invalid payload sent to hook" instead of my own message?
Your hook answered with status 400. Supabase Auth reads the error message from the body only when the status is 200 or 202, and turns a 400 into "Invalid payload sent to hook" and a 401 into "Hook requires authorization token". Answer a refusal with 200 and {"error": {"message": "...", "http_code": 403}}.
How do I let people sign in again while I fix the hook?
Switch the hook off under Authentication, then Hooks, in your Supabase dashboard. Check what it was doing first. A Before User Created hook that blocked some sign-ups stops blocking them, and a claim the Custom Access Token hook added disappears from every token, so any rule that reads it treats everybody as not having it.