diff --git a/backend/app/api/users.py b/backend/app/api/users.py index 64055c8..1fbb367 100644 --- a/backend/app/api/users.py +++ b/backend/app/api/users.py @@ -13,6 +13,12 @@ class UserName(BaseModel): username: str +@router.get("/me", response_model=UserName) +def me(user: ApiUser) -> UserName: + """Who a token belongs to (e.g. so the agent only takes over its owner's clips).""" + return UserName(id=user.id, username=user.username) + + @router.get("", response_model=list[UserName]) def list_user_names(user: ApiUser, db: DbSession) -> list[UserName]: """Names of the other active users, for sharing projects; nothing else is revealed.""" diff --git a/backend/tests/test_tokens.py b/backend/tests/test_tokens.py index 66abbd5..036d3ea 100644 --- a/backend/tests/test_tokens.py +++ b/backend/tests/test_tokens.py @@ -239,3 +239,8 @@ def test_latest_clip_ignores_pinning_and_files(agent): agent.post("/api/files", params={"name": "newer.txt"}, content=b"file") assert agent.get("/api/clips/latest").json()["content"] == "newest text" + + +def test_token_knows_its_user(agent, db): + anna = db.query(User).filter_by(username="anna").one() + assert agent.get("/api/users/me").json() == {"id": anna.id, "username": "anna"}