Skip to content

Secure full-stack JWT auth with FastAPI backend and React frontend using HTTP-only cookies, user registration, login, and protected routes.

License

Notifications You must be signed in to change notification settings

Darrius-W/FastAPI-React-Auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔐 FastAPI-React-Auth – Token-Based Authentication with FastAPI & React

Python FastAPI React License Tests

A full-stack web authentication system built using FastAPI and React, implementing secure JWT-based authentication with HTTP-only cookies, user registration, login, protected routes, and logout functionality.


🚀 Features

  • 🔐 Secure login and registration using JWT tokens (stored in HTTP-only cookies)
  • 🔒 Password hashing with bcrypt
  • ✅ Protected API routes using FastAPI dependencies
  • 🧪 Integration tests with Pytest
  • 🎯 Token expiration, logout, and cookie invalidation
  • 🌐 CORS configuration for frontend/backend communication

🛠️ Tech Stack

Frontend

  • React (Hooks, Axios, React Router)
  • JavaScript (ES6+)
  • HTML5, CSS3

Backend

  • FastAPI
  • Python
  • Pydantic
  • bcrypt, JWT

Testing

  • Pytest (Unit & Integration Tests)

🔧 Installation & Setup

1. Clone the repo

git clone https://github.com/Darrius-W/Auth-Python.git cd FastAPI-React-Auth

2. Setup the backend

cd server
python -m venv venv
venv\Scripts\activate
pip install -r requirements.txt
uvicorn main:app --reload

3. Setup the frontend

cd client
npm install
npm start

4. Run Tests

cd server
pytest


🔒 Authentication Flow

  1. Signup or Login from React frontend
  2. Backend returns JWT token in an HTTP-only cookie
  3. Protected routes are accessed only if token is valid
  4. /logout deletes cookie and ends session

✅ Example Usage

  • Visit /profile to see a protected page after logging in
  • Manually clear cookies or logout to simulate session expiration

🧪 Testing Highlights

  • ✅ Tested signup, login, protected route access, and logout with Pytest
  • ✅ Simulated cookie handling in test client
  • ✅ Covers valid and invalid authentication paths

About

Secure full-stack JWT auth with FastAPI backend and React frontend using HTTP-only cookies, user registration, login, and protected routes.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published