|
1 | 1 | const { v4: uuidv4 } = require('uuid');
|
2 |
| -const axios = require('axios') |
3 |
| -const fs = require('fs'); |
| 2 | +const axios = require('axios'); |
4 | 3 | const chalk = require('chalk');
|
5 |
| -const { saveUserData, getUserData, checkUserAuth, deleteUserData } = require('./userData'); |
6 |
| - |
7 |
| -// Function to delete the users.json file |
8 |
| - |
| 4 | +const { saveUserData, checkUserAuth, deleteUserData } = require('./userData'); |
9 | 5 |
|
10 | 6 | // Function to log out the user
|
11 | 7 | const logout = () => {
|
12 | 8 | deleteUserData();
|
13 | 9 | console.log('Logged out successfully');
|
14 | 10 | };
|
15 | 11 |
|
16 |
| - |
| 12 | +// Function to sign in the user |
17 | 13 | const signIn = () => {
|
18 | 14 | if (checkUserAuth()) {
|
19 | 15 | console.log(chalk.yellow('Already logged in.'));
|
20 | 16 | } else {
|
21 | 17 | const uuid = uuidv4();
|
22 |
| - |
23 | 18 | console.log(chalk.blue(`Please open this URL to login: http://portal.codebolt.ai/performSignIn?uid=${uuid}&loginflow=app`));
|
24 |
| - |
| 19 | + |
25 | 20 | const intervalId = setInterval(async () => {
|
26 |
| - try { |
27 |
| - // const response = await axios.get( |
28 |
| - // `https://us-central1-codeboltai.cloudfunctions.net/checkOneTimeToken?oneTimeToken=${uuid}` |
29 |
| - // ); |
30 |
| - const response = await axios.get( |
31 |
| - `https://api.codebolt.ai/api/auth/addonetimetoken?oneTimeToken=${uuid}` |
32 |
| - ); |
| 21 | + try { |
| 22 | + console.log(`https://api.codebolt.ai/api/auth/addonetimetoken?oneTimeToken=${uuid}`); |
| 23 | + const response = await axios.post( |
| 24 | + `https://api.codebolt.ai/api/auth/addonetimetoken?oneTimeToken=${uuid}` |
| 25 | + ); |
33 | 26 |
|
34 |
| - if (response.status === 200) { |
35 |
| - clearInterval(intervalId); |
36 |
| - console.log(chalk.green('Login successful!')); |
37 |
| - saveUserData(response.data); |
| 27 | + if (response.status === 200) { |
| 28 | + clearInterval(intervalId); |
| 29 | + console.log(chalk.green('Login successful!')); |
| 30 | + saveUserData(response.data); |
| 31 | + } |
| 32 | + } catch (error) { |
| 33 | + console.error(chalk.red('Error checking token:', error)); |
38 | 34 | }
|
39 |
| - // Assuming there is a function saveUserApiResponse to handle saving the response |
40 |
| - } catch (error) { |
41 |
| - // console.log('Error checking token:', error); |
42 |
| - } |
43 | 35 | }, 1000);
|
44 | 36 | }
|
45 | 37 | };
|
46 | 38 |
|
47 |
| -module.exports={ |
| 39 | +module.exports = { |
48 | 40 | signIn,
|
49 | 41 | logout
|
50 |
| -} |
| 42 | +}; |
0 commit comments