Next Auth authorize function getting executed twice
Unanswered
Spectacled bear posted this in #help-forum
Spectacled bearOP
Hi there, I'm using next auth for my next application. My authorize function is getting called twice and im getting a error since the api Im calling inside the authorize is expecting a token which is valid for the first time, second time it throws error of 404 (server implementation)
Is it expected like authorize function getting called twice?
Is it expected like authorize function getting called twice?
17 Replies
Spectacled bearOP
Bump
@Spectacled bear Hi there, I'm using next auth for my next application. My authorize function is getting called twice and im getting a error since the api Im calling inside the authorize is expecting a token which is valid for the first time, second time it throws error of 404 (server implementation)
Is it expected like authorize function getting called twice?
something is causing component auth function is in to re-render. find what is causing the re-render and then it should work
Brown bear
it only happens on development and exactly when using strict mode
it will not occur on production
So you just need to fix 404 error - i think your api endpoint doesn't correct
If you dont' want to stric mode, update the config like this
module.exports = {
reactStrictMode: false,
};@Brown bear it only happens on development and exactly when using strict mode
Spectacled bearOP
yeah i got this, but what's the fix for this? I don't want to turn off the strict mode for whole app. Im getting error since im returning null from authorize and hence redirecting to login screen,
Brown bear
Did you fix 404 error?
Spectacled bearOP
I turned the strict mode to false
Brown bear
Then, what issue do you have?
Spectacled bearOP
I don't want to turn off the react strict mode
@Brown bear Did you fix 404 error?
Brown bear
?
Spectacled bearOP
For this issue, i turned it off and it worked but i dont want to turn it off. Is there a way to fix this by keeping the strict mode as true?
Brown bear
I can't know without checking any error message
You would be upload the error message screenshot to get clear help
Your authorize function is called from within a hook. The double execution is a React mechanism to make sure your hook does not have unexpected side-effects. If your hook does not work well when executed twice then you should restructure your code to fix this issue.
@Willem Liu Your authorize function is called from within a hook. The double execution is a React mechanism to make sure your hook does not have unexpected side-effects. If your hook does not work well when executed twice then you should restructure your code to fix this issue.
Swainson's Thrush
Yes call your
signIn function on events like onClick.