diff --git a/src/auth/login.ts b/src/auth/login.ts index 879c112..d2a8b04 100644 --- a/src/auth/login.ts +++ b/src/auth/login.ts @@ -39,7 +39,6 @@ export interface AuthenticateOptions { signal?: AbortSignal; promptForEmail?: () => Promise; promptForOtp?: (email: string) => Promise; - promptForBrowserAuth?: () => Promise; } function normalizeInput(value: string | null | undefined): string | null { @@ -91,16 +90,6 @@ export async function saveBrowserAuthInput(input: string): Promise return credentials; } -async function promptForBrowserCredentials( - options: AuthenticateOptions, -): Promise { - const input = normalizeInput(await options.promptForBrowserAuth?.()); - if (!input) { - return null; - } - return saveBrowserAuthInput(input); -} - function buildAuthHeaders(includeJsonContentType = false): Record { return { Accept: "application/json", @@ -297,11 +286,6 @@ export async function authenticate(options: AuthenticateOptions = {}): Promise promptInput("Perplexity email", "you@example.com"), promptForOtp: async (email) => promptInput(`Enter OTP sent to ${email}`, "123456"), - promptForBrowserAuth: async () => { - ctx?.ui?.notify?.(browserLoginInstructions(), "info"); - return promptInput( - "Paste copied cURL command or Cookie header", - "curl 'https://www.perplexity.ai/' -H 'Cookie: ...'", - ); - }, }); if (signal?.aborted) { diff --git a/test/auth/login.test.ts b/test/auth/login.test.ts index e38ac2c..341443c 100644 --- a/test/auth/login.test.ts +++ b/test/auth/login.test.ts @@ -442,35 +442,6 @@ describe("auth/login", () => { expect(saveTokenMock).toHaveBeenCalledTimes(0); }); - test("authenticate falls back to browser auth when OTP CSRF hits Cloudflare", async () => { - process.env.PI_AUTH_NO_BORROW = "1"; - const browserToken = createJwt(Date.now() + 2 * 60 * 60 * 1000); - - const loadTokenMock = mock(async () => null); - const saveTokenMock = mock(async (_token: StoredToken) => undefined); - const clearTokenMock = mock(async () => undefined); - - mock.module("../../src/auth/storage.js", () => ({ - loadToken: loadTokenMock, - saveToken: saveTokenMock, - clearToken: clearTokenMock, - })); - - const fetchMock = mock(async () => - new Response("Just a moment...", { status: 403 }), - ); - globalThis.fetch = fetchMock as unknown as typeof fetch; - - const { authenticate } = await importLoginModule(); - - const token = await authenticate({ - promptForEmail: async () => "user@example.com", - promptForBrowserAuth: async () => `__Secure-next-auth.session-token=${browserToken}; cf_clearance=ok`, - }); - - expect(token.cookies).toContain("cf_clearance=ok"); - expect(saveTokenMock).toHaveBeenCalledTimes(1); - }); test("authenticate throws NO_TOKEN when no cached token and no OTP email input", async () => { process.env.PI_AUTH_NO_BORROW = "1";