@@ -13,10 +13,11 @@ export function Web3AuthInnerProvider(params: PropsWithChildren<Web3AuthProvider
1313
1414 const [ isInitializing , setIsInitializing ] = useState < boolean > ( false ) ;
1515 const [ initError , setInitError ] = useState < Error | null > ( null ) ;
16- const [ isAuthenticated , setIsAuthenticated ] = useState < boolean > ( false ) ;
16+ const [ isConnected , setIsConnected ] = useState < boolean > ( false ) ;
1717 const [ provider , setProvider ] = useState < IProvider | null > ( null ) ;
1818 const [ isInitialized , setIsInitialized ] = useState < boolean > ( false ) ;
1919 const [ status , setStatus ] = useState < CONNECTOR_STATUS_TYPE | null > ( null ) ;
20+ const [ isMFAEnabled , setIsMFAEnabled ] = useState < boolean > ( false ) ;
2021
2122 const getPlugin = useCallback (
2223 ( name : string ) => {
@@ -29,7 +30,7 @@ export function Web3AuthInnerProvider(params: PropsWithChildren<Web3AuthProvider
2930 useEffect ( ( ) => {
3031 const resetHookState = ( ) => {
3132 setProvider ( null ) ;
32- setIsAuthenticated ( false ) ;
33+ setIsConnected ( false ) ;
3334 setStatus ( null ) ;
3435 } ;
3536
@@ -60,8 +61,6 @@ export function Web3AuthInnerProvider(params: PropsWithChildren<Web3AuthProvider
6061 } ;
6162 } , [ web3Auth ] ) ;
6263
63- // TODO: don't throw error in init, connect in v9
64-
6564 useEffect ( ( ) => {
6665 const notReadyListener = ( ) => setStatus ( CONNECTOR_STATUS . NOT_READY ) ;
6766 const readyListener = ( ) => {
@@ -73,13 +72,13 @@ export function Web3AuthInnerProvider(params: PropsWithChildren<Web3AuthProvider
7372 // we do this because of rehydration issues. status connected is fired first but web3auth sdk is not ready yet.
7473 if ( web3Auth . status === CONNECTOR_STATUS . CONNECTED ) {
7574 setIsInitialized ( true ) ;
76- setIsAuthenticated ( true ) ;
75+ setIsConnected ( true ) ;
7776 setProvider ( data . provider ) ;
7877 }
7978 } ;
8079 const disconnectedListener = ( ) => {
8180 setStatus ( web3Auth . status ) ;
82- setIsAuthenticated ( false ) ;
81+ setIsConnected ( false ) ;
8382 setProvider ( null ) ;
8483 } ;
8584
@@ -89,6 +88,11 @@ export function Web3AuthInnerProvider(params: PropsWithChildren<Web3AuthProvider
8988 const errorListener = ( ) => {
9089 setStatus ( CONNECTOR_STATUS . ERRORED ) ;
9190 } ;
91+
92+ const mfaEnabledListener = async ( isMFAEnabled : boolean ) => {
93+ setIsMFAEnabled ( isMFAEnabled ) ;
94+ } ;
95+
9296 if ( web3Auth ) {
9397 // web3Auth is initialized here.
9498 setStatus ( web3Auth . status ) ;
@@ -98,6 +102,7 @@ export function Web3AuthInnerProvider(params: PropsWithChildren<Web3AuthProvider
98102 web3Auth . on ( CONNECTOR_EVENTS . DISCONNECTED , disconnectedListener ) ;
99103 web3Auth . on ( CONNECTOR_EVENTS . CONNECTING , connectingListener ) ;
100104 web3Auth . on ( CONNECTOR_EVENTS . ERRORED , errorListener ) ;
105+ web3Auth . on ( CONNECTOR_EVENTS . MFA_ENABLED , mfaEnabledListener ) ;
101106 }
102107
103108 return ( ) => {
@@ -108,22 +113,24 @@ export function Web3AuthInnerProvider(params: PropsWithChildren<Web3AuthProvider
108113 web3Auth . off ( CONNECTOR_EVENTS . DISCONNECTED , disconnectedListener ) ;
109114 web3Auth . off ( CONNECTOR_EVENTS . CONNECTING , connectingListener ) ;
110115 web3Auth . off ( CONNECTOR_EVENTS . ERRORED , errorListener ) ;
116+ web3Auth . off ( CONNECTOR_EVENTS . MFA_ENABLED , mfaEnabledListener ) ;
111117 }
112118 } ;
113119 } , [ web3Auth ] ) ;
114120
115121 const value = useMemo ( ( ) => {
116122 return {
117123 web3Auth,
118- isAuthenticated ,
124+ isConnected ,
119125 isInitialized,
120126 provider,
121127 status,
122128 isInitializing,
123129 initError,
130+ isMFAEnabled,
124131 getPlugin,
125132 } ;
126- } , [ web3Auth , isAuthenticated , isInitialized , provider , status , getPlugin , isInitializing , initError ] ) ;
133+ } , [ web3Auth , isConnected , isInitialized , provider , status , getPlugin , isInitializing , initError , isMFAEnabled ] ) ;
127134
128135 return createElement ( Web3AuthInnerContext . Provider , { value } , children ) ;
129136}
0 commit comments