Authentication

Demo

Build your own backend for authentication the same way that the authentication backend for chatroom works. It must support:

  • POST /api/users to create a new user
    • password field cannot be blank and must be > 5 letters
    • username field cannot be blank, only contains letters and numbers (alphanumeric), is unique
    • email field must contain @ symbol and must be unique
    • Users should be able to pass in any additional key/value data pairs in the body.
  • POST /api/sessions to create a new session (aka login a user)
    • username field can be either username or email.
    • password field must match the password for the user.
  • GET /api/sessions to get the currently logged in user. You must accept a json web token in the header field.

To generate a jwt token, use jsonwebtoken library.

  • jwt.sign( {userId: 1234 }, 'secret password' )
    • will return a secure jwt token.
  • jwt.decode( token )
    • will return the data in the token, which would be {userId: 1234, iat: ...} if encoded like the example above. iat field gives you the time (in seconds) when the token has been signed.

Make sure you properly secure user passwords with bcrypt