fix: clarify control ui auth hints (fixes #1690)
This commit is contained in:
@@ -66,19 +66,34 @@ function formatGatewayAuthFailureMessage(params: {
|
||||
authMode: ResolvedGatewayAuth["mode"];
|
||||
authProvided: AuthProvidedKind;
|
||||
reason?: string;
|
||||
client?: { id?: string | null; mode?: string | null };
|
||||
}): string {
|
||||
const { authMode, authProvided, reason } = params;
|
||||
const { authMode, authProvided, reason, client } = params;
|
||||
const isCli = isGatewayCliClient(client);
|
||||
const isControlUi = client?.id === GATEWAY_CLIENT_IDS.CONTROL_UI;
|
||||
const isWebchat = isWebchatClient(client);
|
||||
const uiHint = "open a tokenized dashboard URL or paste token in Control UI settings";
|
||||
const tokenHint = isCli
|
||||
? "set gateway.remote.token to match gateway.auth.token"
|
||||
: isControlUi || isWebchat
|
||||
? uiHint
|
||||
: "provide gateway auth token";
|
||||
const passwordHint = isCli
|
||||
? "set gateway.remote.password to match gateway.auth.password"
|
||||
: isControlUi || isWebchat
|
||||
? "enter the password in Control UI settings"
|
||||
: "provide gateway auth password";
|
||||
switch (reason) {
|
||||
case "token_missing":
|
||||
return "unauthorized: gateway token missing (set gateway.remote.token to match gateway.auth.token)";
|
||||
return `unauthorized: gateway token missing (${tokenHint})`;
|
||||
case "token_mismatch":
|
||||
return "unauthorized: gateway token mismatch (set gateway.remote.token to match gateway.auth.token)";
|
||||
return `unauthorized: gateway token mismatch (${tokenHint})`;
|
||||
case "token_missing_config":
|
||||
return "unauthorized: gateway token not configured on gateway (set gateway.auth.token)";
|
||||
case "password_missing":
|
||||
return "unauthorized: gateway password missing (set gateway.remote.password to match gateway.auth.password)";
|
||||
return `unauthorized: gateway password missing (${passwordHint})`;
|
||||
case "password_mismatch":
|
||||
return "unauthorized: gateway password mismatch (set gateway.remote.password to match gateway.auth.password)";
|
||||
return `unauthorized: gateway password mismatch (${passwordHint})`;
|
||||
case "password_missing_config":
|
||||
return "unauthorized: gateway password not configured on gateway (set gateway.auth.password)";
|
||||
case "tailscale_user_missing":
|
||||
@@ -90,10 +105,10 @@ function formatGatewayAuthFailureMessage(params: {
|
||||
}
|
||||
|
||||
if (authMode === "token" && authProvided === "none") {
|
||||
return "unauthorized: gateway token missing (set gateway.remote.token to match gateway.auth.token)";
|
||||
return `unauthorized: gateway token missing (${tokenHint})`;
|
||||
}
|
||||
if (authMode === "password" && authProvided === "none") {
|
||||
return "unauthorized: gateway password missing (set gateway.remote.password to match gateway.auth.password)";
|
||||
return `unauthorized: gateway password missing (${passwordHint})`;
|
||||
}
|
||||
return "unauthorized";
|
||||
}
|
||||
@@ -532,6 +547,7 @@ export function attachGatewayWsMessageHandler(params: {
|
||||
authMode: resolvedAuth.mode,
|
||||
authProvided,
|
||||
reason: authResult.reason,
|
||||
client: connectParams.client,
|
||||
});
|
||||
setCloseCause("unauthorized", {
|
||||
authMode: resolvedAuth.mode,
|
||||
|
||||
Reference in New Issue
Block a user