Files
gemini-cli/packages/cli/src/ui/components/UserIdentity.tsx
T

66 lines
1.6 KiB
TypeScript
Raw Normal View History

/**
* @license
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import type React from 'react';
2026-03-09 13:40:46 -07:00
import { useMemo } from 'react';
import { Box, Text } from 'ink';
import { theme } from '../semantic-colors.js';
import {
type Config,
UserAccountManager,
AuthType,
} from '@google/gemini-cli-core';
interface UserIdentityProps {
config: Config;
}
export const UserIdentity: React.FC<UserIdentityProps> = ({ config }) => {
const authType = config.getContentGeneratorConfig()?.authType;
2026-03-09 13:40:46 -07:00
const email = useMemo(() => {
if (authType) {
const userAccountManager = new UserAccountManager();
2026-03-09 13:40:46 -07:00
return userAccountManager.getCachedGoogleAccount() ?? undefined;
}
2026-03-09 13:40:46 -07:00
return undefined;
}, [authType]);
const tierName = useMemo(
() => (authType ? config.getUserTierName() : undefined),
[config, authType],
);
if (!authType) {
return null;
}
return (
<Box flexDirection="column">
{/* User Email /auth */}
<Box>
<Text color={theme.text.primary} wrap="truncate-end">
{authType === AuthType.LOGIN_WITH_GOOGLE ? (
<Text>{email ?? 'Logged in with Google'}</Text>
) : (
`Authenticated with ${authType}`
)}
</Text>
<Text color={theme.text.secondary}> /auth</Text>
</Box>
{/* Tier Name /upgrade */}
{tierName && (
<Box>
<Text color={theme.text.primary} wrap="truncate-end">
{tierName}
</Text>
<Text color={theme.text.secondary}> /upgrade</Text>
</Box>
)}
</Box>
);
};