feat: Add GEMINI_DEFAULT_AUTH_TYPE support (#4002)

This commit is contained in:
N. Taylor Mullen
2025-07-12 20:43:35 -07:00
committed by GitHub
parent 4442e893c3
commit 26a79fec25
2 changed files with 199 additions and 25 deletions

View File

@@ -18,18 +18,47 @@ interface AuthDialogProps {
initialErrorMessage?: string | null;
}
function parseDefaultAuthType(
defaultAuthType: string | undefined,
): AuthType | null {
if (
defaultAuthType &&
Object.values(AuthType).includes(defaultAuthType as AuthType)
) {
return defaultAuthType as AuthType;
}
return null;
}
export function AuthDialog({
onSelect,
settings,
initialErrorMessage,
}: AuthDialogProps): React.JSX.Element {
const [errorMessage, setErrorMessage] = useState<string | null>(
initialErrorMessage
? initialErrorMessage
: process.env.GEMINI_API_KEY
? 'Existing API key detected (GEMINI_API_KEY). Select "Gemini API Key" option to use it.'
: null,
);
const [errorMessage, setErrorMessage] = useState<string | null>(() => {
if (initialErrorMessage) {
return initialErrorMessage;
}
const defaultAuthType = parseDefaultAuthType(
process.env.GEMINI_DEFAULT_AUTH_TYPE,
);
if (process.env.GEMINI_DEFAULT_AUTH_TYPE && defaultAuthType === null) {
return (
`Invalid value for GEMINI_DEFAULT_AUTH_TYPE: "${process.env.GEMINI_DEFAULT_AUTH_TYPE}". ` +
`Valid values are: ${Object.values(AuthType).join(', ')}.`
);
}
if (
process.env.GEMINI_API_KEY &&
(!defaultAuthType || defaultAuthType === AuthType.USE_GEMINI)
) {
return 'Existing API key detected (GEMINI_API_KEY). Select "Gemini API Key" option to use it.';
}
return null;
});
const items = [
{
label: 'Login with Google',
@@ -55,6 +84,13 @@ export function AuthDialog({
return item.value === settings.merged.selectedAuthType;
}
const defaultAuthType = parseDefaultAuthType(
process.env.GEMINI_DEFAULT_AUTH_TYPE,
);
if (defaultAuthType) {
return item.value === defaultAuthType;
}
if (process.env.GEMINI_API_KEY) {
return item.value === AuthType.USE_GEMINI;
}