feat(auth): Active Devices — view/revoke mobile sessions
All checks were successful
PR Checks / server-tests (pull_request) Successful in 9m27s
PR Checks / client-build (pull_request) Successful in 10m16s
PR Checks / bot-install (pull_request) Successful in 9m17s

Adds the self-service device-session surface the mobile-SSO spec requires, on
top of the existing mobile_refresh_tokens store.

- Schema: device_name + last_used_at columns on mobile_refresh_tokens (nullable,
  additive via the ALTER section; seeded to now on insert). With single-use
  rotation each login/refresh inserts a fresh row, so the active row's timestamp
  is the session's last activity, and the label is carried forward on refresh.
- Model: listActiveForUser (one row per live device, no token hash) +
  revokeByIdForUser (ownership-scoped, idempotent).
- GET /auth/me/sessions + DELETE /auth/me/sessions/:id (role-agnostic, behind
  requireAuth). Named distinctly from /auth/me/devices (push endpoints).
- device_name is an optional field on /auth/mobile/login and
  /auth/mobile/sso/exchange so the app can label a device.
- Client: an "Active Devices" panel on the player account page (list + sign a
  device out), plus the PlayerLogin change to honor the mobile SSO bridge's
  { redirect } deep link on a 2FA completion.
- Swagger DeviceSession schema + regenerated spec; 3 controller tests. Full
  server suite green (274); client builds.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-07-20 17:01:47 -05:00
parent 61f4591a6b
commit e3dd5358b6
15 changed files with 535 additions and 11 deletions

View File

@@ -1770,6 +1770,118 @@
]
}
},
"/api/v1/auth/me/sessions": {
"get": {
"tags": [
"Auth · Me"
],
"summary": "List active mobile device sessions (self)",
"description": "Active (unrevoked, unexpired) mobile bearer sessions — one per live device — for the Active Devices screen. Never returns tokens.",
"responses": {
"200": {
"description": "Active device sessions",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/DeviceSession"
}
}
}
}
},
"401": {
"description": "Not authenticated",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"403": {
"description": "Forbidden"
},
"500": {
"description": "Internal Server Error"
}
},
"security": [
{
"cookieAuth": []
},
{
"bearerAuth": []
}
]
}
},
"/api/v1/auth/me/sessions/{id}": {
"delete": {
"tags": [
"Auth · Me"
],
"summary": "Revoke one mobile device session (self)",
"description": "Revokes a single device by its session id (ownership-scoped). Revoking stops future token renewals; an already-issued access token remains valid until it expires (see the documented revocation-latency window).",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "integer"
},
"description": "The session row id from GET /auth/me/sessions."
}
],
"responses": {
"200": {
"description": "Revoked (idempotent)",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"revoked": {
"type": "boolean"
}
}
}
}
}
},
"400": {
"description": "Bad Request"
},
"401": {
"description": "Not authenticated",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"403": {
"description": "Forbidden"
},
"500": {
"description": "Internal Server Error"
}
},
"security": [
{
"cookieAuth": []
},
{
"bearerAuth": []
}
]
}
},
"/api/v1/auth/me/devices": {
"post": {
"tags": [
@@ -11113,6 +11225,23 @@
"example": "123456"
}
}
},
"device_name": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "string"
},
"description": {
"type": "string",
"example": "Optional friendly device label for Active Devices."
},
"example": {
"type": "string",
"example": "Pixel 8"
}
}
}
}
}
@@ -11299,6 +11428,119 @@
"example": "The PKCE verifier for the challenge sent to /auth/mobile/sso/start."
}
}
},
"device_name": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "string"
},
"description": {
"type": "string",
"example": "Optional friendly device label for Active Devices."
},
"example": {
"type": "string",
"example": "Pixel 8"
}
}
}
}
}
}
},
"DeviceSession": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "object"
},
"properties": {
"type": "object",
"properties": {
"id": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "integer"
},
"description": {
"type": "string",
"example": "Session row id (pass to DELETE /auth/me/sessions/:id)."
}
}
},
"deviceName": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "string"
},
"nullable": {
"type": "boolean",
"example": true
},
"example": {
"type": "string",
"example": "Pixel 8"
}
}
},
"userAgent": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "string"
},
"nullable": {
"type": "boolean",
"example": true
}
}
},
"createdAt": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "string"
},
"format": {
"type": "string",
"example": "date-time"
}
}
},
"lastUsedAt": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "string"
},
"format": {
"type": "string",
"example": "date-time"
}
}
},
"expiresAt": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "string"
},
"format": {
"type": "string",
"example": "date-time"
}
}
}
}
}

View File

@@ -158,6 +158,7 @@ const doc = {
username: { type: 'string', example: 'admin' },
password: { type: 'string', format: 'password', example: 'super-secret' },
code: { type: 'string', description: 'TOTP code (only when 2FA is enabled).', example: '123456' },
device_name: { type: 'string', description: 'Optional friendly device label for Active Devices.', example: 'Pixel 8' },
},
},
MobileTokenResponse: {
@@ -197,6 +198,18 @@ const doc = {
type: 'string',
description: 'The PKCE verifier for the challenge sent to /auth/mobile/sso/start.',
},
device_name: { type: 'string', description: 'Optional friendly device label for Active Devices.', example: 'Pixel 8' },
},
},
DeviceSession: {
type: 'object',
properties: {
id: { type: 'integer', description: 'Session row id (pass to DELETE /auth/me/sessions/:id).' },
deviceName: { type: 'string', nullable: true, example: 'Pixel 8' },
userAgent: { type: 'string', nullable: true },
createdAt: { type: 'string', format: 'date-time' },
lastUsedAt: { type: 'string', format: 'date-time' },
expiresAt: { type: 'string', format: 'date-time' },
},
},
Message: {