feat(auth): implement authentication endpoints and JWT handling
This commit is contained in:
+12
-3
@@ -1,17 +1,25 @@
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
||||
from api.auth.router import router as auth_router
|
||||
from api.proxy.router import router as proxy_router
|
||||
from db.proxy import ensure_proxy_indexes
|
||||
from core.config import settings
|
||||
from core.mongodb import close_mongodb, init_mongodb
|
||||
from core.redis import close_redis, init_redis
|
||||
from core.security import hash_password
|
||||
from db.auth import ensure_auth_indexes, ensure_single_account
|
||||
from db.proxy import ensure_proxy_indexes
|
||||
from fastapi import FastAPI
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(_: FastAPI):
|
||||
await init_mongodb()
|
||||
await init_redis()
|
||||
await ensure_auth_indexes()
|
||||
await ensure_single_account(
|
||||
username=settings.AUTH_USERNAME,
|
||||
password_hash=hash_password(settings.AUTH_PASSWORD),
|
||||
)
|
||||
await ensure_proxy_indexes()
|
||||
try:
|
||||
yield
|
||||
@@ -24,6 +32,7 @@ app = FastAPI(
|
||||
lifespan=lifespan,
|
||||
)
|
||||
|
||||
app.include_router(auth_router)
|
||||
app.include_router(proxy_router)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user