feat(cli): Add /auth logout command to clear credentials and auth state (#13383)

This commit is contained in:
Scars
2025-12-18 01:07:13 +08:00
committed by GitHub
parent d02f3f6809
commit 80c4225286
6 changed files with 339 additions and 10 deletions

View File

@@ -4,7 +4,13 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { useCallback, useMemo, useEffect, useState } from 'react';
import {
useCallback,
useMemo,
useEffect,
useState,
createElement,
} from 'react';
import { type PartListUnion } from '@google/genai';
import process from 'node:process';
import type { UseHistoryManagerReturn } from './useHistoryManager.js';
@@ -45,6 +51,11 @@ import {
} from '../state/extensions.js';
import { appEvents } from '../../utils/events.js';
import { useAlternateBuffer } from './useAlternateBuffer.js';
import {
LogoutConfirmationDialog,
LogoutChoice,
} from '../components/LogoutConfirmationDialog.js';
import { runExitCleanup } from '../../utils/cleanup.js';
interface SlashCommandProcessorActions {
openAuthDialog: () => void;
@@ -400,6 +411,22 @@ export const useSlashCommandProcessor = (
Date.now(),
);
return { type: 'handled' };
case 'logout':
// Show logout confirmation dialog with Login/Exit options
setCustomDialog(
createElement(LogoutConfirmationDialog, {
onSelect: async (choice: LogoutChoice) => {
setCustomDialog(null);
if (choice === LogoutChoice.LOGIN) {
actions.openAuthDialog();
} else {
await runExitCleanup();
process.exit(0);
}
},
}),
);
return { type: 'handled' };
case 'dialog':
switch (result.dialog) {
case 'auth':