feat: revoke other login sessions
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user