Skip to content

Commit 7be81cd

Browse files
Add success state (#8)
* simple success state * remove css * fix imports * fix imports
1 parent c54cf0e commit 7be81cd

File tree

3 files changed

+71
-16
lines changed

3 files changed

+71
-16
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
},
8383
"scripts": {
8484
"pack": "oclif pack tarballs --parallel --no-xz",
85-
"build": "shx rm -rf dist && tsc -b",
85+
"build": "shx rm -rf dist && tsc -b && shx cp src/commands/login/login.html dist/commands/login/login.html",
8686
"lint": "eslint . --ext .ts",
8787
"postpack": "shx rm -f oclif.manifest.json",
8888
"posttest": "npm run lint",

src/commands/login/index.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import {Command} from '@oclif/core'
22
import * as fs from 'node:fs'
33
import * as http from 'node:http'
4+
import path, {dirname} from 'node:path'
45
import {createInterface} from 'node:readline'
6+
import {fileURLToPath} from 'node:url'
57
import open from 'open'
68

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)
1013

1114
export default class LoginIndex extends Command {
1215
static override args = {}
@@ -34,8 +37,10 @@ export default class LoginIndex extends Command {
3437

3538
if (jwt && email) {
3639
// 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)
3944

4045
// Close the server once JWT and email are captured
4146
server.close()
@@ -99,18 +104,18 @@ export default class LoginIndex extends Command {
99104
const content = fs.readFileSync(envFilePath, 'utf8')
100105

101106
// 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=')
104109
? content + `HYP_JWT=${jwt}\nHYP_EMAIL=${email}\nHYP_ORG_ID=${orgId}\n`
105110
: 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')
114119

115120
// delete the file
116121
fs.unlinkSync(envFilePath)

src/commands/login/login.html

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<!-- src/commands/login/login.html -->
2+
<!DOCTYPE html>
3+
<html lang="en">
4+
<head>
5+
<meta charset="UTF-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Success!</title>
8+
<style>
9+
body {
10+
font-family: Arial, sans-serif;
11+
display: flex;
12+
flex-direction: column;
13+
justify-content: center;
14+
align-items: center;
15+
height: 100vh;
16+
width: 100vw;
17+
margin: 0;
18+
background-color: #14161f;
19+
}
20+
h1 {
21+
color: #fff;
22+
text-align: center;
23+
margin-bottom: 8px;
24+
}
25+
26+
p {
27+
color: #62646b;
28+
text-align: center;
29+
}
30+
31+
svg {
32+
width: 36px;
33+
height: 36px;
34+
margin-bottom: 16px;
35+
}
36+
</style>
37+
</head>
38+
<body>
39+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
40+
<path
41+
fillRule="evenodd"
42+
clipRule="evenodd"
43+
fill="#fff"
44+
d="M10.0173 0H2.64764L0 10.3598H7.36967L10.0173 0ZM2.91136 22.6282L6.0172 10.3599H14.1776L16.8252 0.00012207H24.1949L18.3248 22.9691H10.9551L14.1592 10.4317L2.91136 22.6282Z"
45+
/>
46+
</svg>
47+
<h1>Authentication complete!</h1>
48+
<p>You can now close this window and return to the terminal.</p>
49+
</body>
50+
</html>

0 commit comments

Comments
 (0)