feat(admin): prompt user to restart the CLI if they change auth to oauth mid-session or don't have auth type selected at start of session (#16426)

This commit is contained in:
Shreya Keshive
2026-01-12 15:39:08 -05:00
committed by GitHub
parent 2306e60be4
commit d65eab01d2
10 changed files with 207 additions and 2 deletions
+30 -1
View File
@@ -126,6 +126,7 @@ import {
WARNING_PROMPT_DURATION_MS,
QUEUE_ERROR_DISPLAY_DURATION_MS,
} from './constants.js';
import { LoginWithGoogleRestartDialog } from './auth/LoginWithGoogleRestartDialog.js';
function isToolExecuting(pendingHistoryItems: HistoryItemWithoutId[]) {
return pendingHistoryItems.some((item) => {
@@ -468,6 +469,16 @@ export const AppContainer = (props: AppContainerProps) => {
apiKeyDefaultValue,
reloadApiKey,
} = useAuthCommand(settings, config);
const [authContext, setAuthContext] = useState<{ requiresRestart?: boolean }>(
{},
);
useEffect(() => {
if (authState === AuthState.Authenticated && authContext.requiresRestart) {
setAuthState(AuthState.AwaitingGoogleLoginRestart);
setAuthContext({});
}
}, [authState, authContext, setAuthState]);
const { proQuotaRequest, handleProQuotaChoice } = useQuotaAndFallback({
config,
@@ -511,6 +522,11 @@ export const AppContainer = (props: AppContainerProps) => {
const handleAuthSelect = useCallback(
async (authType: AuthType | undefined, scope: LoadableSettingScope) => {
if (authType) {
if (authType === AuthType.LOGIN_WITH_GOOGLE) {
setAuthContext({ requiresRestart: true });
} else {
setAuthContext({});
}
await clearCachedCredentialFile();
settings.setValue(scope, 'security.auth.selectedType', authType);
@@ -539,7 +555,7 @@ Logging in with Google... Restarting Gemini CLI to continue.
}
setAuthState(AuthState.Authenticated);
},
[settings, config, setAuthState, onAuthError],
[settings, config, setAuthState, onAuthError, setAuthContext],
);
const handleApiKeySubmit = useCallback(
@@ -1687,6 +1703,7 @@ Logging in with Google... Restarting Gemini CLI to continue.
handleApiKeyCancel,
setBannerVisible,
setEmbeddedShellFocused,
setAuthContext,
}),
[
handleThemeSelect,
@@ -1722,9 +1739,21 @@ Logging in with Google... Restarting Gemini CLI to continue.
handleApiKeyCancel,
setBannerVisible,
setEmbeddedShellFocused,
setAuthContext,
],
);
if (authState === AuthState.AwaitingGoogleLoginRestart) {
return (
<LoginWithGoogleRestartDialog
onDismiss={() => {
setAuthContext({});
setAuthState(AuthState.Updating);
}}
/>
);
}
return (
<UIStateContext.Provider value={uiState}>
<UIActionsContext.Provider value={uiActions}>