credential login with NextAuth
guys i have been dealing with some errors while adding credential login to my project. I am adding the screenshot . I would appreciate any help.
56 Replies
I think it should be:
no it didn't work
can you paste the code here?
async authorize(credentials: Partial<Record<"username" | "password", unknown>> | undefined) {
if (!credentials?.username || !credentials?.password) {
throw new Error("Email and password are required");
}
// Find the user by email
const user = await prisma.user.findUnique({
where: {
email: {
equals: credentials.username,
},
},
})
if (!user) {
throw new Error("No user found with the provided email");
}
// Validate the provided password against the stored hashed password
const isPasswordValid = await validatePassword(credentials.password, user.password);
if (!isPasswordValid) {
throw new Error("Invalid password");
}
// Exclude sensitive fields before returning the user object
const { password, ...userWithoutPassword } = user;
return userWithoutPassword;
}
lmk if you need anything else
sorry, was making coffee
I think you can use findFirst instead of findUnique
also, you'll need to add the password column to user
i still get this error
yeah i did it
remove the equals
did you push the changes?
check with prisma studio
oh it works
nice, 1 problem gone
this is the only problem left acually
remove the await
is user.password nullable?
this is the schema
i didnt see anything wrong
check in prisma studio
btw i might add the salting and hashing later i am just training myself rn
yes I figured dw
also, just console.log(user)
sorry i didn’t get it i opened the prisma studio but i dint understand what you need me to show you
the user table, but console.log first
just before the line with the error
i added console.log right before the error line but i cant find where it shows
in the terminal
because it runs on the server
oh sorry, do you have the dev server running?
do you mean localhost:3000
it is not right now
start it and try to sign up/in
it is working normal on homepage btw
are there errors in the terminal?
this
hey i just relized i got this error as well
share the full file
wat
add
this is the error i screen recorded
where should i add it
sorry, change the line to:
in session, just above the error
the error in the code is gone but it still does not open
still getting the same error on terminal
you said you pushed the changes to the db right?
yes
try manually adding a user in prisma studio
i added a user
yep nothing has changed
wait should i add frontend as well
you should see the default nextauth one
just return the user and comment out the lines related to the password
can you share the full file?
maybe even put the project on github
yes yes
i am doing it right now
i did it btw nothing changed
GitHub
GitHub - siarkonyar/loracassi
Contribute to siarkonyar/loracassi development by creating an account on GitHub.
could you open it
yes
tbh I need to sleep, but I'll try to help you before going
ok, I got your error
try adding a custom sign in page
sorry, I have to rest a couple of hours, I'll check later
I'm looking at the code and I noticed that you have two nextauth configs. Also you're using nextauth v5, which has a new syntax to get handlers.
Move authOptions in
server/auth/config.ts
(rename it to authConfig and replace the existing one)
In app/api/auth/[...nextauth]/route.ts
leave only:
sorry mate i had to go outside
i’ll let you know when i do the changes
i really appreciate your help btw you are really nice
and kind
mate you are the best
it is working
thanks a lot
no problem 🙂
hi, sorry to bother you but how can u display the error message inline like that?
i think it was an extension
check eslint it might me it i don’t remember
let me know if you cant find it i can share my extensions
lmk
yeah pls share, tks
these are all of it
wait which extension is it