How do I setup credentials based auth with the app I created with T3 CLI?

I used the approach I saw on mosh hammedanis course, and it looks something like this, but trying to adapt this code into the t3 project I recieved from the CLI gave me several errors
No description
5 Replies
Connor B
Connor B8mo ago
Bro my eyes are hurting trying to look at the ss. post code
Teodorant Master Of Nonsense
import CredentialsProvider from "next-auth/providers/credentials"; import bcrypt from "bcrypt"; import prisma from "@/prisma/client"; export const authOptions = { providers: [ CredentialsProvider({ name: "Credentials", credentials: { email: { label: "email:", type: "text", placeholder: "your-email", }, password: { label: "password:", type: "password", placeholder: "your-password", }, }, async authorize(credentials) { try { const foundUser = await prisma.user.findUnique({ where: { email: credentials!.email }, }); if (foundUser) { console.log("User Exists"); console.log(foundUser); const match = await bcrypt.compare( credentials!.password, foundUser.password ); if (match) { console.log("Good Pass"); foundUser.password = " "; // foundUser["role"] = "Unverified Email"; return foundUser; } } } catch (error) { console.log(error); } return null; }, }), ], callbacks: { async jwt({ token, user }: any) { // console.log("jwt callback", { token, user, session }); if (user) { token.role = user.role; token.isClient = user.isClient; token.isAdmin = user.isAdmin; token.isRepairman = user.isRepairman; token.sub = user.id; } return token; }, async session({ session, token }: any) { // console.log("sesh callback", { token, user, session }); if (session?.user) { session.user.role = token.role; session.user.isClient = token.isClient; session.user.isAdmin = token.isAdmin; session.user.isRepairman = token.isRepairman; session.user.sub = token.sub; } return session; }, }, };
Connor B
Connor B7mo ago
try adding a syntax tag in the future:
import CredentialsProvider from "next-auth/providers/credentials";
import bcrypt from "bcrypt";
import prisma from "@/prisma/client";

export const authOptions = {
providers: [
CredentialsProvider({
name: "Credentials",
credentials: {
email: {
label: "email:",
type: "text",
placeholder: "your-email",
},
password: {
label: "password:",
type: "password",
placeholder: "your-password",
},
},
async authorize(credentials) {
try {
const foundUser = await prisma.user.findUnique({
where: { email: credentials!.email },
});

if (foundUser) {
console.log("User Exists");
console.log(foundUser);
const match = await bcrypt.compare(
credentials!.password,
foundUser.password
);

if (match) {
console.log("Good Pass");
foundUser.password = " ";

// foundUser["role"] = "Unverified Email";
return foundUser;
}
}
} catch (error) {
console.log(error);
}
return null;
},
}),
],
import CredentialsProvider from "next-auth/providers/credentials";
import bcrypt from "bcrypt";
import prisma from "@/prisma/client";

export const authOptions = {
providers: [
CredentialsProvider({
name: "Credentials",
credentials: {
email: {
label: "email:",
type: "text",
placeholder: "your-email",
},
password: {
label: "password:",
type: "password",
placeholder: "your-password",
},
},
async authorize(credentials) {
try {
const foundUser = await prisma.user.findUnique({
where: { email: credentials!.email },
});

if (foundUser) {
console.log("User Exists");
console.log(foundUser);
const match = await bcrypt.compare(
credentials!.password,
foundUser.password
);

if (match) {
console.log("Good Pass");
foundUser.password = " ";

// foundUser["role"] = "Unverified Email";
return foundUser;
}
}
} catch (error) {
console.log(error);
}
return null;
},
}),
],
makes life a lot easier what are your errors?
Teodorant Master Of Nonsense
I am using this code on a default t3 project, and when I enter in my credentials, it logs out good pass
Teodorant Master Of Nonsense
but it doesn't change the sign in button to sign out and I can' display the id on the screen
Want results from more Discord servers?
Add your server