Next.js Authentication - Mongoose/MongoDB integration with NextAuth | Production Grade

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
our today's topics is how to use mongos with nexs 13 for mongod DB so I have created a plan to share first of all we will create mongodb database in mongodb atlast create two model one for user and another is account create mongod DV connection and finally create mongod adapter for next O So before wasting more time let's move into mongodb Atlas and create a [Music] database so I'm going to use the free version I'm not going to pay today for this tutorial but yes I recommend if you want to more faster Services then you can use premium on no problem but for this tutorial let's use the free version so you can select AWS Google Cloud so I prefer AWS from mind and the reason you can choose whenever you want but since I'm from India so I'm selecting Mumbai and keep it as it is cluster or I can provide a name so the name should be your name or my name or anything else okay name is nothing and create that's going to be fun I'm sure traffic light lot of traffic light [Music] boom so they ask me to create a password okay so since I'm going to use authentication um not going to use the any certificate or AWS so I will use the username and password so okay keep it is keep it is as it is and just I'm going to store it somewhere to user use it future okay so usern name and password and my local environment good fine IP address add my IP address for now okay great local environment okay fine everything is perfect perfect so connect m be from all IP addresses with your credential okay so I'm going to put the IP address like this and this should be for public and entry create user perfect so then finish and close go to congratulation let's move ahead [Music] no okay I don't anything deploy F perfect so let's go to the connect so to connect between mongodb and the next day project since we are using NJ so we will select NJ and we will copy this line up single Center uh string to future use okay I will St it there for future use okay fine let's go to database it will take some time you know oh boom it's ready now go to browse collections to create new database that's really awesome guys uh load local sample no I don't need the sample dat database or data sheet I will use add my own data and the name should be from my end but you can write any of your name since this is a next to project so I will use this name and the collection name I'm sure there should be a user colle user model so I will use the users collection name that should be po plural right so create so before that just keep the name as it is copy it and use there on this line okay already I have the name there so I will replace this with the password genine password fine and this is our mongod DV connection string so same time I will create a EnV file inside our parent folder which isnv you can see from there new file and this should be EnV and in this EnV file what we'll do we'll do many for this project also the mongodb URI so in this line of mongodb URI we will use this line to connect from nextjs to mongod DV and the note environment should be development because we are now on the development mode but whenever we we have uploaded into the server like ver and AWS we will change replace with the production fine our next steps was create model user and account so to create models I will create a folder inside the SRC folder this is models and as I told you earlier we will create two model one is user and another is account so already I have created two models on my another project so I will use those models same time yeah so let me explain the user model here you can see in this user model this is a production gr up model you know I have many many field there like name email password uid ID roles e admin uh who is we will use in the next videos for example let me explain on just simple one thing like roles this roles for multiple type of user like if you want to um set type of user like author like admin like client okay so if you want to provide divided different type of role for different type of user and different different type of access so for this I used the role and active sub keep it as it is we will use this in future and for the forget password we'll use this the forget password token the foret password token expir verify token and verify token expiry this is the most important thing but if you want you can remove the occupation you can remove the bio the city state country if it's totally up to you but from from my end I keep as it is because you know among is a document based database so there is no restriction or limit to make a data sheet long and the accounts here is the accounts model so this is should this is these things are most most needed so that's okay fine so model creation is completed let's create a mongodb connection so to create a mongod DV connection let's create a folder there inser the SRC which is called the DB connect or yeah this should be DB connect and inside the folder create a file db. DS okay this should be our mongod DV connection we will so I will use three steps to mongod DV connect connect between mongod DV and the our project first of all I have imported the mongus from mongos and I have apply validation if myv file does not have the mongodb URI then it will provide me a error and second time I'll provide the type definition like this and also I will create a mongus caching connection this is important why I'll let you I'll let you explain everything step by step let me and regarding the connection notas connection which is this okay what I have done on there so guys you can ask me why I have used the connection with the cash connection so here is explanation when your app for example this is app and this is the database so when our app call to database to face a data instantly our data reply with the database to the our app so there is a connection create when you when you try to connect to onod there is there is a connection already created and same time if my app try to create try to call database for another pH so so for this piece I don't want to reconnect reuse the connect method to connect to mongod DV I want to use the connect method from cach so that's why I have used this cash feature cash feature by this way you can reduce the database connection call and and make our site more faster and by this way API should load more more faster and more organized way so that that's why I have created a cash connection if the connection is exist then the connect will be apply from the cash if not then this should be a fresh connection okay so our Mongo's DB's connection is completed let's create a [Music] adapter so to connect from uh to use mongod adapter we'll need a extension I copied it and I'm installing this adapter in the me of time I'll copy this enter code okay and create a folder there outside of the F folder but inside the SRC there should be library but you can create any type of folder no problem inside the Library I will create a file which is mongod DB adapter. DS and the the number of code I will copy this from there this from there and paste it there okay so this is final our mongod DB setup is completed so our next uh Target was creating uh a MP forms for our registration page for login page and the password receipt page
Info
Channel: Sandipan Das
Views: 340
Rating: undefined out of 5
Keywords:
Id: wVr6HDQaHvM
Channel Id: undefined
Length: 13min 22sec (802 seconds)
Published: Sat Nov 18 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.