Welcome to the JWT-Based Authentication System built with Actix Web in Rust! This project leverages the security, scalability and speed of Actix Web to provide a robust and secure authentication system.
- Role-Based Authentication: Secure access with role-based permissions.
- Argon2 Password Hashing: Enhanced security with Argon2 hashing.
- User Registration: Easy user sign-up process.
- Login with Token Generation: Secure login with JWT token generation.
- Token Removal with Logout API: Seamless logout functionality.
- Admin Role: Admins can view the list of users.
- User Details: Logged-in users can view their own details.
- Swagger UI: Integrated Swagger UI for easy API documentation.
- Production-Level Structure: Organized and maintainable project structure.
- PostgreSQL Connectivity: Reliable database connectivity with PostgreSQL.
- Middleware for Route Guarding: Secure routes with custom middleware.
Explore the API documentation with Swagger UI:
-
Clone the repository:
https://github.com/alexsayantan/actix-auth.git cd jwt-auth-actix-web -
Set up PostgreSQL:
- Ensure you have PostgreSQL installed and running.
- Create a database and update the connection string in the
.envfile.
-
Run the application:
cargo run
-
Register a new user:
POST /api/auth/register
-
Login and get a token:
POST /api/auth/login
-
Logout and remove the token:
POST /api/auth/logout
-
View user list (Admin only):
GET /api/users
-
View logged-in user details:
GET /api/users/me
src/
βββ handlers/
β βββ auth.rs
β βββ mod.rs
β βββ users.rs
βββ routes/
β βββ auth.rs
β βββ heath.rs
β βββ mod.rs
β βββ users.rs
βββ utils/
β βββ mod.rs
β βββ password.rs
β βββ token.rs
βββ auth.rs
βββ config.rs
βββ db.rs
βββ dtos.rs
βββ error.rs
βββ main.rs
βββ models.rs
Contributions are welcome! Please fork this repository and submit a pull request.