However I cannot seem to get it to work using google-oauth2
If I try and use webAuth.signup instead of webAuth.authorize it says I need to pass an email and password.
When I use this code, the user is able to sign up no problem however the user_metadata is not storing the promo code the user signed up with therefore being charged full price.
Iām doing the above in a hosted login page. My code is as follows:
function loginWithGoogle() {
webAuth.authorize(
{
connection: 'google-oauth2',
},
function (err, authResult) {
webAuth.parseHash(
{ hash: window.location.hash },
function (err, authResult) {
let idToken = authResult.idToken;
if (err) {
return console.log(err);
}
webAuth.client.userInfo(token, function (err, user) {
var auth0Manage = new auth0.Management({
domain: 'DOMAIN',
token: idToken,
});
let metaData = { promo: '1234', date: date };
auth0Manage.patchUserMetadata(
user.sub,
metaData,
function (err, user) {
console.log(err);
});
});
});
});
}
This doesnāt seem to do anything though. I canāt get any Google userās to actually have User Metadata. Iāve tried playing with the audience that gets supplied to webAuth so that itās for the Management API but I canāt seem to make this work. Any ideas? Any help would be greatly appreciated.
Hi @Chris1337, thanks for sharing this charming solution, the authResult in my callback function is undefined, do you have any ideas?
Also seems like this is for popup authorize, does it work for none popup version?
Just like webAuth.authorize()?
Iād be very appreciate
I tested it with webAuth.authorize() and it doesnāt work for me. Am I doing something wrong or is your example @Chris1337 only for the popup version?
Hi @ArkasDev - I was having the same issue as you, while I have not tried the above solution, I did get something to work for me. Basically if you pass what you need as an extra query param in your /authorize endpoint, you can access that value from within a post login action and set the user metadata like this:
exports.onExecutePostLogin = async (event, api) => {
if (event.connection.strategy === event.connection.name && event.stats.logins_count === 1) {
api.user.setUserMetadata(āmobile_phoneā, event.request.query[āmobilePhoneā]);
}
};
For me it was mobile phone. Hope this helps