refactor: loginManually takes promptLogin
parent
b5e314eaf1
commit
597960df32
13
src/app.ts
13
src/app.ts
|
|
@ -263,9 +263,20 @@ export class App {
|
||||||
}
|
}
|
||||||
async run() {
|
async run() {
|
||||||
await this.profile.readState();
|
await this.profile.readState();
|
||||||
|
const { logger, readline, newFetcher } = this.env;
|
||||||
|
|
||||||
if (!this.profile.state.loginState?.sessionToken) {
|
if (!this.profile.state.loginState?.sessionToken) {
|
||||||
const sessionToken = await loginManually(this.env);
|
const sessionToken = await loginManually({
|
||||||
|
newFetcher,
|
||||||
|
promptLogin: async (url: string) => {
|
||||||
|
logger.log("Navigate to this URL in your browser:");
|
||||||
|
logger.log(url);
|
||||||
|
logger.log(
|
||||||
|
'Log in, right click the "Select this account" button, copy the link address, and paste it below:',
|
||||||
|
);
|
||||||
|
return await readline();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
await this.profile.writeState({
|
await this.profile.writeState({
|
||||||
...this.profile.state,
|
...this.profile.state,
|
||||||
|
|
|
||||||
13
src/iksm.ts
13
src/iksm.ts
|
|
@ -9,7 +9,10 @@ import { APIError } from "./APIError.ts";
|
||||||
import { Env, Fetcher } from "./env.ts";
|
import { Env, Fetcher } from "./env.ts";
|
||||||
|
|
||||||
export async function loginManually(
|
export async function loginManually(
|
||||||
{ logger, readline, newFetcher }: Env,
|
{ newFetcher, promptLogin }: {
|
||||||
|
newFetcher: () => Fetcher;
|
||||||
|
promptLogin: (url: string) => Promise<string>;
|
||||||
|
},
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const fetch = newFetcher();
|
const fetch = newFetcher();
|
||||||
|
|
||||||
|
|
@ -52,13 +55,7 @@ export async function loginManually(
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
logger.log("Navigate to this URL in your browser:");
|
const login = (await promptLogin(res.url)).trim();
|
||||||
logger.log(res.url);
|
|
||||||
logger.log(
|
|
||||||
'Log in, right click the "Select this account" button, copy the link address, and paste it below:',
|
|
||||||
);
|
|
||||||
|
|
||||||
const login = (await readline()).trim();
|
|
||||||
if (!login) {
|
if (!login) {
|
||||||
throw new Error("No login URL provided");
|
throw new Error("No login URL provided");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue