feat: revoke other login sessions
ci / gitleaks (push) Successful in 7s
ci / docker (push) Successful in 3m24s

This commit is contained in:
2026-09-11 15:38:41 +08:00
parent cf6cdcf949
commit 5f2f38da3e
5 changed files with 51 additions and 2 deletions
+12
View File
@@ -272,6 +272,18 @@ async def list_sessions(
return [{"id": row.id, "current": row.token_hash == current_hash, "created_at": row.created_at, "last_seen_at": row.last_seen_at, "expires_at": row.expires_at, "ip_address": row.ip_address, "user_agent": row.user_agent} for row in rows]
@app.delete("/api/v1/sessions/others", status_code=204)
async def revoke_other_sessions(
token: str = Depends(session_token),
user: User = Depends(current_user),
db: AsyncSession = Depends(get_db),
):
current_hash = hash_token(token)
await db.execute(delete(Session).where(Session.user_id == user.id, Session.token_hash != current_hash))
await db.commit()
return Response(status_code=204)
@app.delete("/api/v1/sessions/{session_id}", status_code=204)
async def revoke_session(
session_id: UUID,