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.
- 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
Follow these steps to get the project up and running on your local machine.
- Python 3.6+
- Live Server Extension in VSCode
-
Clone the Repository
git clone https://github.com/LunlunChin/FastAPI-Auth
-
Navigate to the Directory
cd FastAPI-Auth
-
** Set up and activatevirtual env**
python3 -m venv venv
.\venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Run the Server
Launch the FastAPI server using Uvicorn:
uvicorn main:app --reload
-
Set Up the Frontend
Open the
index.html
file using the Live Server extension in Visual Studio Code. Guide to setting up Live Server. -
Access the Application
Visit the URL provided by Live Server, typically
http://127.0.0.1:5500/index.html
.
-
Open the web application in your browser.
-
Enter the following credentials:
- Username: admin
- Password: admin
-
Click the Login button.
-
Upon successful login, the JWT token will be logged in the browser's console.
-
To view the stored JWT token, press
F12
to open the Developer Tools, go to theApplication
tab, and look underSession Storage
.
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/