- First install all the packages, set up MongoDB and the environment.
- Configure scripts to run server using nodemon
- Create routes using express-router
- Folder 'routes' has all routes
- Create 'User' model using mongoose and mongoDB Schema
- Use the User model in user route and register new User
- For registerising User we have to check if user already exists
- if new user we will encrypt password using bcrypt and then save it to mongoDB
- Then provide a token to the user(It can be a new user or existing user)
a. We will then use user-id to provide token
b. To create a token which can be then send to a authorized route, we have to create it usinqjwt.sign()
we will senduser.id
as payload
c. Then we use that token for our middleware(in middleware we are just decrypting the token and assigningreq.user
to
the user in database) which will provide access to authorized routes - After using that token for our middleware we can use the middleware as a 2nd Parameter to our auth-route,
which will make the auth route a procted/authorized route. - Then that route can display all user data.
Login/Register Summary
-> if its a new user, first it is saved to database and
then it is given a token which is then decoded ny middleware and
then authorized by auth route for access its details.
-> if its an existing user, it's credential are validated and
then a token is provided to him/her and then decoded then
authorized by auth route to access its details
- Create 'Profile' model using mongoose and mongoDB schema
a. Then createprofile.js
. It will have multiple routes.
b. Route for creating a profile.
c. Route for getting all profiles.
d. Rote for getting current user profile.
e. Route for getting profile by user id. \