Skip to content

Latest commit

 

History

History
118 lines (91 loc) · 2.42 KB

File metadata and controls

118 lines (91 loc) · 2.42 KB

🔐 FastAPI Login + Token Authentication

This project demonstrates how to build a secure login system in FastAPI using JWT (JSON Web Tokens) for authentication.

It’s the same project shown in my YouTube Short — Build Login + Token Auth with FastAPI 🚀 (Watch the full demo there!)


⚡ Features

✅ Register a new user (/auth/register)
✅ Login and get an access token (/auth/login)
✅ Verify the current user (/auth/me)
✅ Password hashing using Passlib
✅ JWT token creation & verification with python-jose
✅ Clean project structure with routers, schemas, and models


🗂️ Project Structure

fastapi-login-jwt/
│
├── main.py
├── auth.py
├── models.py
├── schemas.py
├── utils.py
├── database.py
└── requirements.txt

🚀 Quick Start

1️⃣ Clone the Repository

git clone https://github.com/your-username/fastapi-login-jwt.git
cd fastapi-login-jwt

2️⃣ Install Dependencies

pip install -r requirements.txt

Or install manually:

pip install fastapi uvicorn sqlalchemy pymysql python-jose[cryptography] passlib[bcrypt] python-multipart "pydantic[email]"

3️⃣ Run the App

uvicorn main:app --reload

Open your browser or Postman:
👉 http://127.0.0.1:8000/docs


🔑 API Endpoints

1. Register User

POST /auth/register

{
  "email": "user@example.com",
  "password": "password123"
}

2. Login User

POST /auth/login

{
  "email": "user@example.com",
  "password": "password123"
}

Response:

{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6...",
  "token_type": "bearer"
}

3. Get Current User

GET /auth/me
Header → Authorization: Bearer <your_token>


🧰 Tech Stack

  • FastAPI — Web framework
  • SQLAlchemy — ORM for DB
  • Passlib — Password hashing
  • python-jose — JWT token handling
  • Uvicorn — ASGI server

📹 YouTube Tutorial

🎥 Watch the full Shorts video here:
👉 Build Login + Token Auth with FastAPI


👨‍💻 Author

Programmer Chandra
🔗 YouTube Channel


⭐ If you find this helpful, star the repo and share it with your dev friends!