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);
|
await clearToken().catch(() => undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
let canceledAtEmailPrompt = false;
|
|
||||||
let canceledAtOtpPrompt = false;
|
|
||||||
|
|
||||||
const promptForEmail = async (): Promise<string | undefined> => {
|
const promptForEmail = async (): Promise<string | undefined> => {
|
||||||
const value = await ctx.ui.input("Perplexity email", "you@example.com");
|
const value = await ctx.ui.input("Perplexity email", "you@example.com");
|
||||||
if (!value?.trim()) {
|
return value?.trim() || undefined;
|
||||||
canceledAtEmailPrompt = true;
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const promptForOtp = async (email: string): Promise<string | undefined> => {
|
const promptForOtp = async (email: string): Promise<string | undefined> => {
|
||||||
const value = await ctx.ui.input(`Enter OTP sent to ${email}`, "123456");
|
const value = await ctx.ui.input(`Enter OTP sent to ${email}`, "123456");
|
||||||
if (!value?.trim()) {
|
return value?.trim() || undefined;
|
||||||
canceledAtOtpPrompt = true;
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await authenticate({
|
await authenticate({ promptForEmail, promptForOtp });
|
||||||
promptForEmail,
|
|
||||||
promptForOtp,
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.ui.notify("Perplexity login successful. Token saved.", "info");
|
ctx.ui.notify("Perplexity login successful. Token saved.", "info");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (canceledAtEmailPrompt || canceledAtOtpPrompt) {
|
if (error instanceof AuthError && error.code === "NO_TOKEN") {
|
||||||
ctx.ui.notify(
|
ctx.ui.notify(
|
||||||
"Perplexity login canceled. Re-run /perplexity-login and provide email + OTP, or set PI_PERPLEXITY_EMAIL and PI_PERPLEXITY_OTP.",
|
"Perplexity login canceled. Re-run /perplexity-login and provide email + OTP, or set PI_PERPLEXITY_EMAIL and PI_PERPLEXITY_OTP.",
|
||||||
"warning",
|
"warning",
|
||||||
|
|||||||
Reference in New Issue
Block a user