Skip to content

user authentication service with actix, jwt, pg, and diesel

Notifications You must be signed in to change notification settings

alexUXUI/actix-user-authentication

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

actix-user-service

🚧 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.


API

/app

/login | POST -> User with JWT

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"] 
}

/logout | POST -> bool

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"] 
}

/users

/all | GET -> All users

Request

curl -X GET \
-H "Authorization: <JWT>" \
http://localhost:3000/users/all 

2XX Response

{
    "users": [
        {
            "id": 2,
            "name": "Alex",
            "email": "[email protected]"
        }
    ],
}

/create | POST -> Creates a new user

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"
}

/{id} | GET -> Gets a user by ID

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]",
    }
}

Tasks:

  1. Tests

  2. Use a third-party authentication strategy

  3. Make routes for:

  • reauth
  • delete
  • update
  • reset pw
  1. Cookies and cookie-based sessions

  2. Better error-handling scheme with better types and middleware

About

user authentication service with actix, jwt, pg, and diesel

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published