| |
| |
| |
| |
| |
|
|
| import { |
| type AuthType, |
| type Config, |
| getErrorMessage, |
| ValidationRequiredError, |
| isAccountSuspendedError, |
| ProjectIdRequiredError, |
| } from '@google/gemini-cli-core'; |
|
|
| import type { AccountSuspensionInfo } from '../ui/contexts/UIStateContext.js'; |
|
|
| export interface InitialAuthResult { |
| authError: string | null; |
| accountSuspensionInfo: AccountSuspensionInfo | null; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| export async function performInitialAuth( |
| config: Config, |
| authType: AuthType | undefined, |
| ): Promise<InitialAuthResult> { |
| if (!authType) { |
| return { authError: null, accountSuspensionInfo: null }; |
| } |
|
|
| try { |
| await config.refreshAuth(authType); |
| |
| |
| } catch (e) { |
| if (e instanceof ValidationRequiredError) { |
| |
| |
| return { authError: null, accountSuspensionInfo: null }; |
| } |
| const suspendedError = isAccountSuspendedError(e); |
| if (suspendedError) { |
| return { |
| authError: null, |
| accountSuspensionInfo: { |
| message: suspendedError.message, |
| appealUrl: suspendedError.appealUrl, |
| appealLinkText: suspendedError.appealLinkText, |
| }, |
| }; |
| } |
| if (e instanceof ProjectIdRequiredError) { |
| |
| |
| return { |
| authError: getErrorMessage(e), |
| accountSuspensionInfo: null, |
| }; |
| } |
| return { |
| authError: `Failed to sign in. Message: ${getErrorMessage(e)}`, |
| accountSuspensionInfo: null, |
| }; |
| } |
|
|
| return { authError: null, accountSuspensionInfo: null }; |
| } |
|
|