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

Fix: Upgrade next-auth to fix auth example #830

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

raylworks
Copy link

@raylworks raylworks commented Aug 13, 2024

SYMPTOM

There is a behavior mismatch when I follow the Chapter 15 Adding Authentication - Updating the login form

For the function authenticate of /app/lib/actions.ts:

export async function authenticate(prevState: string | undefined, formData: FormData) {
  try {
    await signIn('credentials', formData);
  } catch (error) {
    if (error instanceof AuthError) {
      switch (error.type) {
        case 'CredentialsSignin':    // <-- Should Go Into Here
          return 'Invalid credentials.';
        default:    // <-- But Go Into Here
          return 'Something went wrong.';
      }
    }
    throw error;
  }
}

When I input the right email and wrong password, it should throw the CredentialsSignin error, but acutally it throws CallbackRouteError. The consequence is, the UI shows error message "Something went wrong." instead of "Invalid credentials.".

Reference:

CAUSE

The cause is the package [email protected].

Many next-auth users report same issue that, they found next-auth throws CallbackRouteError instead of CredentialsSignin. The issue is narrowed down to [email protected], there is a code change breaks error type contract.

Reference:

FIX

The next-auth team's noticed this issue and fixed it in new version, [email protected]. So we can upgrade to [email protected] to fix the authentication behavior.

Reference:

Copy link

vercel bot commented Aug 13, 2024

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

Name Status Preview Comments Updated (UTC)
next-learn-starter ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 13, 2024 6:32am
next-seo-starter ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 13, 2024 6:32am

Copy link

vercel bot commented Aug 13, 2024

@raylworks is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/[email protected] environment Transitive: network +9 4.05 MB thvu

🚮 Removed packages: npm/[email protected]

View full report↗︎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant