Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[auth][error] CredentialsSignin, when return null for CredentialsProvider in the authorize function. #9900

Closed
AmphibianDev opened this issue Feb 4, 2024 · 32 comments
Labels
bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@AmphibianDev
Copy link

Environment

System:
OS: Windows 11 10.0.22631
CPU: (24) x64 AMD Ryzen 9 3900X 12-Core Processor
Memory: 25.36 GB / 47.93 GB
Binaries:
Node: 20.11.0 - C:\Program Files\nodejs\node.EXE
npm: 10.2.4 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Chromium (121.0.2277.98)
Internet Explorer: 11.0.22621.1
npmPackages:
@auth/prisma-adapter: ^1.2.1 => 1.2.1
next: 14.1.0 => 14.1.0
next-auth: ^5.0.0-beta.5 => 5.0.0-beta.5
react: ^18 => 18.2.0

Reproduction URL

https://github.com/AmphibianDev/todo-app/tree/main

Describe the issue

The error occurs only when authorize returns null, if it's returning a user, it works.

How to reproduce

auth.config.ts

import { NextAuthConfig } from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";

export default {
  providers: [
    CredentialsProvider({
      async authorize(credentials, req) {
        return null;
      },
    }),
  ],
} satisfies NextAuthConfig;

auth.ts

import NextAuth from "next-auth";
import authConfig from "@/auth.config";
import prisma from "@/lib/prisma";
import { PrismaAdapter } from "@auth/prisma-adapter";

export const {
  handlers: { GET, POST },
  auth,
  signIn,
  signOut,
} = NextAuth({ adapter: PrismaAdapter(prisma), session: { strategy: "jwt" }, ...authConfig });

Error:

[auth][error] CredentialsSignin: Read more at https://errors.authjs.dev#credentialssignin
    at Module.callback (C:\Users\Work\Desktop\todo-app\.next\server\chunks\node_modules_f27a4e._.js:2982:30)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Module.AuthInternal (C:\Users\Work\Desktop\todo-app\.next\server\chunks\node_modules_f27a4e._.js:3597:24)
    at async Module.Auth (C:\Users\Work\Desktop\todo-app\.next\server\chunks\node_modules_f27a4e._.js:3722:29)
    at async Module.signIn (C:\Users\Work\Desktop\todo-app\.next\server\chunks\node_modules_edd83f._.js:3286:17)
    at async logInAction (C:\Users\Work\Desktop\todo-app\.next\server\chunks\[root of the server]__19aaaf._.js:351:9)
    at async C:\Users\Work\Desktop\todo-app\node_modules\next\dist\compiled\next-server\app-page.runtime.dev.js:39:406
    at async t4 (C:\Users\Work\Desktop\todo-app\node_modules\next\dist\compiled\next-server\app-page.runtime.dev.js:38:6379)
    at async rk (C:\Users\Work\Desktop\todo-app\node_modules\next\dist\compiled\next-server\app-page.runtime.dev.js:39:25934)
    at async doRender (C:\Users\Work\Desktop\todo-app\node_modules\next\dist\server\base-server.js:1394:30)
    at async cacheEntry.responseCache.get.routeKind (C:\Users\Work\Desktop\todo-app\node_modules\next\dist\server\base-server.js:1555:28)
    at async DevServer.renderToResponseWithComponentsImpl (C:\Users\Work\Desktop\todo-app\node_modules\next\dist\server\base-server.js:1463:28)
    at async DevServer.renderPageComponent (C:\Users\Work\Desktop\todo-app\node_modules\next\dist\server\base-server.js:1856:24)       
    at async DevServer.renderToResponseImpl (C:\Users\Work\Desktop\todo-app\node_modules\next\dist\server\base-server.js:1894:32)      
    at async DevServer.pipeImpl (C:\Users\Work\Desktop\todo-app\node_modules\next\dist\server\base-server.js:911:25)
    at async NextNodeServer.handleCatchallRenderRequest (C:\Users\Work\Desktop\todo-app\node_modules\next\dist\server\next-server.js:271:17)
    at async DevServer.handleRequestImpl (C:\Users\Work\Desktop\todo-app\node_modules\next\dist\server\base-server.js:807:17)
    at async C:\Users\Work\Desktop\todo-app\node_modules\next\dist\server\dev\next-dev-server.js:331:20
    at async Span.traceAsyncFn (C:\Users\Work\Desktop\todo-app\node_modules\next\dist\trace\trace.js:151:20)
    at async DevServer.handleRequest (C:\Users\Work\Desktop\todo-app\node_modules\next\dist\server\dev\next-dev-server.js:328:24)      
    at async invokeRender (C:\Users\Work\Desktop\todo-app\node_modules\next\dist\server\lib\router-server.js:163:21)
    at async handleRequest (C:\Users\Work\Desktop\todo-app\node_modules\next\dist\server\lib\router-server.js:342:24)
    at async requestHandlerImpl (C:\Users\Work\Desktop\todo-app\node_modules\next\dist\server\lib\router-server.js:366:13)
    at async Server.requestListener (C:\Users\Work\Desktop\todo-app\node_modules\next\dist\server\lib\start-server.js:140:13)

Expected behavior

Rejecting the singin attempt without throwing a server error in the console, and showing the user "Invalid credentials"

"use server";

import { signIn } from "@/auth";
import { $LogInSchema, LogInSchema } from "@/lib/validation";
import { DEFAULT_LOGIN_REDIRECT } from "@/routes";
import { AuthError } from "next-auth";

export async function logInAction(formData: LogInSchema) {
  const validatedFields = $LogInSchema.safeParse(formData);

  if (!validatedFields.success) return { error: "Invalid fields" };

  const { email, phone } = validatedFields.data;

  try {
    await signIn("credentials", { email, phone, redirectTo: DEFAULT_LOGIN_REDIRECT });
  } catch (error) {
    if (error instanceof AuthError) {
      switch (error.type) {
        case "CredentialsSignin":
          return { error: "Invalid credentials" };
        default:
          return { error: "Something went wrong" };
      }
    }

    throw error;
  }
}
@AmphibianDev AmphibianDev added bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Feb 4, 2024
@AmphibianDev AmphibianDev changed the title Next.js Server Error when return null for CredentialsProvider, authorize function. [auth][error] CredentialsSignin, when return null for CredentialsProvider in the authorize function. Feb 4, 2024
@balazsorban44
Copy link
Member

Returning null will show this error, this is currently expected. You can follow the development on #9099 for customizing the returned error type.

@Jay-Karia
Copy link
Contributor

Here is the code solution:

Try adding a new case to your switch statement:

if (error instanceof AuthError) {
      switch (error.type) {
                case "CredentialsSignin":
                    return { msg: "Invalid credentials" , status: "error"};
                case "CredentialsSignin":
                    throw error;
                default:
                    return { msg: "Something went wrong", status: "error" };
            }
    }

This works for me!

@AdanSerrano
Copy link

great, error resolve @Jay-Karia

@BinaryScary
Copy link

BinaryScary commented Apr 1, 2024

@Jay-Karia's fix does not seem to work for me, "[auth][error] CredentialsSignin" logs are still printed to the console even with the additional switch case.

Is there really no method to handle invalid credentials in authenticate without throwing an error?

[auth][error] CredentialsSignin: Read more at https://errors.authjs.dev#credentialssignin
    at Module.callback (webpack-internal:///(action-browser)/./node_modules/@auth/core/lib/actions/callback/index.js:225:23)
    at async AuthInternal (webpack-internal:///(action-browser)/./node_modules/@auth/core/lib/index.js:66:24)
    at async Auth (webpack-internal:///(action-browser)/./node_modules/@auth/core/index.js:126:34)
    at async signIn (webpack-internal:///(action-browser)/./node_modules/next-auth/lib/actions.js:51:17)
    at async authenticate (webpack-internal:///(action-browser)/./app/lib/appAuth.js:20:9)
    at async /Users/samwong/Security/Projects/imhere/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:39:406
    at async t2 (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:38:6412)
    at async rS (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:41:1369)
    at async doRender (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/base-server.js:1378:30)
    at async cacheEntry.responseCache.get.routeKind (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/base-server.js:1539:28)
    at async DevServer.renderToResponseWithComponentsImpl (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/base-server.js:1447:28)
    at async DevServer.renderPageComponent (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/base-server.js:1844:24)
    at async DevServer.renderToResponseImpl (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/base-server.js:1882:32)
    at async DevServer.pipeImpl (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/base-server.js:895:25)
    at async NextNodeServer.handleCatchallRenderRequest (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/next-server.js:269:17)
    at async DevServer.handleRequestImpl (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/base-server.js:791:17)
    at async /Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/dev/next-dev-server.js:331:20
    at async Span.traceAsyncFn (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/trace/trace.js:151:20)
    at async DevServer.handleRequest (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/dev/next-dev-server.js:328:24)
    at async invokeRender (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/lib/router-server.js:174:21)
    at async handleRequest (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/lib/router-server.js:353:24)
    at async requestHandlerImpl (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/lib/router-server.js:377:13)
    at async Server.requestListener (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/lib/start-server.js:140:13)

@liroyleshed
Copy link

@Jay-Karia's fix does not seem to work for me, "[auth][error] CredentialsSignin" logs are still printed to the console even with the additional switch case.

Is there really no method to handle invalid credentials in authenticate without throwing an error?

[auth][error] CredentialsSignin: Read more at https://errors.authjs.dev#credentialssignin
    at Module.callback (webpack-internal:///(action-browser)/./node_modules/@auth/core/lib/actions/callback/index.js:225:23)
    at async AuthInternal (webpack-internal:///(action-browser)/./node_modules/@auth/core/lib/index.js:66:24)
    at async Auth (webpack-internal:///(action-browser)/./node_modules/@auth/core/index.js:126:34)
    at async signIn (webpack-internal:///(action-browser)/./node_modules/next-auth/lib/actions.js:51:17)
    at async authenticate (webpack-internal:///(action-browser)/./app/lib/appAuth.js:20:9)
    at async /Users/samwong/Security/Projects/imhere/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:39:406
    at async t2 (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:38:6412)
    at async rS (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:41:1369)
    at async doRender (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/base-server.js:1378:30)
    at async cacheEntry.responseCache.get.routeKind (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/base-server.js:1539:28)
    at async DevServer.renderToResponseWithComponentsImpl (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/base-server.js:1447:28)
    at async DevServer.renderPageComponent (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/base-server.js:1844:24)
    at async DevServer.renderToResponseImpl (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/base-server.js:1882:32)
    at async DevServer.pipeImpl (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/base-server.js:895:25)
    at async NextNodeServer.handleCatchallRenderRequest (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/next-server.js:269:17)
    at async DevServer.handleRequestImpl (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/base-server.js:791:17)
    at async /Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/dev/next-dev-server.js:331:20
    at async Span.traceAsyncFn (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/trace/trace.js:151:20)
    at async DevServer.handleRequest (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/dev/next-dev-server.js:328:24)
    at async invokeRender (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/lib/router-server.js:174:21)
    at async handleRequest (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/lib/router-server.js:353:24)
    at async requestHandlerImpl (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/lib/router-server.js:377:13)
    at async Server.requestListener (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/lib/start-server.js:140:13)

100%

@LabelMinsk
Copy link

LabelMinsk commented May 7, 2024

@Jay-Karia's fix does not seem to work for me, "[auth][error] CredentialsSignin" logs are still printed to the console even with the additional switch case.

Is there really no method to handle invalid credentials in authenticate without throwing an error?

[auth][error] CredentialsSignin: Read more at https://errors.authjs.dev#credentialssignin
    at Module.callback (webpack-internal:///(action-browser)/./node_modules/@auth/core/lib/actions/callback/index.js:225:23)
    at async AuthInternal (webpack-internal:///(action-browser)/./node_modules/@auth/core/lib/index.js:66:24)
    at async Auth (webpack-internal:///(action-browser)/./node_modules/@auth/core/index.js:126:34)
    at async signIn (webpack-internal:///(action-browser)/./node_modules/next-auth/lib/actions.js:51:17)
    at async authenticate (webpack-internal:///(action-browser)/./app/lib/appAuth.js:20:9)
    at async /Users/samwong/Security/Projects/imhere/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:39:406
    at async t2 (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:38:6412)
    at async rS (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:41:1369)
    at async doRender (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/base-server.js:1378:30)
    at async cacheEntry.responseCache.get.routeKind (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/base-server.js:1539:28)
    at async DevServer.renderToResponseWithComponentsImpl (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/base-server.js:1447:28)
    at async DevServer.renderPageComponent (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/base-server.js:1844:24)
    at async DevServer.renderToResponseImpl (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/base-server.js:1882:32)
    at async DevServer.pipeImpl (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/base-server.js:895:25)
    at async NextNodeServer.handleCatchallRenderRequest (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/next-server.js:269:17)
    at async DevServer.handleRequestImpl (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/base-server.js:791:17)
    at async /Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/dev/next-dev-server.js:331:20
    at async Span.traceAsyncFn (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/trace/trace.js:151:20)
    at async DevServer.handleRequest (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/dev/next-dev-server.js:328:24)
    at async invokeRender (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/lib/router-server.js:174:21)
    at async handleRequest (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/lib/router-server.js:353:24)
    at async requestHandlerImpl (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/lib/router-server.js:377:13)
    at async Server.requestListener (/Users/samwong/Security/Projects/imhere/node_modules/next/dist/server/lib/start-server.js:140:13)

Did you win it?

@LabelMinsk
Copy link

I have win it. But it looks like a crutch. Before use signIn('credentials',{...}) execute checkup on isExisting smt if result will be null we return {error: 'error'} and if we found for example user we got pure data to method signIn.
It is crutch dont got [auth][error] exeption

@missile-developer
Copy link

Why it this closed ?

@a-shalda
Copy link

a-shalda commented May 8, 2024

I do not know about you guys, but I could not find a good way to handle errors in v5, so I switched to v4 instead

@Jay-Karia
Copy link
Contributor

I agree with all of you about the error logs, but it solves the errors at frontend in the development server.

@negati-ve
Copy link

This needs to be reopened

@neil-py
Copy link

neil-py commented May 21, 2024

I have win it. But it looks like a crutch. Before use signIn('credentials',{...}) execute checkup on isExisting smt if result will be null we return {error: 'error'} and if we found for example user we got pure data to method signIn. It is crutch dont got [auth][error] exeption

so far, this is the only solution I can do with V5; simply check if the user actually exists or is valid before calling the authorization. It's not the best approach, unlike v4, but there's nothing we can do.

@wrongbyte
Copy link

wrongbyte commented May 23, 2024

Returning null will show this error, this is currently expected. You can follow the development on #9099 for customizing the returned error type.

@balazsorban44 so every time a login fails it will spawn an error on server side? It doesn't sound right to me. We should be able to handle failed login cases without treating it as an error, since it is not an error at all.

@iamvladw
Copy link

Returning null will show this error, this is currently expected. You can follow the development on #9099 for customizing the returned error type.

@balazsorban44 so every time a login fails it will spawn an error on server side? It doesn't sound right to me. We should be able to handle failed login cases without treating it as an error, since it is not an error at all.

I get it, it's frustrating as well, I am trying to find a good error handling method also but nothing seems to work. We need to understand tho that v5 is still in beta and it's not meant for production.

@wrongbyte
Copy link

wrongbyte commented May 29, 2024

Okay, I've just found a very stupid workaround (which is definitely not optimal, but solves this for now).

Supposing that authenticate is the server action that calls the signIn method from next auth, you'll have to do something like this in your login form:

  const onSubmit = async (formData: LoginUserPayload) => {
    try {
      // The function that calls your credentials API
      await loginUser(formData);
      /**
       * If the previously call to `loginUser` is not successful (i.e login not successful), 
       * the control flow is passed to the catch block, therefore we only call the authenticate 
       * action if the response is 200, preventing the next-auth error to happen.
       * https://github.com/nextauthjs/next-auth/issues/9900
       */
      await authenticate(formData)
    } catch (e) {
      // handle the error (which should be an Axios error or similar) here.
      setAuthError("Incorrect email or password")
    }
  };

Basically, you only call the next-auth methods if you are sure that the login is going to be successful (what is, you don't handle the failed login using next auth). This results in two repeated requests (in the successful case), but I could not find any other solution at the moment.

@aespinoza96
Copy link

aespinoza96 commented Jun 3, 2024

I tried the solution they suggest, create a custom error class that extends from CredentialsSignIn and set a code. however, if condition to redirect is false, I am just getting a "Configuration" type error and code is empty. This has not been solved or I am not doing something right.

@lucho20pt
Copy link

// login.ts

"use server"
import { z } from 'zod'
import { AuthError } from 'next-auth'
import { signIn } from '@/auth'

import { LoginSchema } from '@/schema'
import { DEFAULT_LOGIN_REDIRECT } from '@/routes'

export const login = async (values: z.infer<typeof LoginSchema>) => {
  const validatedFields = LoginSchema.safeParse(values)

  if (!validatedFields.success) {
    return { error: 'Invalid fields!' }
  }

  const { email, password } = validatedFields.data

  try {
    const resultSignIn = await signIn('credentials', {
      email,
      password,
      redirectTo: DEFAULT_LOGIN_REDIRECT,
    })

    if (!resultSignIn) {
      throw new Error('Sign in failed')
    }
  } catch (error) {
    if (error instanceof AuthError) {
      switch (error.type) {
        case 'CredentialsSignin':
          return { error: 'Invalid Credentials!' }
        default:
          return { error: 'Something went wrong!' }
      }
    }
    throw error
  }
}

I never get to hit the case 'CredentialsSignin' return with wrong email, password, etc... it always return me just the default!
Can i do something about it ?

@cedrickring
Copy link

cedrickring commented Jun 14, 2024

This mechanism actually works in 5.0.0-beta.19 if you build together an error like this, which passes the required checks in callback.ts:

import { AuthError } from 'next-auth';

class InvalidCredentials extends AuthError {
  public readonly kind = 'signIn';

  constructor() {
    super('Invalid credentials');
    this.type = 'CredentialsSignin';
  }
}

Especially the type and kind are important. If you don't specify a kind, you will be routed to the error page on any error you throw.

@Jes015
Copy link

Jes015 commented Jun 17, 2024

Bro, this is horrible, why not just not show an error when null is returned?

@dsmabulage
Copy link

This mechanism actually works in 5.0.0-beta.19 if you build together an error like this, which passes the required checks in callback.ts:

import { AuthError } from 'next-auth';

class InvalidCredentials extends AuthError {
  public readonly kind = 'signIn';

  constructor() {
    super('Invalid credentials');
    this.type = 'CredentialsSignin';
  }
}

Especially the type and kind are important. If you don't specify a kind, you will be routed to the error page on any error you throw.

async authorize({ email, password }) {
        throw new InvalidCredentials();
      },

I tried this but it wont return error to the client side

@dsmabulage
Copy link

Bro, this is horrible, why not just not show an error when null is returned?

I have some additional conditions that I want to send to the user, other than the invalid credentials.

@sharkydeveloping
Copy link

sharkydeveloping commented Jun 28, 2024

i have the same problem, but this

import { AuthError } from 'next-auth';

class InvalidCredentials extends AuthError {
  public readonly kind = 'signIn';

  constructor() {
    super('Invalid credentials');
    this.type = 'CredentialsSignin';
  }
}

fix it

@dileepainivossl
Copy link

i have the same problem, but this

import { AuthError } from 'next-auth';

class InvalidCredentials extends AuthError {
  public readonly kind = 'signIn';

  constructor() {
    super('Invalid credentials');
    this.type = 'CredentialsSignin';
  }
}

fix it

This wont return a custom message right?

image

@christensen143
Copy link

I think I found a "work around" for this that is much easier to work with than suggested work around.

  1. The CredentialsSignin error is nested within the cause property of the CallbackRouteError.
  2. The cause object has an err property which is the CredentialsSignin error.
  3. The CredentialsSignin error has a code property set to 'credentials'.
try {
    await signIn('credentials', {
      email,
      password,
      redirectTo: DEFAULT_LOGIN_REDIRECT,
    });
  } catch (error) {
    if (error instanceof AuthError) {
      switch (error.type) {
        case 'CallbackRouteError':
          if (
            error.cause &&
            typeof error.cause === 'object' &&
            'err' in error.cause
          ) {
            const cause = error.cause as { err: { code?: string } };
            if (cause.err && cause.err.code === 'credentials') {
              return { error: 'Invalid credentials' };
            }
          }
        default:
          return { error: 'An authentication error occurred' };
      }
    }

    throw error;
  }

@JulianMiguelAngle
Copy link

is it teribble? 😂

@JulianMiguelAngle
Copy link

Returning null will show this error, this is currently expected. You can follow the development on #9099 for customizing the returned error type.

Lucia auth 😘
next auth 💀

@plutack
Copy link

plutack commented Jul 24, 2024

errors as values 😭
edit: After going through the documentation, as much as this is exactly how next specifies this is exactly how this should behave , it rubs off on me wrong.
Does this behavior carry over to production too?

@JasonDsouza212
Copy link

I guess calling the sign-in method only after we are sure that the credentials are valid is the way to go for now. I believe implementing this would be one possible solution

@plutack
Copy link

plutack commented Aug 1, 2024

I guess calling the sign-in method only after we are sure that the credentials are valid is the way to go for now. I believe implementing this would be one possible solution

I am starting to wonder if it is really a big deal if it does throws an error that panics...seems like it is already handled with a console log
Some correct me if I am wrong

@wzrdx
Copy link

wzrdx commented Aug 7, 2024

I guess calling the sign-in method only after we are sure that the credentials are valid is the way to go for now. I believe implementing this would be one possible solution

I am starting to wonder if it is really a big deal if it does throws an error that panics...seems like it is already handled with a console log Some correct me if I am wrong

I'm also wondering the same thing

@cherylli
Copy link

cherylli commented Aug 7, 2024

I think It was just a bit confusing when following the docs, especially when someone is newish to nextauth and v5, it does not produce the expected result

@plutack
Copy link

plutack commented Aug 7, 2024

I think It was just a bit confusing when following the docs, especially when someone is newish to nextauth and v5, it does not produce the expected result

I definitely think it is a weird behaviour but the docs clearly state this is the expected behaviour
ref: https://authjs.dev/reference/express#credentialssignin
if you scroll down to NOTE. I thought perhaps setting debug to false solves it or maybe in production this error isn't logged this way.
the debug false didn't work and since I am still working on my prject, I am yet to actually see what the beahviour looks like in prod.
I have decided to embrace the behaviour as it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Projects
None yet
Development

No branches or pull requests