refactor(auth): enhance authentication detection and status handling

- Improved the CodexCliDetector to provide detailed logging and better error handling when reading the authentication file.
- Updated the authentication method determination in the settings and setup views to prioritize CLI-based methods over traditional API key methods.
- Expanded the CodexAuthStatus interface to include new authentication methods, ensuring accurate representation of the authentication state.
- Enhanced UI feedback in the settings view to reflect the new authentication methods, improving user experience.
This commit is contained in:
Kacper
2025-12-10 23:35:09 +01:00
parent 6086d22a44
commit d5d6cdf80f
5 changed files with 143 additions and 35 deletions

View File

@@ -11,7 +11,7 @@ import {
CardHeader,
CardTitle,
} from "@/components/ui/card";
import { useSetupStore } from "@/store/setup-store";
import { useSetupStore, type CodexAuthStatus } from "@/store/setup-store";
import { useAppStore } from "@/store/app-store";
import { getElectronAPI } from "@/lib/electron";
import {
@@ -805,13 +805,22 @@ function CodexSetupStep({
setCodexCliStatus(cliStatus);
if (result.auth) {
const authStatus = {
const method = result.auth.method === "cli_verified" || result.auth.method === "cli_tokens"
? (result.auth.method === "cli_verified" ? "cli_verified" : "cli_tokens")
: result.auth.method === "auth_file"
? "api_key"
: result.auth.method === "env_var"
? "env"
: "none";
const authStatus: CodexAuthStatus = {
authenticated: result.auth.authenticated,
method: result.auth.method === "auth_file" ? "api_key" : result.auth.method === "env_var" ? "env" : "none",
apiKeyValid: result.auth.authenticated,
method,
// Only set apiKeyValid for actual API key methods, not CLI login
apiKeyValid: method === "cli_verified" || method === "cli_tokens" ? undefined : result.auth.authenticated,
};
console.log("[Codex Setup] Auth Status:", authStatus);
setCodexAuthStatus(authStatus as any);
setCodexAuthStatus(authStatus);
} else {
console.log("[Codex Setup] No auth info in result");
}