Skip to content

Basic Auth System Built using FastAPI and vanilla JS

Notifications You must be signed in to change notification settings

LunlunChin/FastAPI-Auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI Auth System

This project demonstrates a simple authentication system using FastAPI for the backend and a basic HTML/JavaScript frontend. It uses JWT (JSON Web Tokens) for handling secure authentication.

Features

  • Backend API built with FastAPI.
  • JWT Authentication with a 30-minute expiration.
  • Mock database with a single user for demonstration.
  • Frontend form handling and token storage.
  • SQLite to track user login

Getting Started

Follow these steps to get the project up and running on your local machine.

Prerequisites

  • Python 3.6+
  • Live Server Extension in VSCode

Installation

  1. Clone the Repository

    git clone https://github.com/LunlunChin/FastAPI-Auth
  2. Navigate to the Directory

    cd FastAPI-Auth
  3. ** Set up and activatevirtual env**

    python3 -m venv venv
    .\venv\Scripts\activate
  4. Install dependencies

    pip install -r requirements.txt
  5. Run the Server

    Launch the FastAPI server using Uvicorn:

    uvicorn main:app --reload
  6. Set Up the Frontend

    Open the index.html file using the Live Server extension in Visual Studio Code. Guide to setting up Live Server.

  7. Access the Application

    Visit the URL provided by Live Server, typically http://127.0.0.1:5500/index.html.

Usage

  1. Open the web application in your browser.

  2. Enter the following credentials:

    • Username: admin
    • Password: admin
  3. Click the Login button.

  4. Upon successful login, the JWT token will be logged in the browser's console.

  5. To view the stored JWT token, press F12 to open the Developer Tools, go to the Application tab, and look under Session Storage.

image

6.go to the /logins endpoint to get the SQLite Db data that contains the list of username and login_time http://127.0.0.1:8000/logins/

image

About

Basic Auth System Built using FastAPI and vanilla JS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published