Automated Action 4e361e2d61 Add user authentication and user-specific invoice management
- Create User model and database schema
- Add JWT authentication with secure password hashing
- Create authentication endpoints for registration and login
- Update invoice routes to require authentication
- Ensure users can only access their own invoices
- Update documentation in README.md
2025-05-30 09:00:26 +00:00

40 lines
1.1 KiB
Python

from typing import List, Union
import secrets
from pydantic import AnyHttpUrl, validator
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
# API config
API_V1_STR: str = "/api/v1"
PROJECT_NAME: str = "Invoice Generation Service"
# CORS settings
BACKEND_CORS_ORIGINS: List[Union[str, AnyHttpUrl]] = []
# Security settings
SECRET_KEY: str = secrets.token_urlsafe(32)
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 8 # 8 days
# Set this to a real key in production environment
def __init__(self, **data):
super().__init__(**data)
if self.SECRET_KEY == "":
self.SECRET_KEY = secrets.token_urlsafe(32)
@validator("BACKEND_CORS_ORIGINS", pre=True)
def assemble_cors_origins(cls, v: Union[str, List[str]]) -> Union[List[str], str]:
if isinstance(v, str) and not v.startswith("["):
return [i.strip() for i in v.split(",")]
elif isinstance(v, (list, str)):
return v
raise ValueError(v)
class Config:
case_sensitive = True
env_file = ".env"
# Create settings instance
settings = Settings()