baumblatt / capacitor-firebase-auth

Capacitor Firebase Authentication Plugin
MIT License
261 stars 129 forks source link

There is a way to get the user info from the `plugin.signIn()` method? #123

Open nelson6e65 opened 3 years ago

nelson6e65 commented 3 years ago

I meant like #23 but before perform the web auth:

const result = await  plugin.signIn(providerId)`

const { email } = result.userInfo; // or something like this

So I can do something like this:


if (emailIsAlreadyRegistered(email) {
  showAlert('You already registered with password. Login to confirm your account')
  registerService.saveResultForLinking(result);
  await  plugin.signOut();
  await redirectToTheLoginPageWithFilled({email});
} else {
  const credential = auth.GoogleAuthProvider.credential(result.idToken);
  await auth().signInWithCredential(credential);
}

https://github.com/baumblatt/capacitor-firebase-auth/blob/73116ce400bf746ed2a5bbe82879ed5b030c6ce6/src/alternative/alternative.ts#L54

I want this because if I login with Google and it's already registered with email/password or Facebook for that email, the is credential replaced (https://stackoverflow.com/a/40768870/7242535).

The credentials are returned, but after sign in (https://github.com/baumblatt/capacitor-firebase-auth/issues/106#issuecomment-675671922) https://github.com/baumblatt/capacitor-firebase-auth/blob/73116ce400bf746ed2a5bbe82879ed5b030c6ce6/src/alternative/alternative.ts#L61

nelson6e65 commented 3 years ago

Or

if (!emailIsAlreadyRegistered(email)) {
  showAlert('You are not registered yet. Do you want to create an account?')
}
nelson6e65 commented 3 years ago

For Facebook, for example, I can just handle the auth/account-exists-with-different-credential error code from alternative facades, but this does not throw with Google provider if there is an already registered user with an @gmail.com email; it just gets replaced the credential.

baumblatt commented 3 years ago

Hi Nelson,

Please, keep in mind that you can do it just accessing the plugin direct with your own Javascript layer.

You can, just copy and paste the code to your App and customize it to your need.

Sorry about, but seems that this behaviour is very specific, we prefer to keep like default by Firebase.

Let me know if you need some help doing this or we can close this issue.

Best regards, Bernardo Baumblatt

nelson6e65 commented 3 years ago

Yes, I did it, splitting more the code to with an option to only login in the native layer to perform the check and then login in the JavaScript layer with Firebase, but I was not able to check the user details. 🥺 The result only gives me the token ID, no more info.

I was wondering if there is a way to access the email info before to perform the Firebase sign-in, but I think this is made internally by Firebase.

https://github.com/baumblatt/capacitor-firebase-auth/blob/73116ce400bf746ed2a5bbe82879ed5b030c6ce6/src/alternative/alternative.ts#L59-L61

nelson6e65 commented 3 years ago

I had to workaround.

My real issue was about credentials been replaced by Google, but you only need to verify the email when registering if you are using a direct password. So, the next time user sign-in, if the user uses Google the credential, it will be linked without replacements.

nelson6e65 commented 3 years ago

I was wondering if there is a way to access the email info before to perform the Firebase sign-in, but I think this is made internally by Firebase.

If this is not possible 🥺, then you can close this question.