Reputation: 2499
In my application I added some other providers like twitter or facebook for the sign-in process. With the twitter provider in one case, it does not fetch the email-address. I suspect, because twitter does not know the email of the user (possibly only logged in with a phone-number). Now how can I verify the user if there is no email to use <firebase.User>user.sendEmailVerification()
?
I can offer some code for the sign-in process of my app using Angular.
public async loginWithDifferentProvider(provider: 'Google' | 'Facebook' | 'Twitter'): Promise<void | string | boolean> {
let auth;
switch (provider) {
case 'Google':
auth = new firebase.auth.GoogleAuthProvider();
break;
case 'Facebook':
auth = new firebase.auth.FacebookAuthProvider();
break;
case 'Twitter':
auth = new firebase.auth.TwitterAuthProvider();
break;
}
try {
await this.oAuthLogin(auth);
return this.router.navigate(['/stories']);
} catch (e) {
this.notify.danger(e.message);
}
}
private async oAuthLogin(provider) {
const loginMetaData: UserCredential = await this.auth.firebaseAuthInstance.signInWithPopup(provider);
const user: firebase.User = loginMetaData.user;
let photoUrl: string;
switch (loginMetaData.credential.providerId) {
case 'twitter.com':
photoUrl = loginMetaData.user.photoURL.replace('_normal', '');
break;
case 'facebook.com':
const id = loginMetaData.additionalUserInfo.profile['id'];
photoUrl = `https://graph.facebook.com/${id}/picture?type=large`;
break;
}
return this.userService.createUserFromOtherProvider(user, photoUrl); // creates firestore doc. of the user
}
Upvotes: 0
Views: 29
Reputation: 598728
The sendEmailVerification
method is specifically made to verify the user's email address. If there is no email address in the user's profile, it's meaningless to call the method.
You could detect that their profile doesn't have an email address, and then ask the user for their email address. You can then set the email address in their Firebase Authentication profile and call sendEmailVerification
after that to verify it.
Upvotes: 1