Skip to content

Create endpoint for user-registration

What does this MR do?

  1. Installing libraries and setting up the npm environment

Libraries:

  • mongodb
  • express
  • mongoose
  • nodemon
  • bcrypt
  • jsonwebtoken
  • cors
  • multer
  • mongodb-memory-server
  1. Connect with 'mongodb-memory-server' initially (Will change it to MongoDB Atlas later)

  2. Create endpoints for POST requests - /register, /login, /updateUser, /user/:username

  3. Create User.model.js which contains the properties of the schema using mongoose

  4. Create Controllers for /register, /login, /updateUser, /user/:username

  5. Validate authentication

Starting Project

Start server by npm start in the daily-thought-user-service/server directory image

Testing endpoints

a. Register Route [/register]

Valid registration -

image

Username Exists -

Registration_Error_Username_exists

Email Exists -

Registration_Error_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 -

Login_Success

User Not Found (Invalid User) -

Login_User_not_Found

Invalid Credentials (Password Does not Match)

Login_Invalid_Credentials

c. GetUser Route [/user/:username]

You have to register first, and then can use this route. It is a GET request.

Valid User

Get_User_-_Success

Invalid User

Get_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.

Update_User_-_Parameters

Then you click send, and you will get the following response:

Update_User_-_Successful_Response

If you go to the GetUser [/user/:username] route again, you will see the email and profile got updated.

Update_User_-_Showing_Results

Relevant issues

Please ensure the 'Mongoose' is of version "mongoose": "^6.8.0",, as some methods do not work in the newer version.

Merge request reports