Skip to content

Conversation

@ThangHuuVu
Copy link
Member

@ThangHuuVu ThangHuuVu commented Jul 27, 2024

in #11050 we accidentally introduced a regression issue for the authorize function of the CredentialProvider. Returning null in this callback is now throwing a ConfigurationError which should not be the case.

This PR reverts the changes in #11050 and adds some tests to avoid regressing in the future.

Fixes #11074 #11190 #11428

@ThangHuuVu ThangHuuVu requested a review from 0ubbe as a code owner July 27, 2024 06:02
@vercel
Copy link

vercel bot commented Jul 27, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
auth-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 27, 2024 6:14am
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
next-auth-docs ⬜️ Ignored (Inspect) Visit Preview Jul 27, 2024 6:14am
proxy ⬜️ Ignored (Inspect) Visit Preview Jul 27, 2024 6:14am

@github-actions github-actions bot added the core Refers to `@auth/core` label Jul 27, 2024
@codecov
Copy link

codecov bot commented Jul 27, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.

Please upload report for BASE (main@c188390). Learn more about missing BASE report.

Files Patch % Lines
packages/core/src/lib/actions/callback/index.ts 50.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #11469   +/-   ##
=======================================
  Coverage        ?   40.02%           
=======================================
  Files           ?      179           
  Lines           ?    28682           
  Branches        ?     1258           
=======================================
  Hits            ?    11481           
  Misses          ?    17201           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@BertramYe
Copy link

but thre were problem, if we use the try....catch.... to wrap the signIn function, even we can catch the error we defined, but it won't auto redirect the path we want, even we have login in with correct credentails !!!!!!

@TruongNam0301
Copy link

i still cannot handle error message to return clientSide
`import { APP_ENV } from "@/constants/env.constant";
import { type NextAuthConfig } from "next-auth";
import Credentials from "next-auth/providers/credentials";
import Google from "next-auth/providers/google";

export default {
providers: [
Google({
clientId: APP_ENV.GOOGLE_CLIENT_ID,
clientSecret: APP_ENV.GOOGLE_CLIENT_SECRET,
}),
Credentials({
async authorize(credentials) {
const payload = {
email: credentials.email as string,
password: credentials.password as string,
};
throw new Error("Email not found");
// const user = await signin(payload);
// return user ?? null;
},
}),
],
pages: {
signIn: "/login",
error: "/login",
},
secret: APP_ENV.AUTH_SECRET,
} satisfies NextAuthConfig;
`
in clientSide always return this
image

@russssl
Copy link

russssl commented Nov 12, 2024

@TruongNam0301 Same error here. No metter what error is thrown, I always get 'Configuration'

@manishoctal
Copy link

Configuration is still there.

image

@domkoder
Copy link

domkoder commented Dec 9, 2024

Configuration is still there.

image

Same thing here, any luck @manishoctal @TruongNam0301

@manishoctal
Copy link

Not yet!!

@Zhavii
Copy link

Zhavii commented Jan 3, 2025

Really?

@iamdevlinph
Copy link

iamdevlinph commented Mar 20, 2025

I'm in "next-auth": "5.0.0-beta.25" and it's still happening. This is using the solution here

image

Update:

Fixed my issue by doing the following

#auth.config.ts
async authorize(credentials) {
  if (!credentials.email || !credentials.password) {
    return null;
  }

  try {
    const response = await fetch('/api/auth/login', {});
    const data = await response.json();

    if (!data.success) {
        throw new Error(data.message); // error from API
    }
    
    return data.data as User;
  } catch (e) {
    throw new InvalidLoginError((e as { message: string }).message);
  }
},
})

Create the following class

class InvalidLoginError extends CredentialsSignin {
  code = "custom";
  constructor(message: string) {
    super(message);
    this.code = message;
  }
}

And in the client

import { signIn } from "next-auth/react";

try {
  const res = await signIn("credentials", {
    redirect: false,
    ...data,
  });

  if (res?.error) {
    setLoginError(res.code as unknown as string);
  }
} catch (e) {
  console.error("Something went wrong trying to login", e);
}

@M-Ali-Haider
Copy link

@iamdevlinph I love you

@MauriRojas
Copy link

@iamdevlinph thank you, this is the only solution that worked.

@russssl
Copy link

russssl commented Jun 10, 2025

using better-auth now no such problems happening

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Refers to `@auth/core`

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CallbackRouteError on Credentials when following docs