fix: fix bugs
This commit is contained in:
		| @@ -44,4 +44,5 @@ export const getConfig = () => { | ||||
|  | ||||
| export const writeConfig = (config: Record<string, any>) => { | ||||
|   fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); | ||||
|   return config; | ||||
| }; | ||||
|   | ||||
| @@ -4,13 +4,7 @@ import { chalk } from '../chalk.ts'; | ||||
| import jsonwebtoken from 'jsonwebtoken'; | ||||
| import { BaseLoad } from '@kevisual/load'; | ||||
| import { getConfig, writeConfig } from '../get-config.ts'; | ||||
| const saveToken = async (token: string) => { | ||||
|   const config = await getConfig(); | ||||
|   writeConfig({ | ||||
|     ...config, | ||||
|     token, | ||||
|   }); | ||||
| }; | ||||
|  | ||||
| type LoginWithWebOptions = {}; | ||||
| export const loginWithWeb = async (opts?: LoginWithWebOptions) => { | ||||
|   const baseURL = getBaseURL(); | ||||
| @@ -36,6 +30,7 @@ export const loginWithWeb = async (opts?: LoginWithWebOptions) => { | ||||
|  | ||||
| type PollLoginOptions = { | ||||
|   tokenSecret: string; | ||||
|   saveToken?: any; | ||||
| }; | ||||
| export const pollLoginStatus = async (token: string, opts: PollLoginOptions) => { | ||||
|   const load = new BaseLoad(); | ||||
| @@ -75,8 +70,9 @@ export const pollLoginStatus = async (token: string, opts: PollLoginOptions) => | ||||
|       }; | ||||
|       const userToken = payload.userToken; | ||||
|       // console.log('token:\n\n', userToken); | ||||
|       console.log(chalk.green('登录成功', payload?.user?.username)); | ||||
|       await saveToken(userToken.token); | ||||
|       console.log(chalk.green('网页登录成功', payload?.user?.username)); | ||||
|       console.log(chalk.green('token:', userToken.token)); | ||||
|       await opts?.saveToken(userToken.token); | ||||
|       return; | ||||
|     } catch (error) { | ||||
|       console.log(chalk.red('登录失败'), error); | ||||
| @@ -85,9 +81,9 @@ export const pollLoginStatus = async (token: string, opts: PollLoginOptions) => | ||||
|   console.log(chalk.red('登录失败'), res); | ||||
| }; | ||||
|  | ||||
| export const loginInCommand = async () => { | ||||
| export const loginInCommand = async (saveToken: any) => { | ||||
|   const { url, token, tokenSecret } = await loginWithWeb(); | ||||
|   await pollLoginStatus(token, { tokenSecret }); | ||||
|   await pollLoginStatus(token, { tokenSecret, saveToken }); | ||||
|   return url; | ||||
| }; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user