Darrius-W / FastAPI-React-Auth

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

Repository from Github https://github.comDarrius-W/FastAPI-React-AuthRepository from Github https://github.comDarrius-W/FastAPI-React-Auth

πŸ” 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.

License:MIT License


Languages

Language:Python 48.8%Language:JavaScript 42.9%Language:HTML 6.9%Language:CSS 1.5%