I am barely 2 months with React and currently I am having issues with integrating google signin to my application. This is what I have tried so far but it's still not working and I don't know what I am not doing right. Please any help would be appreciated.
I have attached both files for your review in case you might want to see where the issue is coming from. Thank you very much.
firebase file
import firebase from "firebase/app";
import "firebase/auth";
import "firebase/firestore";
const config = {
apiKey: "*** API KEY ***",
authDomain: "*** PROJECT ID ***.firebaseapp.com",
projectId: "*** PROJECT ID *** ",
storageBucket: "*** PROJECT ID ***.appspot.com",
messagingSenderId: "*** SENDER ID ***",
appId: "*** APP ID ***",
measurementId: "*** MEASUREMENT ID ***"
};
firebase.initializeApp(config); // this creates and initializes a Firebase instance.
export const auth = firebase.auth();
export const firestore = firebase.firestore();
//google auth utility
const provider = new firebase.auth.GoogleAuthProvider();
provider.setCustomParameters({prompt: 'select_account'}); //this always triggers the google pop-up for signin
export const signInWithGoogle = () => auth.signInWithPopup(provider);
export default firebase;
signin file
import React, { Component } from 'react'
import FormInput from '../formInput/FormInput'
import '../signIn/SignIn.css';
import CustomButton from '../customButton/CustomButton';
import signInWithGoogle from '../../firebase/firebase';
class SignIn extends Component {
constructor(props) {
super(props);
this.state = {
email: '',
password: '',
}
}
// onsubmit handler for the form
handleSubmit = (event) => {
event.preventDefault();
this.setState({ email: '', password: '' });
}
//onchange handler for the input
handleChange = (event) => {
const { value, name, } = event.target;
this.setState({ [name]: value })
}
render() {
return (
<div className="sign-in">
<h2>I already have an account</h2>
<span>Sign in with your email and password</span>
<form onSubmit={this.handleSubmit}>
<FormInput
type="email"
name="email"
value={this.state.email}
handleChange={this.handleChange}
label="email"
required
/>
<FormInput
type="password"
name="password"
value={this.state.password}
handleChange={this.handleChange}
label="password"
required
/>
<CustomButton type="submit">Sign In</CustomButton><br />
<CustomButton onclick={signInWithGoogle}>{''}Sign in with Google{''}</CustomButton>
</form>
</div>
)
}
}
export default SignIn;