POST /usersshould acceptpasswordfield and before save replace it with hash (use bcrypt package).- Add a
POST /loginmethod which accepts JSON withloginandpasswordand should return JWT token in response body:{ token: <jwt_token> }(use jsonwebtoken package). - JWT token should contain
userIdandloginin a payload. - Secret that used for signing the token should be stored in
.envfile. - For all client requests the JWT token should be added in HTTP
Authorizationheader to all requests that requires authentication. HTTP authentication must followBearerscheme, e.g.:
Authorization: Bearer <jwt_token>
- Add a
middlewarewhich will proxy all the requests (except/login) and check that HTTPAuthorizationheader has the correct value of JWT token. - In case of the HTTP
Authorizationheader in the request is absent or invalid or doesn’t followBearerscheme, themiddlewareshould stop further router method execution and return HTTP 401 code (Unauthorized error) and the corresponding error message. - Add admin user to DB on service start with
login = adminandpassword = admin.
gyp ERR! stack Error: "pre" versions of node cannot be installed, use the --nodedir flag insteadPlease check compatibility between Node.JS and Bcrypt versions.
node-pre-gyp ERR! Tried to download(404): https://github.com/kelektiv/node.bcrypt.js/releases/download/v1.0.2/bcrypt_lib-v1.0.2-node-v48-linux-x64.tar.gzMake sure you have the appropriate dependencies installed and configured for your platform. You can find installation instructions for the dependencies for some common platforms in this page.