#2530: fix(gateway): improve auth error for native apps
gateway
Cluster:
Gateway and macOS Improvements
## Summary
Fixes #2268
Improves authentication error messages for macOS/iOS/Android apps to clearly indicate where to set `gateway.remote.token`.
## Problem
When native apps (macOS/iOS/Android) fail to connect due to missing auth credentials, they received a generic error message:
```
unauthorized: gateway token missing (provide gateway auth token)
```
This was confusing because it didn't specify:
- Where to set the token (`~/.clawdbot/clawdbot.json`)
- What config key to use (`gateway.remote.token`)
- That it must match the server's `gateway.auth.token`
## Solution
Enhanced `formatGatewayAuthFailureMessage` in [message-handler.ts:76-96](https://github.com/clawdbot/clawdbot/blob/main/src/gateway/server/ws-connection/message-handler.ts#L76-L96) to detect native apps and provide specific guidance:
**Before:**
```
unauthorized: gateway token missing (provide gateway auth token)
```
**After:**
```
unauthorized: gateway token missing (set gateway.remote.token in ~/.clawdbot/clawdbot.json to match gateway.auth.token on the server)
```
## Changes
- Added detection for `MACOS_APP`, `IOS_APP`, and `ANDROID_APP` client IDs
- Provided platform-specific error hints that include:
- Config file path
- Exact config key name
- Requirement to match server config
- Applies to both token and password auth modes
## Testing
- Code review: logic correctly identifies native app client IDs
- Error message format matches existing CLI/Control UI patterns
- Backward compatible: other clients continue to receive appropriate hints
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR improves gateway authentication error messages for native app clients by detecting macOS/iOS/Android client IDs and returning more actionable hints (config file path and exact config keys to set). It also includes several gateway WS connection hardening tweaks (host parsing/local-client detection, additional Tailscale auth failure reasons, and Control UI device-auth bypass wiring), which aligns the WS handler with the newer `isLocalDirectRequest` logic in `src/gateway/auth.ts` and improves diagnostics and safety around proxied/loopback connections.
<h3>Confidence Score: 4/5</h3>
- This PR is likely safe to merge, with one logging/telemetry correctness concern to address.
- Changes are mostly user-facing messaging and refactors toward existing auth helpers, but the new `authMethod` fallback can mislabel the attempted authentication path (notably when Tailscale is attempted first), which could confuse operators when debugging auth failures.
- src/gateway/server/ws-connection/message-handler.ts
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#8260: fix(macOS): gateway readiness detection + reversible Configure later
by xksteven · 2026-02-03
81.5%
#15722: fix: prefer explicit token over stored device token for remote gate...
by 0xPotatoofdoom · 2026-02-13
78.2%
#11205: Android: fix gateway connection and canvas URL for Tailscale serve
by emonty · 2026-02-07
78.0%
#19937: fix(gateway): validate token/password auth modes and isolate gatewa...
by NewdlDewdl · 2026-02-18
77.8%
#6352: fix(ux): update gateway token error message UI location
by Glucksberg · 2026-02-01
76.6%
#19885: test(gateway,browser): isolate tests from ambient OPENCLAW_GATEWAY_...
by NewdlDewdl · 2026-02-18
76.3%
#21651: fix(gateway): token fallback + operator.admin scope superset in pai...
by lan17 · 2026-02-20
76.2%
#6770: fix(gateway): protect host-local transport fields from config.patch
by ryx2 · 2026-02-02
76.2%
#11455: fix(gateway): default gateway.mode to local when unset
by AnonO6 · 2026-02-07
76.1%
#13321: android/gateway: harden manual connect identity and A2UI UX
by m888m · 2026-02-10
76.0%