Skip to content

Commit 04b812b

Browse files
committed
fix(gemini): use reliable bash-based auth detection in entrypoint
1 parent a0d16c1 commit 04b812b

File tree

1 file changed

+12
-11
lines changed
  • packages/lib/src/core/templates-entrypoint

1 file changed

+12
-11
lines changed

packages/lib/src/core/templates-entrypoint/gemini.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,19 @@ GEMINI_CONFIG_SETTINGS_FILE="$GEMINI_SETTINGS_DIR/settings.json"
9292
mkdir -p "$GEMINI_SETTINGS_DIR" || true
9393
9494
# Disable folder trust prompt and enable auto-approval in settings.json
95+
# Detect auth method using Bash (more reliable in entrypoint)
96+
GEMINI_DETECTED_AUTH=""
97+
if [[ -f "$GEMINI_CONFIG_DIR/.gemini/oauth_creds.json" ]]; then
98+
GEMINI_DETECTED_AUTH="oauth-personal"
99+
elif [[ -f "$GEMINI_CONFIG_DIR/.api-key" ]]; then
100+
GEMINI_DETECTED_AUTH="api-key"
101+
fi
102+
95103
GEMINI_SYNC_SETTINGS_SCRIPT=$(cat <<'NODE'
96104
const fs = require("node:fs")
97105
const path = require("node:path")
98106
const settingsPath = process.argv[2]
107+
const detectedAuth = process.argv[3]
99108
if (!settingsPath) process.exit(1)
100109
101110
const isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v)
@@ -114,16 +123,8 @@ if (!isRecord(nextSettings.security.folderTrust)) nextSettings.security.folderTr
114123
nextSettings.security.folderTrust.enabled = false
115124
nextSettings.approvalPolicy = "never"
116125
117-
// Force auth method detection and correct placement in settings.json
118-
// Check GEMINI_CONFIG_DIR directly as symlinks might not be ready
119-
const configDir = process.env.GEMINI_CONFIG_DIR || ""
120-
const hasOauth = configDir && fs.existsSync(path.join(configDir, ".gemini", "oauth_creds.json"))
121-
const hasApiKey = configDir && fs.existsSync(path.join(configDir, ".api-key"))
122-
123-
if (hasOauth) {
124-
nextSettings.security.auth = { ...(isRecord(nextSettings.security.auth) ? nextSettings.security.auth : {}), selectedType: "oauth-personal" }
125-
} else if (hasApiKey) {
126-
nextSettings.security.auth = { ...(isRecord(nextSettings.security.auth) ? nextSettings.security.auth : {}), selectedType: "api-key" }
126+
if (detectedAuth) {
127+
nextSettings.security.auth = { ...(isRecord(nextSettings.security.auth) ? nextSettings.security.auth : {}), selectedType: detectedAuth }
127128
}
128129
129130
if (JSON.stringify(settings) !== JSON.stringify(nextSettings)) {
@@ -132,7 +133,7 @@ if (JSON.stringify(settings) !== JSON.stringify(nextSettings)) {
132133
}
133134
NODE
134135
)
135-
node -e "$GEMINI_SYNC_SETTINGS_SCRIPT" "$GEMINI_CONFIG_SETTINGS_FILE" || true
136+
node -e "$GEMINI_SYNC_SETTINGS_SCRIPT" "$GEMINI_CONFIG_SETTINGS_FILE" "$GEMINI_DETECTED_AUTH" || true
136137
137138
# Pre-trust important directories in trustedFolders.json
138139
# Use flat mapping as required by recent Gemini CLI versions

0 commit comments

Comments
 (0)