M-a document based open source database
E- a web application framework for Node.js
R- A js front-end library for building user interfaces
N-js runtime environment that executed JS outside of a a-browser
Mongoose-Simple,schema based solution to model application
- require express and set const app to express to use express libraries on app.
- app.get res for ->index, about, signup,login
- add middleware in about req,res,next()
- In DB folder create conn(connection) file.
- require mongoose
- mongoose.connect(DB,) DB="string from cluster connect of Atlas"
- use promises, then and catch err
- Auntenticity- dotenv
- create config.env
- define the port and DB(to secure the passwords of DB)
- dotenv.config in App (once)
- userSchema
- require mongoose
- new mongoose.Schema//create a new instance
- create Schema using objects define type:,
- create a model of the user Schema mongoose.model('USER', userSchema)->(name, schemaname)
- Router in Backend
- Express Router Middleware Setup and Getting Data Back From POSTMAN to Our MERN Application
- Save data in Atlas
- All fields are required, Check if email matches, if not create new user.
- SignIn page
- enter email password, check if matches with DB, if null then user does not exist
- Secure password
- npm i bcryptjs
- before save data, call the bcryptsjs in userSchema.pre and hash the password.
- to check email and password : for email: .finOne, for password: bcrypt.compare
- Cookies and Tokens
- The user submits login credentials to the backend server. Upon the request, the server verifies the credentials before generating an encrypted JWT with a secret key and sends it back to the client. On the client-side, the browser stores the token locally using the local storage, session storage, or cookie storage
- npm i jsonwebtoken User Authentication Using JWT & Stored Token In MongoDB Atlas
- Generate JWT Token and stored it in DB.
- How to store the token in Cookies
- get the token from cookie and verify the User