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.

Using middleware results in INVALID_CALLBACK_URL_ERROR

See original GitHub issue

Environment

System: OS: macOS 12.4 CPU: (8) x64 Intel® Core™ i7-1068NG7 CPU @ 2.30GHz Memory: 348.10 MB / 32.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.13.2 - ~/.nvm/versions/node/v16.13.2/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 8.1.2 - ~/.nvm/versions/node/v16.13.2/bin/npm Browsers: Chrome: 102.0.5005.61 Firefox: 101.0 Safari: 15.5 npmPackages: next: ^12.0.11-canary.4 => 12.1.6 next-auth: latest => 4.4.0 react: ^17.0.2 => 17.0.2

Reproduction URL

https://github.com/nextauthjs/next-auth-example

Describe the issue

Using next-auth middleware with the latest version of Next (currently 12.1.6) doesn’t work.

The callbackUrl of withAuth is a relative URL. However, v12.0.9 of Next added “Enforce absolute URLs in Edge Runtime PR

Navigating to a page that is protected by middleware results in the user being redirected to http://localhost:3000/api/auth/signin?callbackUrl=%2Fadmin and an error message in the browser: image

How to reproduce

Steps to reproduce:

  1. Clone the next-auth-example repository
  2. Add a NEXTAUTH_SECRET in .env.local
  3. Start the dev server
  4. Go to localhost:3000 and click Admin

Result: Server error. The server log shows https://next-auth.js.org/errors#invalid_callback_url_error Invalid callback URL. Received: /admin InvalidCallbackUrl: Invalid callback URL. Received: /admin

Expected behavior

There should be a login form and no server errors.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:4
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
yanickrochoncommented, Aug 16, 2022

@danvernon my conclusion is that the signOut method is not clearning the cookie properly because clearing the cookie from the browser (through the dev console) removes this error. Next Auth should do a better job at validating it’s content before throwing errors at users.

4reactions
balazsorban44commented, Jun 13, 2022

This should be fixed in 4.5.0, please give it a try and let us know!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Errors - NextAuth.js
This error is a result of either a problem with the provider response or the ... The callbackUrl provided was either invalid or...
Read more >
next-auth credentials provider server error - Stack Overflow
INVALID_CALLBACK_URL_ERROR means that the callbackUrl provided was either invalid or not defined. See the NextAuth doc for more information.
Read more >
Invalid Callback Address Occurs When Calling the ... - 华为云
A callback address must contain the public IP address (or domain name), port number, and file path. A correct example is as follows:...
Read more >
URL Rewriting Middleware in ASP.NET Core - Microsoft Learn
This article introduces URL rewriting with instructions on how to use URL Rewriting Middleware in ASP.NET Core apps. URL rewriting is the ...
Read more >
A Guide to Error Handling in Express.js | Scout APM Blog
As a result, the equally (if not more) crucial error-handling part ... response sent back – no more middleware called }) app.use((req, res, ......
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