File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
examples/getting-started/src/components Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change
1
+ import { DeviceFlowTokenExpiredError } from "@navigraph/app"
1
2
import { DeviceFlowParams } from "@navigraph/auth"
2
3
import { useCallback , useState } from "react"
3
4
import { useNavigraphAuth } from "../hooks/useNavigraphAuth"
4
5
5
6
export default function Auth ( ) {
7
+ const [ error , setError ] = useState < Error | null > ( null )
6
8
const [ params , setParams ] = useState < DeviceFlowParams | null > ( null )
7
9
const { user, isInitialized, signIn, signOut } = useNavigraphAuth ( )
8
10
9
- const handleSignIn = useCallback ( ( ) => signIn ( params => setParams ( params ) ) . finally ( ( ) => setParams ( null ) ) , [ signIn ] )
11
+ const handleSignIn = useCallback (
12
+ ( ) =>
13
+ signIn ( params => {
14
+ setParams ( params )
15
+ setError ( null )
16
+ } )
17
+ . catch ( err => setError ( err ) )
18
+ . finally ( ( ) => setParams ( null ) ) ,
19
+ [ signIn ] ,
20
+ )
10
21
11
22
const isLoginInProgress = ! ! params
12
23
@@ -22,6 +33,12 @@ export default function Auth() {
22
33
</ button >
23
34
) }
24
35
36
+ { error && (
37
+ < div className = "text-red-500" >
38
+ { error instanceof DeviceFlowTokenExpiredError ? "Session expired, try again!" : error . message }
39
+ </ div >
40
+ ) }
41
+
25
42
{ params ?. verification_uri_complete && ! user && (
26
43
< div className = "flex flex-col items-center gap-2" >
27
44
< a
You can’t perform that action at this time.
0 commit comments