Using credentials provider

Hey guys! I was looking for some kind of info on how I can use credentials provider with NextAuth while using ct3a. I know its insecure and isnt recommended for use and all that but I have a client who wants it. Can anyone help out or point me towards an implementation that works? For context I am using the latest version of ct3a, Prisma, NextAuth, trpc and app router I have added the credentials provider as follows:
providers: [
CredentialsProvider({
name: "Credentials",
credentials: {
email: { label: "Email", type: "email" },
password: { label: "Password", type: "password" },
},
async authorize(credentials) {
const account = await db.account.findFirst({
where: {
email: credentials.email as string,
},
include: {
user: true,
},
});

if (account?.passwordHash) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
const isValid = await bcrypt.compare(
credentials.password as string,
account.passwordHash,
);
console.log("isValid", isValid);
if (isValid) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return account.user;
} else {
return null;
}
} else {
return null;
}
},
}),
],
providers: [
CredentialsProvider({
name: "Credentials",
credentials: {
email: { label: "Email", type: "email" },
password: { label: "Password", type: "password" },
},
async authorize(credentials) {
const account = await db.account.findFirst({
where: {
email: credentials.email as string,
},
include: {
user: true,
},
});

if (account?.passwordHash) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
const isValid = await bcrypt.compare(
credentials.password as string,
account.passwordHash,
);
console.log("isValid", isValid);
if (isValid) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return account.user;
} else {
return null;
}
} else {
return null;
}
},
}),
],
1 Reply

Did you find this page helpful?