nextauthjs / nextauthjs/next-auth

Add helpful error message if redirectTo path is bad

Open
#13,231 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

triage
Dominant language
TypeScript
Stars
28.4k
Forks
4k
PR merge metrics
No merged PRs in 30d

Description

What is the improvement or update you wish to see?

It looks like the redirectTo path in the signIn method has to start with a forward slash. I accidentally passed a value without a slash (e.g. dashboard instead of /dashboard) which causes a fatal error in next.js.

The error messages shown to the developer are ambiguous. Either next.js reports an error in the LoginButton UI component which calls await signIn("microsoft-entra-id", { redirectTo }); or there is a "bad configuration" error page. There is no helpful stacktrace that could lead a developer to the issue.

A server error in the runtime that is caused by a string value is really hard to debug. Please add a check and a helpful error message for the signIn method.

Is there any context that might help us understand?

I spent way too long debugging a weird login issue that was caused by a relative path as a fallback value to redirectTo.

Does the docs page already exist? Please link to it.

I haven't found it, but the error should be shown in the Error.message and the error page.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the signIn method and the LoginButton UI component call await signIn("microsoft-entra-id", { redirectTo });, then reproduce the failure with dashboard as the redirectTo value. Done means an invalid relative path produces a helpful Error.message identifying the bad redirectTo value instead of an ambiguous runtime or configuration error.

Written by the indexing model from the issue text.

Assessment

Tech stack
nextjs, typescript
Domain
authentication
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.