DEV Community

Cover image for Authentication with credentials using Next-Auth and MongoDB - Part 1

Authentication with credentials using Next-Auth and MongoDB - Part 1

Mainak Das on July 13, 2021

Authentication can be a bit sketchy sometimes as we have to keep so much in mind, like session management, protecting several routes/pages, hashing...
Collapse
 
rohitnishad613 profile image
Rohit Nishad •

Well, i think not working with version 4 of next-auth

Collapse
 
dawnind profile image
Mainak Das •

Thanks for the information, haven't looked into V4 yet. Will do and update :)

Collapse
 
geniushawlah profile image
Olasunkanmi Ajibola •

Do you know how to make it work with version 4?

Thread Thread
 
dawnind profile image
Mainak Das •
Collapse
 
geniushawlah profile image
Olasunkanmi Ajibola •

Do you know how to make it work with version 4?

Collapse
 
tosinkoa profile image
Tosinkoa •

Were you able to solve this?
I need to know how to connect with mongodb using version 4 too

Collapse
 
santosbright profile image
Santos Bright •

Nice one bro, but my concern is that I already worked on a backend api which is on a separate codebase, I don’t want to bring in backend logic to my frontend. This doesn’t feels organised, structured or even secured

Collapse
 
sonamshrish profile image
sonam-shrish •

Hi, how can I encode more information in the cookies while signing in. In the above example you've shown, to encode email only(i.e. return {email: result.email}). How can
I for example save user address in cookies? I've tried (return { email: result.email, address: result.address}, but that didn't work.

Collapse
 
russellharrower profile image
Russell Harrower •

By any chance is this on Github? As I am a little lost as to where the signup form sits.

Collapse
 
dawnind profile image
Mainak Das •
Collapse
 
ivkemilioner profile image
dragos •

SyntaxError: Unexpected token < in JSON at position 0

Collapse
 
richardpickett profile image
Richard Pickett •

npm i next-auth mongodb bycryptjs

should be:

npm i next-auth mongodb bcryptjs

Collapse
 
dawnind profile image
Mainak Das •

thanks man :)

Collapse
 
sinapirani profile image
SinaPirani •

its not a secure way
please check typeof password and email
in youre way, password and email can be object or etc.