|
1 | 1 | import {Command} from '@oclif/core'
|
2 | 2 | import * as fs from 'node:fs'
|
3 | 3 | import * as http from 'node:http'
|
| 4 | +import path, {dirname} from 'node:path' |
4 | 5 | import {createInterface} from 'node:readline'
|
| 6 | +import {fileURLToPath} from 'node:url' |
5 | 7 | import open from 'open'
|
6 | 8 |
|
7 |
| -import { |
8 |
| - fileExists, getEnvDir, getEnvFilePath, promptOrgSelection, sendGraphQLRequest, |
9 |
| -} from '../../util/index.js' |
| 9 | +import {fileExists, getEnvDir, getEnvFilePath, promptOrgSelection, sendGraphQLRequest} from '../../util/index.js' |
| 10 | + |
| 11 | +const __filename = fileURLToPath(import.meta.url) |
| 12 | +const __dirname = dirname(__filename) |
10 | 13 |
|
11 | 14 | export default class LoginIndex extends Command {
|
12 | 15 | static override args = {}
|
@@ -34,8 +37,10 @@ export default class LoginIndex extends Command {
|
34 | 37 |
|
35 | 38 | if (jwt && email) {
|
36 | 39 | // Send response back to browser indicating success
|
37 |
| - res.writeHead(200, {'Content-Type': 'text/plain'}) |
38 |
| - res.end('Login successful! You can close this tab.') |
| 40 | + const filePath = path.join(__dirname, 'login.html') |
| 41 | + const content = fs.readFileSync(filePath, 'utf8') |
| 42 | + res.writeHead(200, {'Content-Type': 'text/html'}) |
| 43 | + res.end(content) |
39 | 44 |
|
40 | 45 | // Close the server once JWT and email are captured
|
41 | 46 | server.close()
|
@@ -99,18 +104,18 @@ export default class LoginIndex extends Command {
|
99 | 104 | const content = fs.readFileSync(envFilePath, 'utf8')
|
100 | 105 |
|
101 | 106 | // Check if the file contains HYP_JWT and HYP_EMAIL, if not add them
|
102 |
| - const updatedContent |
103 |
| - = !content.includes('HYP_JWT=') || !content.includes('HYP_EMAIL=') || !content.includes('HYP_ORG_ID=') |
| 107 | + const updatedContent = |
| 108 | + !content.includes('HYP_JWT=') || !content.includes('HYP_EMAIL=') || !content.includes('HYP_ORG_ID=') |
104 | 109 | ? content + `HYP_JWT=${jwt}\nHYP_EMAIL=${email}\nHYP_ORG_ID=${orgId}\n`
|
105 | 110 | : content
|
106 |
| - .split('\n') |
107 |
| - .map(line => { |
108 |
| - if (line.startsWith('HYP_JWT=')) return `HYP_JWT=${jwt}` |
109 |
| - if (line.startsWith('HYP_EMAIL=')) return `HYP_EMAIL=${email}` |
110 |
| - if (line.startsWith('HYP_ORG_ID=')) return `HYP_ORG_ID=${orgId}` |
111 |
| - return line // Keep other lines unchanged |
112 |
| - }) |
113 |
| - .join('\n') |
| 111 | + .split('\n') |
| 112 | + .map((line) => { |
| 113 | + if (line.startsWith('HYP_JWT=')) return `HYP_JWT=${jwt}` |
| 114 | + if (line.startsWith('HYP_EMAIL=')) return `HYP_EMAIL=${email}` |
| 115 | + if (line.startsWith('HYP_ORG_ID=')) return `HYP_ORG_ID=${orgId}` |
| 116 | + return line // Keep other lines unchanged |
| 117 | + }) |
| 118 | + .join('\n') |
114 | 119 |
|
115 | 120 | // delete the file
|
116 | 121 | fs.unlinkSync(envFilePath)
|
|
0 commit comments