Skip to content

A secure backend user authentication system using FastAPI, JWT, and MongoDB Atlas. It supports user signup, login, JWT-based session management, and CRUD operations for user profiles. Passwords are hashed for security. MongoDB Cloud ensures scalable data storage with fast and reliable access.

License

Notifications You must be signed in to change notification settings

mohsinraza2999/user-authentication-using-jwt-fastapi-mongodb-cloud

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

h1 style="color:#2c3e50;">🚀 FastAPI Auth App

A lightweight FastAPI project with JWT-based authentication and MongoDB Cloud.

📌 Features

  • JWT login/register
  • Protected user routes
  • MongoDB Cloud integration
  • CRUD operations
  • Password hashing with passlib

🚀 Getting Started

To run the project locally:

pip install -r requirements.txt
uvicorn app.main:app --reload

📁 Project Structure

  • app/main.py – FastAPI app instance and routes
  • app/api/routes_auth.py – user registration and login operations
  • app/db/models.py – Pydantic models
  • app/core/auth.py – JWT utilities and authentication logic
  • app/core/config.py – project name and secret keys
  • app/db/database.py – MongoDB Cloud connection
  • app/api/routes_user.py – token login and CRUD operations on users
  • app/schemas/schemas.py – login token models

🔐 Authentication

Users receive a JWT token upon login. Send it in the Authorization header as a Bearer token for protected routes.

🌐 MongoDB Cloud

Set up a MongoDB Atlas cluster and add your connection string in app/database.py.

✅ Example .env File

MONGO_URL="your_mongodb_connection_string"
JWT_SECRET_KEY="your_secret_key"
ALGORITHM="HS256"
ACCESS_TOKEN_EXPIRE_MINUTES=30

🛠️ Requirements

fastapi
uvicorn
pymongo
python-jose
passlib[bcrypt]
python-dotenv

About

A secure backend user authentication system using FastAPI, JWT, and MongoDB Atlas. It supports user signup, login, JWT-based session management, and CRUD operations for user profiles. Passwords are hashed for security. MongoDB Cloud ensures scalable data storage with fast and reliable access.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages