this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

CLI: Make 2FA auth actually work

futurGH 66bb9081 b49371d8

+20 -7
+20 -7
src/bin.ts
··· 1 1 #!/usr/bin/env node 2 + import { XRPCError } from "@atcute/client"; 2 3 import type { ComAtprotoLabelDefs } from "@atcute/client/lexicons"; 3 4 import { spawn } from "node:child_process"; 4 5 import * as fs from "node:fs/promises"; ··· 15 16 plcSetupLabeler, 16 17 setLabelerLabelDefinitions, 17 18 } from "./scripts/index.js"; 19 + import { loginAgent } from "./scripts/util.js"; 18 20 import { resolveHandle } from "./util/resolveHandle.js"; 19 21 20 22 const args = process.argv.slice(2); ··· 199 201 } 200 202 } 201 203 202 - const { password, pds, code } = await prompt([{ 204 + const { password, pds } = await prompt([{ 203 205 type: "password", 204 206 name: "password", 205 207 message: "Account password (cannot be an app password):", ··· 209 211 message: "URL of the PDS where the account is located:", 210 212 initial: "https://bsky.social", 211 213 validate: (value) => value.startsWith("https://") || "Must be a valid HTTPS URL.", 212 - }, { 213 - type: "text", 214 - name: "code", 215 - message: "2FA code (leave blank if 2FA is not enabled):", 216 - initial: "", 217 214 }], { onCancel: () => process.exit(1) }); 218 215 219 216 const credentials: LoginCredentials = { identifier: did, password, pds }; 220 - if (code) credentials.code = code.replaceAll(/\s+/g, ""); 217 + 218 + try { 219 + await loginAgent(credentials); 220 + } catch (error) { 221 + if (error instanceof XRPCError && error.kind === "AuthFactorTokenRequired") { 222 + const { code } = await prompt({ 223 + type: "text", 224 + name: "code", 225 + message: "You will receive a 2FA code via email. Code:", 226 + initial: "", 227 + }, { onCancel: () => process.exit(1) }); 228 + credentials.code = code; 229 + } else { 230 + console.error("Error occurred while trying to log in:", error); 231 + process.exit(1); 232 + } 233 + } 221 234 return credentials; 222 235 } 223 236