POST /users
should acceptpassword
field and before save replace it with hash (use bcrypt package or its equivalent likebcryptjs
).- Implement
POST /login
method which accepts JSON withlogin
andpassword
and returns JWT token in response body:{ token: <jwt_token> }
(use jsonwebtoken package). - JWT token should contain
userId
andlogin
in a payload. - Secret that used for signing the token should be stored in
.env
file. - For all client requests the JWT token should be added in HTTP
Authorization
header to all requests that requires authentication. HTTP authentication must followBearer
scheme, e.g.:
Authorization: Bearer <jwt_token>
- Proxy all the requests (except
/login
) and check that HTTPAuthorization
header has the correct value of JWT token. - In case of the HTTP
Authorization
header in the request is absent or invalid or doesn’t followBearer
scheme, further router method execution should be stopped and lead to response with HTTP 401 code (Unauthorized error) and the corresponding error message. - Add admin user to DB on service start with
login = admin
andpassword = admin
.
gyp ERR! stack Error: "pre" versions of node cannot be installed, use the --nodedir flag instead
Please 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.gz
Make 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.