Skip to content

Commit a35f34a

Browse files
committed
fix(gemini): robust auth detection in settings sync
1 parent acebd29 commit a35f34a

File tree

1 file changed

+15
-5
lines changed
  • packages/lib/src/core/templates-entrypoint

1 file changed

+15
-5
lines changed

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,21 @@ const nextSettings = {
119119
}
120120
121121
// Auto-detect auth method if not set
122-
if (!nextSettings.security.auth || !nextSettings.security.auth.selectedType) {
123-
if (fs.existsSync(path.join(path.dirname(settingsPath), "oauth_creds.json"))) {
124-
nextSettings.security.auth = { ...(nextSettings.security.auth || {}), selectedType: "oauth-personal" }
125-
} else if (fs.existsSync(path.join(path.dirname(settingsPath), "..", ".api-key"))) {
126-
nextSettings.security.auth = { ...(nextSettings.security.auth || {}), selectedType: "api-key" }
122+
const currentAuth = nextSettings.security.auth
123+
if (!isRecord(currentAuth) || !currentAuth.selectedType) {
124+
const settingsDir = path.dirname(settingsPath)
125+
const configDir = process.env.GEMINI_CONFIG_DIR || ""
126+
127+
const hasOauth = fs.existsSync(path.join(settingsDir, "oauth_creds.json")) ||
128+
(configDir && fs.existsSync(path.join(configDir, ".gemini", "oauth_creds.json")))
129+
130+
const hasApiKey = fs.existsSync(path.join(settingsDir, "..", ".api-key")) ||
131+
(configDir && fs.existsSync(path.join(configDir, ".api-key")))
132+
133+
if (hasOauth) {
134+
nextSettings.security.auth = { ...(isRecord(currentAuth) ? currentAuth : {}), selectedType: "oauth-personal" }
135+
} else if (hasApiKey) {
136+
nextSettings.security.auth = { ...(isRecord(currentAuth) ? currentAuth : {}), selectedType: "api-key" }
127137
}
128138
}
129139

0 commit comments

Comments
 (0)