Remove closure cancel flags from login command
canceledAtEmailPrompt and canceledAtOtpPrompt were closure booleans set inside prompt callbacks to detect user cancellation after the fact. Fragile if authenticate ever retries prompts or changes order. In the command context both prompt functions are always provided, so AuthError(NO_TOKEN) unambiguously means the user declined to enter required input. Check the error code directly instead.
This commit is contained in:
+4
-21
@@ -67,38 +67,21 @@ export function registerPerplexityCommands(pi: ExtensionAPI): void {
|
||||
await clearToken().catch(() => undefined);
|
||||
}
|
||||
|
||||
let canceledAtEmailPrompt = false;
|
||||
let canceledAtOtpPrompt = false;
|
||||
|
||||
const promptForEmail = async (): Promise<string | undefined> => {
|
||||
const value = await ctx.ui.input("Perplexity email", "you@example.com");
|
||||
if (!value?.trim()) {
|
||||
canceledAtEmailPrompt = true;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return value;
|
||||
return value?.trim() || undefined;
|
||||
};
|
||||
|
||||
const promptForOtp = async (email: string): Promise<string | undefined> => {
|
||||
const value = await ctx.ui.input(`Enter OTP sent to ${email}`, "123456");
|
||||
if (!value?.trim()) {
|
||||
canceledAtOtpPrompt = true;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return value;
|
||||
return value?.trim() || undefined;
|
||||
};
|
||||
|
||||
try {
|
||||
await authenticate({
|
||||
promptForEmail,
|
||||
promptForOtp,
|
||||
});
|
||||
|
||||
await authenticate({ promptForEmail, promptForOtp });
|
||||
ctx.ui.notify("Perplexity login successful. Token saved.", "info");
|
||||
} catch (error) {
|
||||
if (canceledAtEmailPrompt || canceledAtOtpPrompt) {
|
||||
if (error instanceof AuthError && error.code === "NO_TOKEN") {
|
||||
ctx.ui.notify(
|
||||
"Perplexity login canceled. Re-run /perplexity-login and provide email + OTP, or set PI_PERPLEXITY_EMAIL and PI_PERPLEXITY_OTP.",
|
||||
"warning",
|
||||
|
||||
Reference in New Issue
Block a user