I have username/password login integration with Firebase in my web app and that is working great. I’m attempting to add ability to login with Facebook, and link accounts using this Rule:
https://github.com/auth0/rules/blob/master/rules/link-users-by-email.md
This works and does link and merge accounts in Auth0. However, it does not seem to delegate the token with firebase correctly on the app side… in my app.js I have this for delegating the token:
lock.on("authenticated", function(authResult) {
localStorage.setItem('id_token', authResult.idToken);
localStorage.setItem('access_token', authResult.accessToken);
// Set the options to retreive a firebase delegation token
var options = {
id_token : authResult.idToken,
api : 'firebase',
scope : 'openid name email',
target: auth0ClientId
};
// Make a call to the Auth0 '/delegate'
auth0.getDelegationToken(options, function(err, result) {
if(!err) {
// Exchange the delegate token for a Firebase auth token
firebase.auth().signInWithCustomToken(result.id_token).catch(function(error) {
console.log(error);
});
}
});
lock.getUserInfo(authResult.accessToken, function(error, profile) {
if (error) {
console.log(error);
return;
}
localStorage.setItem('profile', JSON.stringify(profile));
authUserInit();
});
I think maybe the timing between the Rule and the getDelegationToken is out of order - do I have to move that piece to the rule or can I trigger it to run again once the accounts have been linked?