A production-ready authentication backend built with Rust, Axum, PostgreSQL, and JWT Authentication.
- User Registration
- User Login
- JWT Authentication
- Role-Based Access Control (Admin/User)
- Email Verification
- Forgot Password & Reset Password
- Password Hashing using Argon2
- PostgreSQL Database Integration
- SQLx ORM
- Request Validation
- CORS Support
- Modular Architecture
- Environment Variable Configuration
- Rust
- Axum
- Tokio
- SQLx
- PostgreSQL
- JWT (jsonwebtoken)
- Argon2
- Serde
- Validator
- Lettre (SMTP)
src/
├── config/
├── db/
├── dtos/
├── error/
├── handler/
│ ├── auth/
│ └── users/
├── mail/
├── middleware/
├── models/
├── routes/
├── utils/
└── main.rsCreate a .env file in the root directory.
PORT=8000
DATABASE_URL=postgres://username:password@localhost:5432/mydb
JWT_SECRET=your_secret_key
SMTP_SERVER=smtp.gmail.com
SMTP_PORT=587
SMTP_USERNAME=your_email@gmail.com
SMTP_PASSWORD=your_app_passwordbrew install postgresql@17
brew services start postgresql@17createdb mydbsqlx migrate runcargo buildcargo runServer will start on:
http://localhost:8000POST /api/auth/registerRequest Body:
{
"name": "Subhro",
"email": "subhro@gmail.com",
"password": "123456",
"passwordConfirm": "123456"
}POST /api/auth/loginRequest Body:
{
"email": "subhro@gmail.com",
"password": "123456"
}Response:
{
"status": "success",
"token": "jwt_token"
}GET /api/auth/verify?token=<verification_token>POST /api/auth/forgot-passwordPOST /api/auth/reset-passwordProtected routes require a JWT token.
Authorization: Bearer <token>Example:
GET /api/users/me- Argon2 Password Hashing
- JWT Authentication
- Email Verification
- Password Reset Tokens
- Input Validation
- Role-Based Authorization
- SQL Injection Protection through SQLx
- Refresh Tokens
- OAuth (Google/GitHub Login)
- Redis Session Storage
- Docker Support
- CI/CD Pipeline
- Rate Limiting
- Account Lockout Protection
Subhro Kolay
Computer Science Undergraduate | Rust Backend Developer | Full Stack Developer
GitHub: https://github.com/your-username
Built with ❤️ using Rust and Axum.