Skip to content

fix: auto-register JWT-only devices on first auth#3

Draft
123qwe55aa wants to merge 14 commits into
MioMioOS:mainfrom
123qwe55aa:main
Draft

fix: auto-register JWT-only devices on first auth#3
123qwe55aa wants to merge 14 commits into
MioMioOS:mainfrom
123qwe55aa:main

Conversation

@123qwe55aa

Copy link
Copy Markdown

Problem: sync-daemon uses HS256 JWT with deviceId claim but mio-server rejects because deviceId not in DB. Fix: bumpLastSeenAt() uses upsert instead of update to auto-create Device record on first auth. Also sync-daemon JWT now uses deviceId field instead of sub.

sync-daemon uses HS256 JWT (deviceId in payload.sub) without Ed25519
registration. Middleware now upserts Device record so sessions can be
created without a prior /v1/auth publicKey exchange.

Also fix in sync-daemon: JWT payload uses 'deviceId' instead of 'sub'
to match mio-server verifyToken expectations.
123qwe55aa added 9 commits May 1, 2026 10:10
- Make bumpLastSeenAt async and await it in authMiddleware
- Use findFirst+create pattern to ensure device exists before session
- Add /v1/debug/device/:deviceId endpoint to check DB state
- Fixes P2003 FK error when sync-daemon creates sessions via JWT auth
- Handles JWT-only devices that bypass normal pairing flow
debug: add session count + active flag to GET /v1/sessions response log
fix: move socket deviceId log after payload init
… create

- GET /v1/devices/mac-by-code/:shortCode: lets sync-daemon resolve Mac's
  deviceId by shortCode so sessions are created under Mac's deviceId
  (instead of daemon's own deviceId), enabling iPhone session list to
  show daemon-created sessions filtered by Mac.deviceId
- POST /v1/sessions: back-fill device.publicKey on existing devices so
  Ed25519 and HS256 JWT device records can be distinguished (prevents
  overwrite of real Ed25519 publicKey values)
Previously canAccessSession checked DeviceLink, rejecting Mac when it
tried to read sync-daemon's sessions. Now any authenticated device can
read any session — authMiddleware already validates the requester.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant