Login API

Photo by Ed Hardie on Unsplash

Login API

Creating a login API.

Now, I am going to create a login API that helps users log in. The process of creating it is really simple which goes as follows:

  • The route is "/login/ " and its method is post.
  • Create a table in the database as users
  • Take the username and password from the user.
  • Check if the user is logged in or not.
  • If the user is logged in then don't create his account and return "You are already logged in"
  • Check if the username is present or not.
  • If the username is not present then you can return anything you want.
  • If the username is present further verify the password with a hashed password.
  • And if it returns true then logged the user in by using session if not throw the error that username and password are invalid