question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Callback hell (?)

See original GitHub issue

When auth fails, it goes back to the site it was called from, and so we end up having something like http://localhost:3000/?callbackUrl=http://localhost:3000/?callbackUrl=http://localhost:3000/

and it will keep adding the callbackUrl again and again…

would you mind doing something to prevent this from happening?

thanks in advance

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
balazsorban44commented, Apr 12, 2021

Would you please share the full next-auth configuration and your / page?

0reactions
balazsorban44commented, Jul 19, 2021

So it’s a bit hard to debug without a runnable reproduction, but your issue might be here:

  const handleSubmit = async (e) => {
    e.preventDefault();
    if (isForSignIn) {
      signIn('credentials', {
        email,
        password,
        callbackUrl: `${window.location.origin}/`, // <--
      });
    } 

You don’t really check if there is already a callbackUrl here. I also wonder if auth fails as you mention, shouldn’t there be an error query parameter as well in the URL?

I think there should be an error parameter, and so you should handle those cases appropriately since you defined a custom sign-in page. See the docs for possible error codes: https://next-auth.js.org/configuration/pages#sign-in-page

And here is the default sign-in page and error messages for reference:

https://github.com/nextauthjs/next-auth/blob/bcb9383aecaee490ba0c4979f3d0f5b0457924a3/src/server/pages/signin.js#L23-L36

(See the whole file for inspiration)

In any case, I am certain it is not a bug in next-auth, so I’ll transfer this to discussions. Feel free to ask further if you have more questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Callback Hell
The cause of callback hell is when people try to write JavaScript in a way where execution happens visually from top to bottom....
Read more >
What to understand Callback and Callback hell in JavaScript
Callback Hell : Callback Hell is essentially nested callbacks stacked below one another forming a pyramid structure. Every callback depends/waits ...
Read more >
How to deal with nested callbacks and avoid “callback hell”
Constructing a callback hell · Get ingredients (we're gonna assume it's a beef burger) · Cook the beef · Get burger buns ·...
Read more >
Callback Hell and How to Rescue it
Callbacks is a great way of handling asynchronous behavior in javascript. In JavaScript, everything behaves like an object so functions have the ...
Read more >
Saved from Callback Hell
Callback hell is real. Developers often see callbacks as pure evil, even to the point of avoiding them. JavaScriptʼs flexibility doesn't ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found