Skip to content

Commit 7212e3a

Browse files
authored
refactor: rename GatewayConfig.password to credential (#18)
The field may hold a token or password depending on gateway auth mode. Rename to 'credential' for clarity. Wire protocol auth.password field is unchanged (that's the actual protocol key name).
1 parent f58bec2 commit 7212e3a

2 files changed

Lines changed: 22 additions & 22 deletions

File tree

context/gateway-context.tsx

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ interface GatewayContextValue {
5252
status: ConnectionStatus
5353
snapshot: GatewaySnapshot | null
5454
error: string | null
55-
connect: (url: string, password: string) => void
55+
connect: (url: string, credential: string) => void
5656
disconnect: () => void
5757
reconnect: () => void
5858
sendRequest: (method: string, params?: Record<string, unknown>) => Promise<unknown>
@@ -81,7 +81,7 @@ export function GatewayProvider({ children }: { children: React.ReactNode }) {
8181
const listenersRef = useRef<Map<string, Set<EventCallback>>>(new Map())
8282
const reconnectTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
8383
const reconnectAttemptRef = useRef(0)
84-
const credentialsRef = useRef<{ url: string; password: string } | null>(null)
84+
const credentialsRef = useRef<{ url: string; credential: string } | null>(null)
8585
const intentionalDisconnectRef = useRef(false)
8686
const deviceIdentityRef = useRef<DeviceIdentity | null>(null)
8787
const connectedRef = useRef(false)
@@ -114,7 +114,7 @@ export function GatewayProvider({ children }: { children: React.ReactNode }) {
114114

115115
// Core connect logic
116116
const doConnect = useCallback(
117-
(url: string, password: string) => {
117+
(url: string, credential: string) => {
118118
cleanup()
119119
intentionalDisconnectRef.current = false
120120
setError(null)
@@ -185,7 +185,7 @@ export function GatewayProvider({ children }: { children: React.ReactNode }) {
185185
const signature = await signPayload(identity.privateKey, authPayload)
186186

187187
connectReq = makeConnectRequest(
188-
password,
188+
credential,
189189
{
190190
id: identity.deviceId,
191191
publicKey: identity.publicKeyBase64Url,
@@ -197,7 +197,7 @@ export function GatewayProvider({ children }: { children: React.ReactNode }) {
197197
)
198198
} else {
199199
// First connection: token-only, no device block
200-
connectReq = makeConnectRequest(password)
200+
connectReq = makeConnectRequest(credential)
201201
}
202202

203203
ws.send(JSON.stringify(connectReq))
@@ -274,7 +274,7 @@ export function GatewayProvider({ children }: { children: React.ReactNode }) {
274274
const shouldRemember = localStorage.getItem(STORAGE_REMEMBER) !== 'false'
275275
if (shouldRemember) {
276276
localStorage.setItem(STORAGE_URL, url)
277-
localStorage.setItem(STORAGE_PASS, password)
277+
localStorage.setItem(STORAGE_PASS, credential)
278278
}
279279
} catch {}
280280
return
@@ -348,7 +348,7 @@ export function GatewayProvider({ children }: { children: React.ReactNode }) {
348348
const delay = Math.min(1000 * Math.pow(2, attempt - 1), 30000)
349349
reconnectTimerRef.current = setTimeout(() => {
350350
if (credentialsRef.current) {
351-
doConnect(credentialsRef.current.url, credentialsRef.current.password)
351+
doConnect(credentialsRef.current.url, credentialsRef.current.credential)
352352
}
353353
}, delay)
354354
}
@@ -359,12 +359,12 @@ export function GatewayProvider({ children }: { children: React.ReactNode }) {
359359

360360
// Public connect
361361
const connect = useCallback(
362-
(url: string, password: string) => {
363-
credentialsRef.current = { url, password }
362+
(url: string, credential: string) => {
363+
credentialsRef.current = { url, credential }
364364
setGatewayUrl(url)
365365
reconnectAttemptRef.current = 0
366366
connectedRef.current = false
367-
doConnect(url, password)
367+
doConnect(url, credential)
368368
},
369369
[doConnect],
370370
)
@@ -392,14 +392,14 @@ export function GatewayProvider({ children }: { children: React.ReactNode }) {
392392
if (creds) {
393393
cleanup()
394394
reconnectAttemptRef.current = 0
395-
doConnect(creds.url, creds.password)
395+
doConnect(creds.url, creds.credential)
396396
return
397397
}
398398
try {
399399
const url = localStorage.getItem(STORAGE_URL)
400400
const pass = localStorage.getItem(STORAGE_PASS)
401401
if (url && pass) {
402-
credentialsRef.current = { url, password: pass }
402+
credentialsRef.current = { url, credential: pass }
403403
setGatewayUrl(url)
404404
cleanup()
405405
doConnect(url, pass)
@@ -469,7 +469,7 @@ export function GatewayProvider({ children }: { children: React.ReactNode }) {
469469
const url = localStorage.getItem(STORAGE_URL)
470470
const pass = localStorage.getItem(STORAGE_PASS)
471471
if (url && pass) {
472-
credentialsRef.current = { url, password: pass }
472+
credentialsRef.current = { url, credential: pass }
473473
setGatewayUrl(url)
474474
doConnect(url, pass)
475475
return
@@ -479,7 +479,7 @@ export function GatewayProvider({ children }: { children: React.ReactNode }) {
479479
// 2. On desktop (Tauri), read gateway config directly from ~/.openclaw/openclaw.json
480480
if (isTauri()) {
481481
try {
482-
const config = await tauriInvoke<{ url: string; password: string }>(
482+
const config = await tauriInvoke<{ url: string; credential: string }>(
483483
'engine_gateway_config',
484484
{},
485485
)
@@ -489,13 +489,13 @@ export function GatewayProvider({ children }: { children: React.ReactNode }) {
489489
const status = await tauriInvoke<{ running: boolean }>('engine_status', {})
490490
if (cancelled) return
491491

492-
if (status?.running && config.url && config.password) {
493-
credentialsRef.current = { url: config.url, password: config.password }
492+
if (status?.running && config.url && config.credential) {
493+
credentialsRef.current = { url: config.url, credential: config.credential }
494494
setGatewayUrl(config.url)
495495
// Save to localStorage so future reconnects are instant
496496
localStorage.setItem(STORAGE_URL, config.url)
497-
localStorage.setItem(STORAGE_PASS, config.password)
498-
doConnect(config.url, config.password)
497+
localStorage.setItem(STORAGE_PASS, config.credential)
498+
doConnect(config.url, config.credential)
499499
return
500500
}
501501
} catch {
@@ -512,7 +512,7 @@ export function GatewayProvider({ children }: { children: React.ReactNode }) {
512512
}).catch(() => null)
513513
if (cancelled) return
514514
if (probe && probe.ok) {
515-
credentialsRef.current = { url: localUrl, password: '' }
515+
credentialsRef.current = { url: localUrl, credential: '' }
516516
setGatewayUrl(localUrl)
517517
localStorage.setItem(STORAGE_URL, localUrl)
518518
localStorage.setItem(STORAGE_PASS, '')

src-tauri/src/engine.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub fn engine_restart() -> Result<String, String> {
117117
#[derive(Clone, Serialize)]
118118
pub struct GatewayConfig {
119119
pub url: String,
120-
pub password: String,
120+
pub credential: String,
121121
}
122122

123123
#[tauri::command]
@@ -157,14 +157,14 @@ pub fn engine_gateway_config() -> Result<GatewayConfig, String> {
157157

158158
// Also check OPENCLAW_GATEWAY_TOKEN env var as final fallback,
159159
// matching how the gateway itself resolves the token at runtime.
160-
let password = if token_from_config.is_empty() {
160+
let credential = if token_from_config.is_empty() {
161161
std::env::var("OPENCLAW_GATEWAY_TOKEN").unwrap_or_default()
162162
} else {
163163
token_from_config.to_string()
164164
};
165165

166166
Ok(GatewayConfig {
167167
url: format!("ws://127.0.0.1:{}", port),
168-
password,
168+
credential,
169169
})
170170
}

0 commit comments

Comments
 (0)