Skip to content

Sample of JWT with Refresh Token using Actix-web + Sqlx + Apalis 🦀💻

License

Notifications You must be signed in to change notification settings

guibeira/actix-jwt-with-refresh-token-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

actix-user-template

Sample of login using Actix-web + Sqlx + Apalis

Installation

Before you can run the application and use these authentication routes, you need to set up the project environment and dependencies.

To install the required dependencies, follow these steps:

Make sure you have Rust and Docker Compose installed on your system.

Navigate to the project directory.

cd actix-jwt-with-refresh-token-template

Create the .env file.

cp .local.env .env

Start Postgres and Redis.

docker compose up -d

Install Rust dependencies using Cargo:

cargo build

Run the project.

cargo run

Routes

Register User

  • Route: /auth/register
  • Method: POST
  • Description: Allows users to create a new account by providing their registration information, including name, email, and password.
curl --location 'http://localhost:8000/api/v1/auth/register' \
--header 'Content-Type: application/json' \
--data-raw '{
    "email": "[email protected]",
    "name": "Admin",
    "password": "password123",
    "passwordConfirm": "password123",
    "photo": "default.png"
}'

Login User

  • Route: /auth/login
  • Method: POST
  • Description: Allows users to log in by providing their email and password. Upon successful login, the user receives an access token.
curl --location 'http://localhost:8000/api/v1/auth/login' \
--header 'Content-Type: application/json' \
--data-raw '{
    "email": "[email protected]",
    "password": "batatinha"
}'

Get User Profile

  • Route: /auth/me
  • Method: GET
  • Description: Retrieves the user's profile information. Requires authentication, and the user must be logged in.
curl --location 'http://localhost:8000/api/v1/auth/me' \
--header 'Cookie: access_token=<ACCESS_TOKEN>'

Logout User

  • Route: /auth/logout
  • Method: GET
  • Description: Logs the user out of the application. Invalidates the current access token, preventing further access to protected resources.
curl --location 'http://localhost:8000/api/v1/auth/logout'
--header 'Cookie: access_token=<ACCESS_TOKEN>'

Refresh Access Token

  • Route: /auth/refresh
  • Method: GET
  • Description: Refreshes the user's access token, allowing them to maintain their session without re-login.
curl --location 'http://localhost:8000/api/v1/auth/refresh' \
--header 'Cookie: access_token=<ACCESS_TOKEN>'

Reset Password

  • Route: /auth/reset-password/
  • Method: POST
  • Description: Allows users to reset their password by providing a new password and a password reset token sent via email.
curl --location 'http://localhost:8000/api/v1/auth/reset-password/' \
--header 'Content-Type: application/json' \
--data '{
    "token": "<RESET_TOKEN>",
    "new_password": "newpass"
}'

Forgot Password

  • Route: /auth/forgot-password
  • Method: POST
  • Description: It initiates the process of resetting a forgotten password by sending a password reset email to the user's registered email address.
curl --location 'http://localhost:8000/api/v1/auth/forgot-password' \
--header 'Content-Type: application/json' \
--data-raw '{"email": "[email protected]"}'

About

Sample of JWT with Refresh Token using Actix-web + Sqlx + Apalis 🦀💻

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published