Skip to content

Commit d8a2c80

Browse files
committed
fix(gateway): prefer explicit token over stored auth
1 parent c06a962 commit d8a2c80

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

src/gateway/client.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,9 @@ export class GatewayClient {
190190
const storedToken = this.opts.deviceIdentity
191191
? loadDeviceAuthToken({ deviceId: this.opts.deviceIdentity.deviceId, role })?.token
192192
: null;
193-
const authToken = storedToken ?? this.opts.token ?? undefined;
194-
const canFallbackToShared = Boolean(storedToken && this.opts.token);
193+
// Prefer explicitly provided credentials (e.g. CLI `--token`) over any persisted
194+
// device-auth tokens. Persisted tokens are only used when no token is provided.
195+
const authToken = this.opts.token ?? storedToken ?? undefined;
195196
const auth =
196197
authToken || this.opts.password
197198
? {
@@ -270,12 +271,6 @@ export class GatewayClient {
270271
this.opts.onHelloOk?.(helloOk);
271272
})
272273
.catch((err) => {
273-
if (canFallbackToShared && this.opts.deviceIdentity) {
274-
clearDeviceAuthToken({
275-
deviceId: this.opts.deviceIdentity.deviceId,
276-
role,
277-
});
278-
}
279274
this.opts.onConnectError?.(err instanceof Error ? err : new Error(String(err)));
280275
const msg = `gateway connect failed: ${String(err)}`;
281276
if (this.opts.mode === GATEWAY_CLIENT_MODES.PROBE) {

0 commit comments

Comments
 (0)