bug: `requireClient()` rejects valid localhost bearer tokens with 401
Summary
Tauri generates a fresh UUID4 client_token on each launch and passes it to the server via --token <uuid>. The server's requireClient() function calls tokens.scopeForToken(token) which returns null for any token not in its internal store, causing a 401 rejection. The UI shows "disconnected" or "limited" — even though the connection is from 127.0.0.1 and is inherently trusted.
To Reproduce
- Launch OpenWork
- Server starts with token A (from
--tokenCLI arg) - UI sends requests with token B (fresh UUID from Tauri, or stale localStorage token)
- Server rejects with 401 —
scopeForToken()returnsnull - UI shows "Not connected"
This is especially reproducible when:
- The fallback server restarts with a different token
hostInfohas not yet arrived from Tauri (race condition)
Expected behavior
Since the server only binds to 127.0.0.1, any non-empty bearer token should be accepted. scopeForToken() should fall back to a default scope (e.g., "collaborator") rather than returning null and triggering a 401.
Actual behavior
The server rejects any bearer token not in its internal token store with a 401, even from localhost. The UI intermittently or permanently shows "disconnected".
OW version & Desktop info
- OpenWork: 0.11.194-1 (AUR)
- OS: Arch Linux x86_64
Additional context
Suggested fix in packages/server/src/server.ts:
// Before:
const scope = await tokens.scopeForToken(token);
// After:
const scope = await tokens.scopeForToken(token) ?? "collaborator";
This makes the first requireClient() call fall back to "collaborator" scope for any valid bearer token from localhost.
can you try this in latest versions and report back if it still exists
closed due to age, please reopen and tag me if still valid