I am trying to implement login with google for web. I was able to do a basic implementation using JavaScript as shown in documentation. But I am not able to get onSignIn invoked when it is inside a react component.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="google-signin-client_id" content="xxx.apps.googleusercontent.com">
<script src="https://apis.google.com/js/platform.js" async defer></script>
<title>Dashboard</title>
</head>
<body>
<div id="app"></div>
</body>
component file - login.jsx
import React from 'react';
import PropTypes from "prop-types";
import styles from "../../../stylesheets/Layout/main.css";
import Logo from './logo';
class LoginPage extends React.Component {
onSignIn (googleUser) {
var profile = googleUser.getBasicProfile();
console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
console.log('Name: ' + profile.getName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is no
}
render() {
return (
<div className="centered">
<Logo className="login-logo" />
<div>
<div className="g-signin2" data-onsuccess={this.onSignIn}></div>
</div>
<div>
<p className="login-text">
Login with Google account
</p>
</div>
</div>
);
}
}
export default LoginPage;