Skip to content

Commit 30a1624

Browse files
committed
refactor(auth): optimize authentication check order for providers
- For Auggie, check credentials first before CLI installation for faster failure - For OpenCode, add additional sentinel file check before falling back to credentials
1 parent cb464ec commit 30a1624

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/infra/engines/providers/auggie/auth.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ function logInstallHelp(): void {
6767

6868

6969
export async function isAuthenticated(): Promise<boolean> {
70-
// Check if CLI is installed
71-
const cliInstalled = await isCliInstalled(metadata.cliBinary);
72-
if (!cliInstalled) {
70+
// Check credential file first (fast file stat)
71+
const hasCredential = await hasAuggieCredential();
72+
if (!hasCredential) {
7373
return false;
7474
}
7575

76-
// Check if Auggie has valid session
77-
return await hasAuggieCredential();
76+
// Credential exists, verify CLI is installed
77+
return await isCliInstalled(metadata.cliBinary);
7878
}
7979

8080
/**

src/infra/engines/providers/opencode/auth.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,24 @@ function logInstallHelp(): void {
7070

7171

7272
export async function isAuthenticated(): Promise<boolean> {
73-
return isCliInstalled(metadata.cliBinary);
73+
// First check if CLI is installed
74+
const cliInstalled = await isCliInstalled(metadata.cliBinary);
75+
if (!cliInstalled) {
76+
return false;
77+
}
78+
79+
// Check sentinel file (created after successful login via codemachine)
80+
const opencodeHome = resolveOpenCodeHome();
81+
const sentinelPath = getSentinelPath(opencodeHome);
82+
try {
83+
await stat(sentinelPath);
84+
return true;
85+
} catch {
86+
// Sentinel not found, check OpenCode's native auth
87+
}
88+
89+
// Check OpenCode's native credential file
90+
return hasOpenCodeCredential('opencode');
7491
}
7592

7693
/**

0 commit comments

Comments
 (0)