Skip to content

Commit 8a40dd8

Browse files
committedMar 10, 2025·
move main into async fn
1 parent e92a10c commit 8a40dd8

File tree

1 file changed

+33
-29
lines changed

1 file changed

+33
-29
lines changed
 

‎src/main.ts

+33-29
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
11
import { Clerk } from '@clerk/clerk-js'
22
import './style.css'
33

4-
const clerk = new Clerk("pk_test_YWRhcHRlZC1mb2FsLTQyLmNsZXJrLmFjY291bnRzLmRldiQ")
5-
await clerk.load()
4+
async function main() {
5+
const clerk = new Clerk("pk_test_YWRhcHRlZC1mb2FsLTQyLmNsZXJrLmFjY291bnRzLmRldiQ")
6+
await clerk.load()
67

7-
if (!clerk.user || !clerk.session) {
8-
window.location.href = "/login"
9-
} else {
10-
const token = await clerk.session.getToken()
8+
if (!clerk.user || !clerk.session) {
9+
window.location.href = "/login"
10+
} else {
11+
const token = await clerk.session.getToken()
1112

12-
async function fetchData() {
13-
const button = document.getElementById("fetch-data-button")! as HTMLButtonElement
14-
button.disabled = true
15-
button.textContent = "Fetching..."
16-
const response = await fetch("/hello", {
17-
headers: {
18-
"Authorization": `Bearer ${token}`
19-
}
20-
})
21-
const el = document.createElement("p")
22-
el.textContent = await response.text()
23-
document.getElementById("app")!.appendChild(el)
24-
button.disabled = false
25-
button.textContent = "Fetch Data"
26-
}
13+
async function fetchData() {
14+
const button = document.getElementById("fetch-data-button")! as HTMLButtonElement
15+
button.disabled = true
16+
button.textContent = "Fetching..."
17+
const response = await fetch("/hello", {
18+
headers: {
19+
"Authorization": `Bearer ${token}`
20+
}
21+
})
22+
const el = document.createElement("p")
23+
el.textContent = await response.text()
24+
document.getElementById("app")!.appendChild(el)
25+
button.disabled = false
26+
button.textContent = "Fetch Data"
27+
}
2728

28-
const app = document.getElementById("app")! as HTMLDivElement
29-
const hello = document.createElement("h1")
30-
hello.textContent = `Hello ${clerk.user.fullName}`
31-
app.appendChild(hello)
29+
const app = document.getElementById("app")! as HTMLDivElement
30+
const hello = document.createElement("h1")
31+
hello.textContent = `Hello ${clerk.user.fullName}`
32+
app.appendChild(hello)
3233

33-
const button = document.createElement("button")
34-
button.textContent = "Fetch Data"
35-
button.onclick = fetchData
36-
app.appendChild(button)
34+
const button = document.createElement("button")
35+
button.textContent = "Fetch Data"
36+
button.onclick = fetchData
37+
app.appendChild(button)
38+
}
3739
}
40+
41+
main().catch(console.error)

0 commit comments

Comments
 (0)
Please sign in to comment.