fix: change login endpoint from OAuth2PasswordRequestForm to accept JSON body
This commit is contained in:
@@ -56,13 +56,17 @@ async def register(data: RegisterRequest, db: AsyncSession = Depends(get_db)):
|
||||
|
||||
@router.post("/login", response_model=LoginResponse)
|
||||
async def login(
|
||||
form: OAuth2PasswordRequestForm = Depends(),
|
||||
data: dict,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
result = await db.execute(select(User).where(User.phone == form.username))
|
||||
phone = data.get("username") or data.get("phone")
|
||||
password = data.get("password")
|
||||
if not phone or not password:
|
||||
raise HTTPException(status_code=422, detail="phone and password required")
|
||||
result = await db.execute(select(User).where(User.phone == phone))
|
||||
user = result.scalar_one_or_none()
|
||||
|
||||
if not user or not verify_password(form.password, user.password_hash):
|
||||
if not user or not verify_password(password, user.password_hash):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Invalid credentials",
|
||||
|
||||
Reference in New Issue
Block a user