diff --git a/src/containers/Auth/components/LoginWithGoogleButton.js b/src/containers/Auth/components/LoginWithGoogleButton.js index 68dbcfee8b709fe34a5fec314ed71d8be91d473e..95f7fa3090b3a2f71f4669fd7c032fbad768cc01 100644 --- a/src/containers/Auth/components/LoginWithGoogleButton.js +++ b/src/containers/Auth/components/LoginWithGoogleButton.js @@ -32,6 +32,13 @@ class LoginWithGoogleButton extends Component { this.stateStr = "koiu7869bvfvyu9KJ678HGtgybO8"; } + componentDidMount(){ + if(isElectron && isElectron()){ + // Initialize Firebase + const firebaseConfig = OAuthConfig.firebaseConfig; + firebase.initializeApp(firebaseConfig); + } + } doLogin = async () => { this.props.startSocialAuth(); this.props.displaySocialAuthMsg(true); @@ -41,29 +48,26 @@ class LoginWithGoogleButton extends Component { if(isElectron && isElectron()){ // firbase code start const id = new Date().getTime(); - - // Initialize Firebase - const firebaseConfig = OAuthConfig.firebaseConfig; - firebase.initializeApp(firebaseConfig); - await firebase.database().ref(`ot-auth-codes/${id}`).set({ authToken: 0, type:'google' }); const oneTimeCodeRef = firebase.database().ref(`ot-auth-codes/${id}`) oneTimeCodeRef.on('value', async snapshot => { const resData = snapshot.val(); - console.log('[DT] authToken::Res::',resData); - if(resData.authToken!==0){ - console.log('[DT] authToken::',resData.authToken); + console.log('[DT] authToken resData::',resData); + if(resData){ + if(resData.authToken!==0){ + console.log('[DT] authToken::',resData.authToken); - //remove firebase ref key after success authenticate - oneTimeCodeRef.remove() - .then(function() { - console.log("[DT] Remove succeeded.") - }) - .catch(function(error) { - console.log("[DT] Remove failed: " + error.message) - }); - - this.props.navigateToSignUp(resData.authToken, 'GOOGLEPLUS'); + //remove firebase ref key after success authenticate + oneTimeCodeRef.remove() + .then(function() { + console.log("[DT] Remove succeeded.") + }) + .catch(function(error) { + console.log("[DT] Remove failed: " + error.message) + }); + + this.props.navigateToSignUp(resData.authToken, 'GOOGLEPLUS'); + } } });