Create endpoint for user-registration
What does this MR do?
- Installing libraries and setting up the npm environment
Libraries:
- mongodb
- express
- mongoose
- nodemon
- bcrypt
- jsonwebtoken
- cors
- multer
- mongodb-memory-server
-
Connect with 'mongodb-memory-server' initially (Will change it to MongoDB Atlas later)
-
Create endpoints for POST requests - /register, /login, /updateUser, /user/:username
-
Create User.model.js which contains the properties of the schema using mongoose
-
Create Controllers for /register, /login, /updateUser, /user/:username
-
Validate authentication
Starting Project
Start server by npm start
in the daily-thought-user-service/server directory
Testing endpoints
a. Register Route [/register]
Valid registration -
Username Exists -
Email Exists -
b. Login Route [/login]
You have to register first, and then log in. You can only log in with your username and password.
Valid Login -
User Not Found (Invalid User) -
Invalid Credentials (Password Does not Match)
c. GetUser Route [/user/:username]
You have to register first, and then can use this route. It is a GET request.
Valid User
Invalid User
d. Update User [/updateuser]
This is a PUT Request. After you register and login, you have to get the 'token' from the login route. You have to paste this token in the Auth>Bearer of the /updateuser.
Then you click send, and you will get the following response:
If you go to the GetUser [/user/:username] route again, you will see the email and profile got updated.
Relevant issues
Please ensure the 'Mongoose' is of version "mongoose": "^6.8.0",
, as some methods do not work in the newer version.