Hook requires authorization token
I think it is not relevant but just for context I am setting up password-less auth using magic links in my project.
I have a custom auth hook in my local running instance for sending emails.
I am getting this following error:
Here is the relevant section in my
config.toml
file:
What could be the reason for this? The error goes away if I remove the auth hook.19 Replies
Maybe show your hook code.
I would log out your hook secret in the function. Seems like it is not getting to the webhook call.
I did that just now in the first line of the function. It seems this api is even being called at all by supabase.
The error is happening before that imo.
Also looking at the code from the guide it uses Deno.env not sure that is critical or not.
Your edge function is not running?
Not going to be much help as this appears to be a local dev environment.
Not exactly sure what your uri is pointing to, but there may be multiple ways to do this.
https://supabase.com/docs/guides/auth/auth-hooks?queryGroups=language&language=http#local-development

I guess you are not using an edge function.
My uri points to my own nextjs api. I am not using an edge function. I dont think that should be an issue.
I could be wrong...
Not messed with local hooks.
The error seems to be though the webhook library call not having the token.
That is why I think it must be something else. Since the api is being called from inside supabase sdk, the addition of the auth token in the header is not under my scope, right?
This is the token you generated for the webhook and stored in the env data I believe.
I'm thinking it is that:

Oh. That token is definitely in my env file. I am passing it in the config file too:
Right. I'm just saying I think the error is that Webhook call saying it is not getting it.
Do you have any other auth webhooks running?
No. That is the only one.
The error message is clearly saying a hook is getting the error, and you don't pass in any sort of JWT token, just the secret.
Nothing in your code seems to generate the message, but I guess you also say it is not running.
Just to confirm, I tested with a random webhook from
webhook.site
too jsut now and it did not get any event.
I will test another thing now. I will comment out the secrets line to see how it behavesI guess there could be something going wrong in the supabase auth code at the point it calls your hook (hence the hook requires part of the error).. But I don't know how you would cause the Auth API call to not have a token.
That message though in quotes "Hook requires authorization token" does not appear on the web....
Yeah. I googled it too and did not find anything.
Alright. So I fixed it. You were right. That secret was not being passed correctly. There were two issues actually:
- I was resetting and not restarting my local instance (silly mistake) - so any config changes were not taking effect.
- I was not passing the env file to those commands. I feel like if the config file uses
env(SOME_ENV_VAR)
, it should be throwing an error for it if it cant find it.
Anyway, thanks for pointing me in the right direction.Sometimes I amaze myself stumbling thru stuff I've never used... Glad it helped.