1
1
import { Clerk } from '@clerk/clerk-js'
2
2
import './style.css'
3
3
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 ( )
6
7
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 ( )
11
12
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
+ }
27
28
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 )
32
33
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
+ }
37
39
}
40
+
41
+ main ( ) . catch ( console . error )
0 commit comments