diff --git a/web/cashtab/src/hooks/useWebAuthentication.js b/web/cashtab/src/hooks/useWebAuthentication.js --- a/web/cashtab/src/hooks/useWebAuthentication.js +++ b/web/cashtab/src/hooks/useWebAuthentication.js @@ -53,42 +53,45 @@ // Run Once useEffect(async () => { - // check to see if user device supports User Verification - const available = - await window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable(); - // only attempt to save/load authentication configuration from local storage if web authetication is supported - if (available) { - const authenticationConfig = - await loadAuthenticationConfigFromLocalStorage(); - // if this is the first time the app is run, then save the default config value - if (authenticationConfig === null) { - saveAuthenticationConfigToLocalStorage(); - } else { - setUserId(authenticationConfig.userId); - setCredentialId(authenticationConfig.credentialId); - setIsAuthenticationRequired( - authenticationConfig.isAuthenticationRequired, - ); - } - // signout the user when the app is not visible (minimize the browser, switch tab, switch app window) - const handleDocVisibilityChange = () => { - if (document.visibilityState !== 'visible') - setIsSignedIn(false); - }; - document.addEventListener( - 'visibilitychange', - handleDocVisibilityChange, - ); + if (window && window.PublicKeyCredential) { + // check to see if user device supports User Verification + const available = + await window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable(); - setIsWebAuthnSupported(available); - setLoading(false); - - return () => { - document.removeEventListener( + // only attempt to save/load authentication configuration from local storage if web authetication is supported + if (available) { + const authenticationConfig = + await loadAuthenticationConfigFromLocalStorage(); + // if this is the first time the app is run, then save the default config value + if (authenticationConfig === null) { + saveAuthenticationConfigToLocalStorage(); + } else { + setUserId(authenticationConfig.userId); + setCredentialId(authenticationConfig.credentialId); + setIsAuthenticationRequired( + authenticationConfig.isAuthenticationRequired, + ); + } + // signout the user when the app is not visible (minimize the browser, switch tab, switch app window) + const handleDocVisibilityChange = () => { + if (document.visibilityState !== 'visible') + setIsSignedIn(false); + }; + document.addEventListener( 'visibilitychange', handleDocVisibilityChange, ); - }; + + setIsWebAuthnSupported(available); + setLoading(false); + + return () => { + document.removeEventListener( + 'visibilitychange', + handleDocVisibilityChange, + ); + }; + } } }, []);