Skip to content

Latest commit

 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RustyEnd 🚀

A production-ready authentication backend built with Rust, Axum, PostgreSQL, and JWT Authentication.

Features

  • 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

Tech Stack

Backend

  • Rust
  • Axum
  • Tokio
  • SQLx
  • PostgreSQL
  • JWT (jsonwebtoken)
  • Argon2
  • Serde
  • Validator

Email Service

  • Lettre (SMTP)

Project Structure

src/
├── config/
├── db/
├── dtos/
├── error/
├── handler/
│   ├── auth/
│   └── users/
├── mail/
├── middleware/
├── models/
├── routes/
├── utils/
└── main.rs

Environment Variables

Create 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_password

Database Setup

Install PostgreSQL

brew install postgresql@17
brew services start postgresql@17

Create Database

createdb mydb

Run Migrations

sqlx migrate run

Run the Application

Install Dependencies

cargo build

Start Server

cargo run

Server will start on:

http://localhost:8000

Authentication Flow

Register

POST /api/auth/register

Request Body:

{
  "name": "Subhro",
  "email": "subhro@gmail.com",
  "password": "123456",
  "passwordConfirm": "123456"
}

Login

POST /api/auth/login

Request Body:

{
  "email": "subhro@gmail.com",
  "password": "123456"
}

Response:

{
  "status": "success",
  "token": "jwt_token"
}

Verify Email

GET /api/auth/verify?token=<verification_token>

Forgot Password

POST /api/auth/forgot-password

Reset Password

POST /api/auth/reset-password

Protected Routes

Protected routes require a JWT token.

Authorization: Bearer <token>

Example:

GET /api/users/me

Security Features

  • Argon2 Password Hashing
  • JWT Authentication
  • Email Verification
  • Password Reset Tokens
  • Input Validation
  • Role-Based Authorization
  • SQL Injection Protection through SQLx

Future Improvements

  • Refresh Tokens
  • OAuth (Google/GitHub Login)
  • Redis Session Storage
  • Docker Support
  • CI/CD Pipeline
  • Rate Limiting
  • Account Lockout Protection

Author

Subhro Kolay

Computer Science Undergraduate | Rust Backend Developer | Full Stack Developer

GitHub: https://github.com/your-username


Built with ❤️ using Rust and Axum.

About

A production-ready authentication backend built with Rust, Axum, PostgreSQL, and JWT Authentication.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages