🚧 work in progress
Minimal user management service with functionality to create a user, log a user in, fetch all users, or fetch a user by id.
Request
curl -X POST \
-H "Content-type: application/json" \
-d '{"name": "paulo", "password": "123" }' \
http://localhost:3000/users/login
2XX Response
{
"user_logged_in": {
"name":"paulo",
"email":"[email protected]",
"jwt":"<JWT>"
}
}
4XX Response
{
"message": "Could not log user in",
// one of the following as a string:
"error": ["Could not log user out"]
}
Request
curl -X POST \
-H "Content-type: application/json" \
-d '{"id": "2" }' \
http://localhost:3000/users/logout
2XX Response
{
"user_logged_out": true
}
4XX Response
{
"user_logged_out": false,
"message": "Could not log user in",
// one of the following as a string:
"error": ["User does not exist", "Incorrect password", "Could not verify password"]
}
Request
curl -X GET \
-H "Authorization: <JWT>" \
http://localhost:3000/users/all
2XX Response
{
"users": [
{
"id": 2,
"name": "Alex",
"email": "[email protected]"
}
],
}
Request
curl -X POST \
-H "Content-type: application/json" \
-H "Authorization: <JWT>" \
-d '{"name": "clara", "password": "123", "email": "[email protected]" }' \
http://localhost:3000/users/create
2XX Response
{
"new_user": {
"name": "clara",
"email": "[email protected]"
}
}
4XX Response
{
"message": "Failed to create user",
"error": "Email already in use"
}
Request
curl -X GET \
-H "Content-type: application/json" \
-H "Authorization: <JWT>" \
http://localhost:3000/users/2
Response
{
"user": {
"id": 2,
"name":"Alex",
"email":"[email protected]",
}
}
-
Tests
-
Use a third-party authentication strategy
-
Make routes for:
- reauth
- delete
- update
- reset pw
-
Cookies and cookie-based sessions
-
Better error-handling scheme with better types and middleware