Typescript Error in Authorize function of CredentialsProvider
authorize typescript error
Type '(credentials: Record<"email" | "password", string> | undefined) => Promise<User>' is not assignable to type '(credentials: Record<"email" | "password", string> | undefined, req: Pick<RequestInternal, "body" | "query" | "headers" | "method">) => Awaitable<...>'.
project/js/next/dropship/node_modules/.prisma/client/index").User' is not assignable to type
Type '(credentials: Record<"email" | "password", string> | undefined) => Promise<User>' is not assignable to type '(credentials: Record<"email" | "password", string> | undefined, req: Pick<RequestInternal, "body" | "query" | "headers" | "method">) => Awaitable<...>'.
project/js/next/dropship/node_modules/.prisma/client/index").User' is not assignable to type
import prisma from "@/lib/prisma";
import bcrypt from "bcryptjs";
import NextAuth from "next-auth/next";
import CredentialsProvider from "next-auth/providers/credentials";
const handler = NextAuth({
providers: [
CredentialsProvider({
name: "Credentials",
credentials: {
email: { label: "Email", type: "email", placeholder: "jsmith" },
password: { label: "Password", type: "password" },
},
async authorize(credentials) {
if (!credentials?.email || !credentials?.password) {
throw new Error("Invalid credentials");
}
const user = await prisma.user.findUnique({
where: {
email: credentials.email,
},
});
if (!user || !user?.password) {
throw new Error("Invalid credentials");
}
const isCorrectPassword = await bcrypt.compare(
credentials.password,
user.password
);
if (!isCorrectPassword) {
throw new Error("Invalid credentials");
}
return user;
},
}),
],
callbacks: {
async jwt({ token, user, trigger, session }) {
if (trigger === "update") {
return { ...token, ...session.user };
}
return { ...token, ...user };
},
async session({ session, token }) {
session.user = token as any;
return session;
},
},
});
export { handler as GET, handler as POST };
import prisma from "@/lib/prisma";
import bcrypt from "bcryptjs";
import NextAuth from "next-auth/next";
import CredentialsProvider from "next-auth/providers/credentials";
const handler = NextAuth({
providers: [
CredentialsProvider({
name: "Credentials",
credentials: {
email: { label: "Email", type: "email", placeholder: "jsmith" },
password: { label: "Password", type: "password" },
},
async authorize(credentials) {
if (!credentials?.email || !credentials?.password) {
throw new Error("Invalid credentials");
}
const user = await prisma.user.findUnique({
where: {
email: credentials.email,
},
});
if (!user || !user?.password) {
throw new Error("Invalid credentials");
}
const isCorrectPassword = await bcrypt.compare(
credentials.password,
user.password
);
if (!isCorrectPassword) {
throw new Error("Invalid credentials");
}
return user;
},
}),
],
callbacks: {
async jwt({ token, user, trigger, session }) {
if (trigger === "update") {
return { ...token, ...session.user };
}
return { ...token, ...user };
},
async session({ session, token }) {
session.user = token as any;
return session;
},
},
});
export { handler as GET, handler as POST };
0 Replies