Skip to content

Oclemy/FastAPI-Auth-and-User-Management

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” FastAPI Auth & User Management

One-file FastAPI authentication system with JWT tokens, user management, admin panel, and built-in frontend.

One Click Deploy

Deploy on Railway

Quick Start (Local)

pip install -r requirements.txt
python main.py
# Open http://localhost:8080
Variable Default Description
SECRET_KEY auto-generated JWT signing key (set for persistence across redeploys)
ACCESS_TOKEN_EXPIRE_MINUTES 30 Access token lifetime
REFRESH_TOKEN_EXPIRE_DAYS 7 Refresh token lifetime
APP_NAME FastAPI Auth Shown in UI
  1. To create the one-click deploy template: Railway Dashboard β†’ Project β†’ Settings β†’ Generate Template

Features

  • Register / Login (email or username) / Logout
  • JWT access + refresh tokens with rotation
  • Token revocation (logout invalidates tokens)
  • Profile view & edit, password change, account deletion
  • Admin panel: list users, toggle active/admin status
  • Auto-creates tables on startup
  • SQLite locally, PostgreSQL on Railway
  • Built-in frontend + Swagger UI at /docs

API Endpoints

POST   /api/auth/register          β†’ Create account, get tokens
POST   /api/auth/login             β†’ Login, get tokens
POST   /api/auth/refresh           β†’ Rotate refresh token
POST   /api/auth/logout            β†’ Revoke token
GET    /api/users/me               β†’ Get profile
PATCH  /api/users/me               β†’ Update profile
POST   /api/users/me/change-password
DELETE /api/users/me               β†’ Delete account
GET    /api/admin/users            β†’ List all users (admin)
PATCH  /api/admin/users/{id}/toggle-active
PATCH  /api/admin/users/{id}/toggle-admin
GET    /api/health

Making First Admin

Register your first user via the UI, then connect to the Railway PostgreSQL and run:

UPDATE users SET is_admin = true WHERE id = 1;

About

FastAPI authentication system with JWT tokens, user management, admin panel, and built-in frontend.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages