first commit

This commit is contained in:
Anurag Jangid 2026-10-08 02:41:41 +05:30
commit d416fe4cce
69 changed files with 8269 additions and 0 deletions

43
backend/app/api/auth.py Normal file
View file

@ -0,0 +1,43 @@
from fastapi import APIRouter, Depends
from motor.motor_asyncio import AsyncIOMotorDatabase
from app.core.security import create_access_token
from app.db.mongo import get_database
from app.schemas.auth import (
AuthBootstrapResponse,
AuthLoginBootstrapRequest,
AuthLoginRequest,
AuthSignupRequest,
AuthTokenResponse,
)
from app.services.auth import create_account, get_account_by_identifier, verify_account_login
router = APIRouter(prefix="/auth", tags=["auth"])
@router.post("/signup", response_model=AuthTokenResponse)
async def signup(payload: AuthSignupRequest, database: AsyncIOMotorDatabase = Depends(get_database)) -> AuthTokenResponse:
owner_id = await create_account(database, payload)
access_token = create_access_token(owner_id)
return AuthTokenResponse(accessToken=access_token, ownerId=owner_id)
@router.post("/bootstrap", response_model=AuthBootstrapResponse)
async def bootstrap(
payload: AuthLoginBootstrapRequest,
database: AsyncIOMotorDatabase = Depends(get_database),
) -> AuthBootstrapResponse:
account = await get_account_by_identifier(database, payload.identifierType.value, payload.identifier)
return AuthBootstrapResponse(
identifierType=payload.identifierType,
identifier=account["identifier"],
saltAuth=account["saltAuth"],
saltEnc=account["saltEnc"],
)
@router.post("/login", response_model=AuthTokenResponse)
async def login(payload: AuthLoginRequest, database: AsyncIOMotorDatabase = Depends(get_database)) -> AuthTokenResponse:
owner_id = await verify_account_login(database, payload)
access_token = create_access_token(owner_id)
return AuthTokenResponse(accessToken=access_token, ownerId=owner_id)