I can't seem to resolve this error after searching extensively on the web.
For more information, visit [auth][error] CallbackRouteError: For more details, please visit https://errors.authjs.dev#callbackrouteerror [auth][cause]: Error at Module.callback (webpack-internal:///(action-browser)/./node_modules/@auth/core/lib/actions/callback/index.js:226: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 $$ACTION_0 (webpack-internal:///(action-browser)/./src/actions/login.ts:30:9) at async C:\Users\me\WebstormProjects\Project-L\node_modules\next\dist\compiled\next-server\app-page.runtime.dev.js:39:418 at async rS (C:\Users\me\WebstormProjects\Project-L\node_modules\next\dist\compiled\next-server\app-page.runtime.dev.js:38:7978) at async r2 (C:\Users\me\WebstormProjects\Project-L\node_modules\next\dist\compiled\next-server\app-page.runtime.dev.js:41:1251) at async doRender (C:\Users\me\WebstormProjects\Project-L\node_modules\next\dist\server\base-server.js:1438:30) at async cacheEntry.responseCache.get.routeKind (C:\Users\me\WebstormProjects\Project-L\node_modules\next\dist\server\base-server.js:1599:28) at async DevServer.renderToResponseWithComponentsImpl (C:\Users\me\WebstormProjects\Project-L\node_modules\next\dist\server\base-server.js:1507:28) at async DevServer.renderPageComponent (C:\Users\me\WebstormProjects\Project-L\node_modules\next\dist\server\base-server.js:1924:24) at async DevServer.renderToResponseImpl (C:\Users\me\WebstormProjects\Project-L\node_modules\next\dist\server\base-server.js:1962:32) at async DevServer.pipeImpl (C:\Users\me\WebstormProjects\Project-L\node_modules\next\dist\server\base-server.js:920:25) at async NextNodeServer.handleCatchallRenderRequest (C:\Users\me\WebstormProjects\Project-L\node_modules\next\dist\server\next-server.js:272:17) at async DevServer.handleRequestImpl (C:\Users\me\WebstormProjects\Project-L\node_modules\next\dist\server\base-server.js:816:17) at async C:\Users\me\WebstormProjects\Project-L\node_modules\next\dist\server\dev\next-dev-server.js:339:20 at async Span.traceAsyncFn (C:\Users\me\WebstormProjects\Project-L\node_modules\next\dist\trace\trace.js:154:20) at async DevServer.handleRequest (C:\Users\me\WebstormProjects\Project-L\node_modules\next\dist\server\dev\next-dev-server.js:336:24) at async requestHandlerImpl (C:\Users\me\WebstormProjects\Project-L\node_modules\next\dist\server\lib\router-server.js:377:13) at async Server.requestListener (C:\Users\me\WebstormProjects\Project-L\node_modules\next\dist\server\lib\start-server.js:141:13) [auth][details]: { "provider": "credentials" }
Below is the code snippet from different files.
"use server"
import * as z from 'zod';
import { AuthError } from "next-auth";
import { signIn } from "@/auth";
import { LoginSchema } from '@/schemas';
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 {
await signIn("credentials", {
email,
password,
redirectTo: DEFAULT_LOGIN_REDIRECT,
})
} catch (error) {
if(error instanceof AuthError){
switch (error.type) {
case "CredentialsSignin":
return {error: "Invalid credentials"}
case "CallbackRouteError":
return {error: "An error occurred with the callback route"}
default:
return {error: "An error occurred"}
}
}
throw error;
}
};
import bcrypt from "bcryptjs";
import type { NextAuthConfig } from "next-auth"
import Credentials from "next-auth/providers/credentials"
import { LoginSchema } from "@/schemas"
import { getUserByEmail } from "@/data/users";
export default {
providers: [
Credentials({
async authorize(credentials: any ) {
const validateFields = LoginSchema.safeParse(credentials)
if(validateFields.success) {
const { email, password } = validateFields.data
const user = await getUserByEmail(email);
if (!user || !user.password) return null;
const passwordsMatch = await bcrypt.compare(
password,
user.password
);
if(passwordsMatch) return user;
}
return null;
}
})
]
} satisfies NextAuthConfig
Even when I attempt to log in correctly, I anticipate receiving {error: "Invalid credentials"} due to incorrect input data, but that's not the error message I receive.
I am using Next.js and auth v5