Trying to get the social google login button working on a custom page. Based on the idea of the code written here https://www.wix.com/corvid/forum/community-discussion/solution-google-facebook-user-information-on-login
I am getting through the process in the iframe but not getting the message from the iframe to the client side code to create the user. Any inputs?
// For full API documentation, including code examples, visit https://wix.to/94BuAAs
import wixUsers from 'wix-users';
$w.onReady(function () {
});
//javascript page code for html iframe interaction
// when a message is received from the HTML Component
$w("#html1").onMessage((results) => {
let googleAccoutInfo = results.data;
console.log(googleAccoutInfo);
//string values for each item
let gUserId = results.data.userId;
let firstName = results.data.firstName;
let lastName = results.data.lastName;
let fullName = results.data.fullName;
let email = results.data.userEmail;
let password = results.data.idToken;
console.log(gUserId);
console.log(firstName);
console.log(lastName);
console.log(fullName);
console.log(email);
console.log(password);
wixUsers.register(email, password)
.then( (result) => {
let status = result.status; // "Active"
let user = result.user;
console.log("user created");
} );
});
Iframe code below:
<!doctype html>
<html>
<head>
<meta name="google-signin-client_id" content="XXXXXXXXXXXXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com">
<script>
</script>
</head>
<body>
<div id="my-signin2"></div>
<script>
function onSuccess(googleUser) {
var profile = googleUser.getBasicProfile();
let userId = profile.getId();
let fullName = profile.getName();
let firstName = profile.getGivenName();
let lastName = profile.getFamilyName();
let userEmail = profile.getEmail();
let idToken = googleUser.getAuthResponse().id_token;
window.parent.postMessage({userId: (userId), idToken: (idToken),fullName: (fullName), firstName: (firstName), lastName: (lastName),userEmail: (userEmail)}, "*");
}//end of googleSignIn
function onFailure(error) {
console.log(error);
}
//custom google button
function renderButton() {
gapi.signin2.render('my-signin2', {
'scope': 'profile email',
'width': 240,
'height': 50,
'longtitle': true,
'theme': 'dark',
'onsuccess': onSuccess,
'onfailure': onFailure
});
}
</script>
<script src="https://apis.google.com/js/platform.js?onload=renderButton" async defer></script>
</body>
</html>