@@ -34,6 +34,7 @@ export function Web3AuthInnerProvider(params: PropsWithChildren<Web3AuthProvider
3434 const [ isInitialized , setIsInitialized ] = useState < boolean > ( false ) ;
3535 const [ status , setStatus ] = useState < CONNECTOR_STATUS_TYPE | null > ( null ) ;
3636 const [ isMFAEnabled , setIsMFAEnabled ] = useState < boolean > ( false ) ;
37+ const [ isAuthorized , setIsAuthorized ] = useState < boolean > ( false ) ;
3738
3839 const getPlugin = useCallback (
3940 ( name : string ) => {
@@ -113,19 +114,30 @@ export function Web3AuthInnerProvider(params: PropsWithChildren<Web3AuthProvider
113114 const rehydrationErrorListener = ( ) => {
114115 setStatus ( web3Auth . status ) ;
115116 setIsConnected ( false ) ;
117+ setIsAuthorized ( false ) ;
116118 setProvider ( null ) ;
117119 } ;
118120
121+ const authorizedListener = ( ) => {
122+ setStatus ( web3Auth . status ) ;
123+ if ( web3Auth . status === CONNECTOR_STATUS . AUTHORIZED ) {
124+ setIsConnected ( true ) ;
125+ setIsAuthorized ( true ) ;
126+ }
127+ } ;
128+
119129 const mfaEnabledListener = ( isMFAEnabled : boolean ) => {
120130 if ( typeof isMFAEnabled === "boolean" ) setIsMFAEnabled ( isMFAEnabled ) ;
121131 } ;
122132
133+ // TODO: In strict mode, web3auth becomes null and .off throws an error sometimes.
123134 if ( web3Auth ) {
124135 // web3Auth is initialized here.
125136 setStatus ( web3Auth . status ) ;
126137 web3Auth . on ( CONNECTOR_EVENTS . NOT_READY , notReadyListener ) ;
127138 web3Auth . on ( CONNECTOR_EVENTS . READY , readyListener ) ;
128139 web3Auth . on ( CONNECTOR_EVENTS . CONNECTED , connectedListener ) ;
140+ web3Auth . on ( CONNECTOR_EVENTS . AUTHORIZED , authorizedListener ) ;
129141 web3Auth . on ( CONNECTOR_EVENTS . DISCONNECTED , disconnectedListener ) ;
130142 web3Auth . on ( CONNECTOR_EVENTS . CONNECTING , connectingListener ) ;
131143 web3Auth . on ( CONNECTOR_EVENTS . ERRORED , errorListener ) ;
@@ -143,6 +155,7 @@ export function Web3AuthInnerProvider(params: PropsWithChildren<Web3AuthProvider
143155 web3Auth . off ( CONNECTOR_EVENTS . ERRORED , errorListener ) ;
144156 web3Auth . off ( CONNECTOR_EVENTS . REHYDRATION_ERROR , rehydrationErrorListener ) ;
145157 web3Auth . off ( CONNECTOR_EVENTS . MFA_ENABLED , mfaEnabledListener ) ;
158+ web3Auth . off ( CONNECTOR_EVENTS . AUTHORIZED , authorizedListener ) ;
146159 }
147160 } ;
148161 } , [ web3Auth ] ) ;
@@ -161,6 +174,7 @@ export function Web3AuthInnerProvider(params: PropsWithChildren<Web3AuthProvider
161174 chainNamespace,
162175 getPlugin,
163176 setIsMFAEnabled,
177+ isAuthorized,
164178 } ;
165179 } , [
166180 web3Auth ,
@@ -175,6 +189,7 @@ export function Web3AuthInnerProvider(params: PropsWithChildren<Web3AuthProvider
175189 setIsMFAEnabled ,
176190 chainId ,
177191 chainNamespace ,
192+ isAuthorized ,
178193 ] ) ;
179194
180195 return createElement ( Web3AuthInnerContext . Provider , { value } , children ) ;
0 commit comments