Skip to content

Commit fe55c73

Browse files
committed
Add cli-auth page
1 parent 6c50b85 commit fe55c73

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

site/api.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,16 @@ export const logout = async (): Promise<void> => {
139139

140140
return
141141
}
142+
143+
export const getApiKey = async (): Promise<{ key: string }> => {
144+
const response = await fetch("/api/v2/api-keys", {
145+
method: "POST",
146+
})
147+
148+
if (!response.ok) {
149+
const body = await response.json()
150+
throw new Error(body.message)
151+
}
152+
153+
return await response.json()
154+
}

site/pages/cli-auth.tsx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { Typography } from "@material-ui/core"
2+
import Paper from "@material-ui/core/Paper"
3+
import { makeStyles } from "@material-ui/core/styles"
4+
import React, { useEffect, useState } from "react"
5+
import { getApiKey } from "../api"
6+
import { CodeExample } from "../components/CodeExample"
7+
8+
import { FullScreenLoader } from "../components/Loader/FullScreenLoader"
9+
import { useUser } from "../contexts/UserContext"
10+
11+
const CliAuthenticationPage: React.FC = () => {
12+
const { me } = useUser(true)
13+
const styles = useStyles()
14+
15+
const [apiKey, setApiKey] = useState<string | null>(null)
16+
17+
useEffect(() => {
18+
if (me?.id) {
19+
getApiKey().then(({ key }) => {
20+
setApiKey(key)
21+
})
22+
}
23+
}, [me?.id])
24+
25+
if (!apiKey) {
26+
return <FullScreenLoader />
27+
}
28+
29+
return (
30+
<div className={styles.root}>
31+
<Paper className={styles.container}>
32+
<Typography className={styles.title}>Session Token</Typography>
33+
<CodeExample code={apiKey} />
34+
</Paper>
35+
</div>
36+
)
37+
}
38+
39+
const useStyles = makeStyles((theme) => ({
40+
root: {
41+
width: "100vh",
42+
height: "100vw",
43+
display: "flex",
44+
justifyContent: "center",
45+
alignItems: "center",
46+
},
47+
title: {
48+
marginBottom: theme.spacing(2),
49+
},
50+
container: {
51+
maxWidth: "680px",
52+
padding: theme.spacing(2),
53+
},
54+
}))
55+
56+
export default CliAuthenticationPage

0 commit comments

Comments
 (0)