Automated Action 50b3fc513b Implement FastAPI user authentication service with MongoDB
- Set up FastAPI application with MongoDB Motor driver
- Implemented user registration, login, and logout with HTTP-only cookies
- Added JWT token authentication and password hashing
- Created user management endpoints for username updates and password changes
- Structured application with proper separation of concerns (models, schemas, services, routes)
- Added CORS configuration and health endpoints
- Documented API endpoints and environment variables in README
2025-06-20 14:19:13 +00:00

19 lines
467 B
Python

import os
from motor.motor_asyncio import AsyncIOMotorClient
from typing import Optional
class Database:
client: Optional[AsyncIOMotorClient] = None
db = Database()
async def get_database():
return db.client.user_auth_db
async def connect_to_mongo():
mongodb_url = os.getenv("MONGODB_URL", "mongodb://localhost:27017")
db.client = AsyncIOMotorClient(mongodb_url)
async def close_mongo_connection():
if db.client:
db.client.close()