@@ -9,6 +9,7 @@ const Home: React.FC = () => {
99 const [ searchParams ] = useSearchParams ( ) ;
1010 const [ accountId , setAccountId ] = useState < string | null > ( null ) ;
1111 const [ signingUrl , setSigningUrl ] = useState < string | null > ( null ) ;
12+ const [ isSignedIn , setIsSignedIn ] = useState ( false ) ;
1213 const [ showModal , setShowModal ] = useState ( false ) ;
1314 const [ copyButtonText , setCopyButtonText ] = useState ( "Copy Sign URL" ) ;
1415
@@ -24,10 +25,24 @@ const Home: React.FC = () => {
2425 const account = client . getActiveAccount ( ) ;
2526 if ( account ) {
2627 setAccountId ( account . accountID ) ;
28+ setIsSignedIn ( true ) ;
29+ } else if ( accountID && signingURL ) {
30+ const isSignedIn = client . signIn ( accountID , signingURL ) ;
31+ if ( isSignedIn ) {
32+ setAccountId ( accountID ) ;
33+ setIsSignedIn ( true ) ;
34+ }
2735 }
2836 }
2937 } , [ searchParams , client ] ) ;
3038
39+ const handleSignOut = ( ) => {
40+ client . signOut ( ) ;
41+ setAccountId ( null ) ;
42+ setSigningUrl ( null ) ;
43+ setIsSignedIn ( false ) ;
44+ } ;
45+
3146 const onCopySignUrl = async ( ) => {
3247 if ( ! accountId || ! signingUrl ) {
3348 return ;
@@ -63,7 +78,10 @@ const Home: React.FC = () => {
6378 < h1 > { `User ${ accountId ? "detected" : "not detected" } ` } </ h1 >
6479 { accountId && < p > { `Account ID: ${ accountId } ` } </ p > }
6580 { signingUrl && < p > { `Signing URL: ${ signingUrl } ` } </ p > }
66- { accountId && signingUrl && < button onClick = { ( ) => setShowModal ( true ) } > Prepare Sign URL</ button > }
81+
82+ { ! isSignedIn && accountId && signingUrl && < button onClick = { ( ) => setShowModal ( true ) } > Prepare Sign URL</ button > }
83+ { isSignedIn && < button onClick = { handleSignOut } > Sign Out</ button > }
84+
6785 { showModal && (
6886 < div className = "modal-overlay" >
6987 < div className = "modal" >
0 commit comments