Skip to content

fachririyanto/fastapi-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 

Repository files navigation

FastAPI Auth

Role-based authentication using FastAPI (Python). Designed for an internal application where user registration is not allowed; users can join only by invitation from superadmin or admin roles.

Tech Stack

  • Database: PostgreSQL
  • Backend: FastAPI (Python)
  • Frontend: Vite, ReactJS, TypeScript, Tailwind (Shadcn)

Modules

  • Authentication
    • Login
    • Forgot Password
    • Reset Password
    • Confirm Account
    • Logout
  • Module Account
    • Update Profile
    • Change Password
    • Revoke Other Sessions
  • Module User
    • List Users
    • Create User
    • Change User Role
    • Change User Active Status
    • Delete User
  • Module Role
    • List Roles
    • Create Role
    • Update Role
    • Delete Role
  • Module Sandbox (Custom CRUD)
    • List Sandbox
    • Create Sandbox
    • Update Sandbox
    • Delete Sandbox

How to run project

First, make sure you have PostgreSQL installed in your local computer or you can use Docker to run the database, for example db-in-docker.

Backend installation

Go to /api directory in your terminal, then type command below to create a python virtual environment:

python -m venv .venv

# or with uv

uv venv

The run command below to install the package:

pip install -r requirements.txt

# or with uv

uv pip install -r requirements.txt

Next create a .env file, you can copy the value from .env.example file to get started, then fill with the correct credentials. After that you must run the migration to install the neccessary tables. You can run the command below to create the tables.

# install tables
python cli_install.py
python cli_install --module sandbox # to install the specific module

# reinstall tables
python cli_reinstall.py
python cli_reinstall.py --module sandbox # to re-install the specific module

# uninstall tables
python cli_uninstall.py
python cli_uninstall.py --module sandbox # to un-install the specific module

After finish run the migration, now you can run the API by running the command below:

fastapi dev main.py

You can access the API at (http://127.0.0.1:8000) or the swagger at (http://127.0.0.1:8000/docs).

Frontend installation

Go to /webapp directory in your terminal, then type the command below to install the package.

npm install

# or with bun

bun install

Create a .env file, you can copy the value from .env.example file to get started, then fill with the correct value.

Then run the frontend by running the command below:

npm run dev

# or with bun

bun run dev

You can access the frontend at (http://localhost:5173).

Login credentials

You can test the login API with this login credentials:

  1. Super Admin (Role: Super Admin)

  2. Admin (Role: Admin)

  3. Fachri (Role: User)

About

Authentication using FastAPI (Python).

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors