https://github.com/justinianus2001/fastapi-auth
https://github.com/justinianus2001/fastapi-auth
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/justinianus2001/fastapi-auth
- Owner: Justinianus2001
- Created: 2025-04-16T07:12:11.000Z (about 2 months ago)
- Default Branch: master
- Last Pushed: 2025-04-16T07:14:10.000Z (about 2 months ago)
- Last Synced: 2025-04-16T09:29:00.115Z (about 2 months ago)
- Language: Python
- Size: 11.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# FastAPI Authentication and CRUD Application
A simple web application built with FastAPI that demonstrates user authentication using JWT tokens and basic CRUD operations with PostgreSQL database.
## Features
- User registration and authentication
- JWT token-based authentication
- PostgreSQL database integration
- CRUD operations for items
- Clean and responsive UI
- Secure password hashing## Prerequisites
- Python 3.8+
- PostgreSQL
- pip (Python package manager)## Setup
1. Clone the repository:
```bash
git clone
cd fastapi-auth-middleware
```2. Create a virtual environment and activate it:
```bash
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
```3. Install dependencies:
```bash
pip install -r requirements.txt
```4. Create a PostgreSQL database named `fastapi_auth_db`
5. Update the `.env` file with your database credentials and secret key:
```
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/fastapi_auth_db
SECRET_KEY=your-secret-key-here
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
```## Running the Application
1. Start the FastAPI server:
```bash
uvicorn app.main:app --reload
```2. Open your browser and navigate to:
```
http://localhost:8000
```## API Documentation
Once the application is running, you can access the API documentation at:
```
http://localhost:8000/docs
```## Project Structure
```
fastapi-auth-middleware/
├── app/
│ ├── __init__.py
│ ├── main.py
│ ├── auth.py
│ ├── models.py
│ └── database.py
├── static/
│ ├── styles.css
│ └── script.js
├── templates/
│ ├── login.html
│ └── items.html
├── requirements.txt
├── .env
└── README.md
```## Security Notes
- The secret key in the `.env` file should be kept secure and never committed to version control
- Passwords are hashed using bcrypt before storing in the database
- JWT tokens are used for authentication
- Database credentials should be properly secured