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!)
✅ 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
fastapi-login-jwt/
│
├── main.py
├── auth.py
├── models.py
├── schemas.py
├── utils.py
├── database.py
└── requirements.txt
git clone https://github.com/your-username/fastapi-login-jwt.git
cd fastapi-login-jwtpip install -r requirements.txtOr install manually:
pip install fastapi uvicorn sqlalchemy pymysql python-jose[cryptography] passlib[bcrypt] python-multipart "pydantic[email]"uvicorn main:app --reloadOpen your browser or Postman:
👉 http://127.0.0.1:8000/docs
POST /auth/register
{
"email": "[email protected]",
"password": "password123"
}POST /auth/login
{
"email": "[email protected]",
"password": "password123"
}Response:
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6...",
"token_type": "bearer"
}GET /auth/me
Header → Authorization: Bearer <your_token>
- FastAPI — Web framework
- SQLAlchemy — ORM for DB
- Passlib — Password hashing
- python-jose — JWT token handling
- Uvicorn — ASGI server
🎥 Watch the full Shorts video here:
👉 Build Login + Token Auth with FastAPI
Programmer Chandra
🔗 YouTube Channel
⭐ If you find this helpful, star the repo and share it with your dev friends!