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.
No description
58 Replies
Daddo
Daddo3mo ago
I think it should be:
const users = await prisma.user.findUnique({
where: {
email: {
equals: credentials.username,
},
},
})
const users = await prisma.user.findUnique({
where: {
email: {
equals: credentials.username,
},
},
})
şiar_619
şiar_619OP3mo ago
no it didn't work
Daddo
Daddo3mo ago
can you paste the code here?
şiar_619
şiar_619OP3mo ago
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
Daddo
Daddo3mo ago
sorry, was making coffee I think you can use findFirst instead of findUnique also, you'll need to add the password column to user
şiar_619
şiar_619OP3mo ago
i still get this error
No description
şiar_619
şiar_619OP3mo ago
yeah i did it
Daddo
Daddo3mo ago
remove the equals did you push the changes? check with prisma studio
şiar_619
şiar_619OP3mo ago
oh it works
Daddo
Daddo3mo ago
nice, 1 problem gone
şiar_619
şiar_619OP3mo ago
this is the only problem left acually
No description
Daddo
Daddo3mo ago
remove the await
şiar_619
şiar_619OP3mo ago
No description
Daddo
Daddo3mo ago
is user.password nullable?
şiar_619
şiar_619OP3mo ago
this is the schema
No description
şiar_619
şiar_619OP3mo ago
i didnt see anything wrong
Daddo
Daddo3mo ago
check in prisma studio
şiar_619
şiar_619OP3mo ago
btw i might add the salting and hashing later i am just training myself rn
Daddo
Daddo3mo ago
yes I figured dw also, just console.log(user)
şiar_619
şiar_619OP3mo ago
sorry i didn’t get it i opened the prisma studio but i dint understand what you need me to show you
Daddo
Daddo3mo ago
the user table, but console.log first just before the line with the error
şiar_619
şiar_619OP3mo ago
i added console.log right before the error line but i cant find where it shows
No description
Daddo
Daddo3mo ago
in the terminal because it runs on the server oh sorry, do you have the dev server running?
şiar_619
şiar_619OP3mo ago
do you mean localhost:3000 it is not right now
Daddo
Daddo3mo ago
start it and try to sign up/in
şiar_619
şiar_619OP3mo ago
No description
şiar_619
şiar_619OP3mo ago
it is working normal on homepage btw
Daddo
Daddo3mo ago
are there errors in the terminal?
şiar_619
şiar_619OP3mo ago
No description
şiar_619
şiar_619OP3mo ago
this
şiar_619
şiar_619OP3mo ago
hey i just relized i got this error as well
No description
Daddo
Daddo3mo ago
share the full file wat add
"jwt" as const
"jwt" as const
şiar_619
şiar_619OP3mo ago
şiar_619
şiar_619OP3mo ago
this is the error i screen recorded where should i add it
Daddo
Daddo3mo ago
sorry, change the line to:
strategy: "jwt" as const,
strategy: "jwt" as const,
in session, just above the error
şiar_619
şiar_619OP3mo ago
the error in the code is gone but it still does not open
No description
şiar_619
şiar_619OP3mo ago
still getting the same error on terminal
Daddo
Daddo3mo ago
you said you pushed the changes to the db right?
şiar_619
şiar_619OP3mo ago
yes
Daddo
Daddo3mo ago
try manually adding a user in prisma studio
şiar_619
şiar_619OP3mo ago
i added a user yep nothing has changed wait should i add frontend as well
Daddo
Daddo3mo ago
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
şiar_619
şiar_619OP3mo ago
yes yes i am doing it right now
şiar_619
şiar_619OP3mo ago
No description
şiar_619
şiar_619OP3mo ago
i did it btw nothing changed
şiar_619
şiar_619OP3mo ago
GitHub
GitHub - siarkonyar/loracassi
Contribute to siarkonyar/loracassi development by creating an account on GitHub.
şiar_619
şiar_619OP3mo ago
could you open it
Daddo
Daddo3mo ago
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:
import { handlers } from "~/server/auth";

export const { GET, POST } = handlers
import { handlers } from "~/server/auth";

export const { GET, POST } = handlers
şiar_619
şiar_619OP3mo ago
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
Daddo
Daddo3mo ago
no problem 🙂
LeThanh James
LeThanh James2mo ago
hi, sorry to bother you but how can u display the error message inline like that?
şiar_619
şiar_619OP2mo ago
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
LeThanh James
LeThanh James2mo ago
yeah pls share, tks
şiar_619
şiar_619OP2mo ago
these are all of it
şiar_619
şiar_619OP2mo ago
LeThanh James
LeThanh James2mo ago
wait which extension is it
şiar_619
şiar_619OP2mo ago
i don't remember which extension specifically
OreQr
OreQr2mo ago
Error Lens - Visual Studio Marketplace
Extension for Visual Studio Code - Improve highlighting of errors, warnings and other language diagnostics.

Did you find this page helpful?