nextauthjs / nextauthjs/next-auth

sendVerificationRequest exceptions not caught, and return to client is ok

Open
#13,124 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Provider type

Email

Environment
 System:
    OS: macOS 15.5
    CPU: (8) arm64 Apple M1
    Memory: 450.28 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.17.1 - /opt/homebrew/opt/node@22/bin/node
    npm: 10.9.2 - /opt/homebrew/opt/node@22/bin/npm
    pnpm: 10.13.1 - /opt/homebrew/bin/pnpm
  Browsers:
    Chrome: 138.0.7204.158
    Safari: 18.5
  npmPackages:
    next: 14.2.30 => 14.2.30 
    next-auth: ^4.24.11 => 4.24.11 
    react: ^18 => 18.3.1 
Reproduction URL

https://github.com/palminha/next-auth-signin-exception

Describe the issue

I login with client signIn and i want to return an error from sendVerificationRequest, and for that i throw an exception.
The exception is not caugh and in the client the returned value is ok, 200, with error string EmailSignin

How to reproduce
  1. Run the example attached
  2. Go to http://localhost:3000
  3. Click in login
  4. See the result
{
"error":"EmailSignin",
"status":200,
"ok":true,
"url":null
}
  1. see the exception not caught in the server
next-auth][error][SIGNIN_EMAIL_ERROR] 
https://next-auth.js.org/errors#signin_email_error Not a valid user {
  error: {
    message: 'Not a valid user',
    stack: 'Error: Not a valid user\n' +
      '    at Object.sendVerificationRequest (webpack-internal:///(rsc)/./src/app/api/auth/[...nextauth]/route.ts:37:23)\n' +
      '    at email (webpack-internal:///(rsc)/./node_modules/next-auth/core/lib/email/signin.js:27:31)\n' +
      '    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n' +
      '    at async Object.signin (webpack-internal:///(rsc)/./node_modules/next-auth/core/routes/signin.js:102:24)\n' +
      '    at async AuthHandler (webpack-internal:///(rsc)/./node_modules/next-auth/core/index.js:221:26)\n' +
      '    at async NextAuthRouteHandler (webpack-internal:///(rsc)/./node_modules/next-auth/next/index.js:57:28)\n' +
      '    at async NextAuth._args$ (webpack-internal:///(rsc)/./node_modules/next-auth/next/index.js:89:16)\n' +
      '    at async /Users/palmito/Development/next-auth-signin-exception/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:57228\n' +
      '    at async eT.execute (/Users/palmito/Development/next-auth-signin-exception/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:46851)\n' +
      '    at async eT.handle (/Users/palmito/Development/next-auth-signin-exception/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:58760)\n' +
      '    at async doRender (/Users/palmito/Development/next-auth-signin-exception/node_modules/next/dist/server/base-server.js:1366:42)\n' +
      '    at async cacheEntry.responseCache.get.routeKind (/Users/palmito/Development/next-auth-signin-exception/node_modules/next/dist/server/base-server.js:1576:40)\n' +
      '    at async DevServer.renderToResponseWithComponentsImpl (/Users/palmito/Development/next-auth-signin-exception/node_modules/next/dist/server/base-server.js:1496:28)\n' +
      '    at async DevServer.renderPageComponent (/Users/palmito/Development/next-auth-signin-exception/node_modules/next/dist/server/base-server.js:1924:24)\n' +
      '    at async DevServer.renderToResponseImpl (/Users/palmito/Development/next-auth-signin-exception/node_modules/next/dist/server/base-server.js:1962:32)\n' +
      '    at async DevServer.pipeImpl (/Users/palmito/Development/next-auth-signin-exception/node_modules/next/dist/server/base-server.js:922:25)\n' +
      '    at async NextNodeServer.handleCatchallRenderRequest (/Users/palmito/Development/next-auth-signin-exception/node_modules/next/dist/server/next-server.js:272:17)\n' +
      '    at async DevServer.handleRequestImpl (/Users/palmito/Development/next-auth-signin-exception/node_modules/next/dist/server/base-server.js:818:17)\n' +
      '    at async /Users/palmito/Development/next-auth-signin-exception/node_modules/next/dist/server/dev/next-dev-server.js:339:20\n' +
      '    at async Span.traceAsyncFn (/Users/palmito/Development/next-auth-signin-exception/node_modules/next/dist/trace/trace.js:154:20)\n' +
      '    at async DevServer.handleRequest (/Users/palmito/Development/next-auth-signin-exception/node_modules/next/dist/server/dev/next-dev-server.js:336:24)\n' +
      '    at async invokeRender (/Users/palmito/Development/next-auth-signin-exception/node_modules/next/dist/server/lib/router-server.js:179:21)\n' +
      '    at async handleRequest (/Users/palmito/Development/next-auth-signin-exception/node_modules/next/dist/server/lib/router-server.js:359:24)\n' +
      '    at async requestHandlerImpl (/Users/palmito/Development/next-auth-signin-exception/node_modules/next/dist/server/lib/router-server.js:383:13)\n' +
      '    at async Server.requestListener (/Users/palmito/Development/next-auth-signin-exception/node_modules/next/dist/server/lib/start-server.js:141:13)',
    name: 'Error'
  },
  providerId: 'email',
  message: 'Not a valid user'
Expected behavior
  • The exception is caught in the server
  • The return object should be like this
{
"error":"The exception error message",
"status":500,
"ok":false,
"url":null
}

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 with core/lib/email/signin.js and core/routes/signin.js, which appear in the reported stack trace, then trace how the client signIn result is formed. Reproduce the email-provider failure from the linked example and verify that the exception is caught and the client receives the expected error, 500 status, ok false, and null URL.

Written by the indexing model from the issue text.

Assessment

Tech stack
nextjs, nodejs, react, typescript
Domain
api, authentication, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.