fix: wrap /auth/me response in user object to match frontend types
Frontend expects {user: {id, email, name, avatar_url}} but backend
was returning flat object. This caused auth state to fail parsing.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
from secrets import token_urlsafe
|
from secrets import token_urlsafe
|
||||||
from typing import AsyncGenerator, Literal, cast
|
from typing import Any, AsyncGenerator, Literal, cast
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
from fastapi import APIRouter, Cookie, Depends, HTTPException, Response, status
|
from fastapi import APIRouter, Cookie, Depends, HTTPException, Response, status
|
||||||
@@ -150,7 +150,7 @@ async def logout(response: Response) -> dict[str, str]:
|
|||||||
async def me(
|
async def me(
|
||||||
session_cookie: str | None = Cookie(default=None, alias="session"),
|
session_cookie: str | None = Cookie(default=None, alias="session"),
|
||||||
session: AsyncSession = Depends(get_db_session),
|
session: AsyncSession = Depends(get_db_session),
|
||||||
) -> dict[str, str]:
|
) -> dict[str, Any]:
|
||||||
if not session_cookie:
|
if not session_cookie:
|
||||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="missing session")
|
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="missing session")
|
||||||
|
|
||||||
@@ -166,8 +166,10 @@ async def me(
|
|||||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="user not found")
|
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="user not found")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"id": str(user.id),
|
"user": {
|
||||||
"email": user.email,
|
"id": str(user.id),
|
||||||
"name": user.name,
|
"email": user.email,
|
||||||
"avatar_url": user.avatar_url or "",
|
"name": user.name,
|
||||||
|
"avatar_url": user.avatar_url or "",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user