mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 15:01:23 +00:00
fix(gateway): prefer explicit token over stored auth
This commit is contained in:
@@ -190,8 +190,9 @@ export class GatewayClient {
|
|||||||
const storedToken = this.opts.deviceIdentity
|
const storedToken = this.opts.deviceIdentity
|
||||||
? loadDeviceAuthToken({ deviceId: this.opts.deviceIdentity.deviceId, role })?.token
|
? loadDeviceAuthToken({ deviceId: this.opts.deviceIdentity.deviceId, role })?.token
|
||||||
: null;
|
: null;
|
||||||
const authToken = storedToken ?? this.opts.token ?? undefined;
|
// Prefer explicitly provided credentials (e.g. CLI `--token`) over any persisted
|
||||||
const canFallbackToShared = Boolean(storedToken && this.opts.token);
|
// device-auth tokens. Persisted tokens are only used when no token is provided.
|
||||||
|
const authToken = this.opts.token ?? storedToken ?? undefined;
|
||||||
const auth =
|
const auth =
|
||||||
authToken || this.opts.password
|
authToken || this.opts.password
|
||||||
? {
|
? {
|
||||||
@@ -270,12 +271,6 @@ export class GatewayClient {
|
|||||||
this.opts.onHelloOk?.(helloOk);
|
this.opts.onHelloOk?.(helloOk);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
if (canFallbackToShared && this.opts.deviceIdentity) {
|
|
||||||
clearDeviceAuthToken({
|
|
||||||
deviceId: this.opts.deviceIdentity.deviceId,
|
|
||||||
role,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
this.opts.onConnectError?.(err instanceof Error ? err : new Error(String(err)));
|
this.opts.onConnectError?.(err instanceof Error ? err : new Error(String(err)));
|
||||||
const msg = `gateway connect failed: ${String(err)}`;
|
const msg = `gateway connect failed: ${String(err)}`;
|
||||||
if (this.opts.mode === GATEWAY_CLIENT_MODES.PROBE) {
|
if (this.opts.mode === GATEWAY_CLIENT_MODES.PROBE) {
|
||||||
|
|||||||
Reference in New Issue
Block a user