Skip to content

ommahmood/fastapi-auth

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI Full-Stack Auth Demo

This repo is a full-stack app using the FastAPI web framework, MySQL for a database, and REST to interact with a simple users table. You may install MySQL natively or use the included Docker file to create a database in a containter. The init-db.sql defines a simple schema for use with the example.

Screenshot

Prerequesites

You just need to have UV installed: How to install UV

TODO

  1. Switch to sending username/password in header! (https://fastapi.tiangolo.com/advanced/security/http-basic-auth/)
  2. Switch to making the authenticate function a dependency: (https://fastapi.tiangolo.com/az/tutorial/security/simple-oauth2)

Usage

  1. Create database credentials (specify your own USERNAME, PASSWORD, and ROOT_PASSWORD!)

    echo "MYSQL_HOST=localhost" > credentials.env
    echo "MYSQL_DATABASE=ece140" >> credentials.env
    echo "MYSQL_USER=USERNAME" >> credentials.env
    echo "MYSQL_PASSWORD=PASSWORD" >> credentials.env
    echo "MYSQL_ROOT_PASSWORD=ROOT_PASSWORD" >> credentials.env
  2. If you have Docker installed, run the following command to start up a MySQL server (ignore this step if you already have MySQL installed and modify the credentials.env file to match your database credentials!). Run the command in a separate terminal window as it will lock up the window for logging.

    docker compose up --build -d

    Note: Just closing the terminal will not stop the database server. In order to stop it, you must issue the command docker-compose down when you are finished.

  3. Seed the database

    cd server
    uv run seed-users.py
  4. Run the server

    uv run main.py

    or

    uv run uvicorn main:app --reload
  5. Visit the docs page to access the login/logout POST routes

    http://127.0.0.1:8000/docs
  6. Once logged in, you can visit the protected route to see if you're logged in

    http://127.0.0.1:8000/protected

About

An example full-stack application that demonstrates session management with authentication

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 57.2%
  • JavaScript 22.3%
  • HTML 14.9%
  • CSS 5.6%