Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(authentication): add fetchSignInMethodsForEmail(...) method #593

Merged
merged 4 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/khaki-seals-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@capacitor-firebase/authentication': minor
---

feat: add `fetchSignInMethodsForEmail(...)` method
226 changes: 103 additions & 123 deletions packages/authentication/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,17 @@ const confirmPasswordReset = async () => {
});
};

const deleteUser = async () => {
await FirebaseAuthentication.deleteUser();
};

const fetchSignInMethodsForEmail = async () => {
const result = await FirebaseAuthentication.fetchSignInMethodsForEmail({
email: 'mail@example.tld',
});
return result.signInMethods;
};

const getCurrentUser = async () => {
const result = await FirebaseAuthentication.getCurrentUser();
return result.user;
Expand Down Expand Up @@ -377,129 +388,65 @@ const useEmulator = async () => {

<docgen-index>

- [@capacitor-firebase/authentication](#capacitor-firebaseauthentication)
- [Installation](#installation)
- [Configuration](#configuration)
- [Examples](#examples)
- [FAQ](#faq)
- [Firebase JavaScript SDK](#firebase-javascript-sdk)
- [Demo](#demo)
- [Starter Templates](#starter-templates)
- [Usage](#usage)
- [API](#api)
- [applyActionCode(...)](#applyactioncode)
- [confirmPasswordReset(...)](#confirmpasswordreset)
- [confirmVerificationCode(...)](#confirmverificationcode)
- [createUserWithEmailAndPassword(...)](#createuserwithemailandpassword)
- [deleteUser()](#deleteuser)
- [getCurrentUser()](#getcurrentuser)
- [getIdToken(...)](#getidtoken)
- [getRedirectResult()](#getredirectresult)
- [getTenantId()](#gettenantid)
- [isSignInWithEmailLink(...)](#issigninwithemaillink)
- [linkWithApple(...)](#linkwithapple)
- [linkWithEmailAndPassword(...)](#linkwithemailandpassword)
- [linkWithEmailLink(...)](#linkwithemaillink)
- [linkWithFacebook(...)](#linkwithfacebook)
- [linkWithGameCenter(...)](#linkwithgamecenter)
- [linkWithGithub(...)](#linkwithgithub)
- [linkWithGoogle(...)](#linkwithgoogle)
- [linkWithMicrosoft(...)](#linkwithmicrosoft)
- [linkWithPhoneNumber(...)](#linkwithphonenumber)
- [linkWithPlayGames(...)](#linkwithplaygames)
- [linkWithTwitter(...)](#linkwithtwitter)
- [linkWithYahoo(...)](#linkwithyahoo)
- [reload()](#reload)
- [sendEmailVerification()](#sendemailverification)
- [sendPasswordResetEmail(...)](#sendpasswordresetemail)
- [sendSignInLinkToEmail(...)](#sendsigninlinktoemail)
- [setLanguageCode(...)](#setlanguagecode)
- [setPersistence(...)](#setpersistence)
- [setTenantId(...)](#settenantid)
- [signInAnonymously()](#signinanonymously)
- [signInWithApple(...)](#signinwithapple)
- [signInWithCustomToken(...)](#signinwithcustomtoken)
- [signInWithEmailAndPassword(...)](#signinwithemailandpassword)
- [signInWithEmailLink(...)](#signinwithemaillink)
- [signInWithFacebook(...)](#signinwithfacebook)
- [signInWithGameCenter(...)](#signinwithgamecenter)
- [signInWithGithub(...)](#signinwithgithub)
- [signInWithGoogle(...)](#signinwithgoogle)
- [signInWithMicrosoft(...)](#signinwithmicrosoft)
- [signInWithPhoneNumber(...)](#signinwithphonenumber)
- [signInWithPlayGames(...)](#signinwithplaygames)
- [signInWithTwitter(...)](#signinwithtwitter)
- [signInWithYahoo(...)](#signinwithyahoo)
- [signOut()](#signout)
- [unlink(...)](#unlink)
- [updateEmail(...)](#updateemail)
- [updatePassword(...)](#updatepassword)
- [updateProfile(...)](#updateprofile)
- [useAppLanguage()](#useapplanguage)
- [useEmulator(...)](#useemulator)
- [addListener('authStateChange', ...)](#addlistenerauthstatechange-)
- [addListener('phoneVerificationCompleted', ...)](#addlistenerphoneverificationcompleted-)
- [addListener('phoneVerificationFailed', ...)](#addlistenerphoneverificationfailed-)
- [addListener('phoneCodeSent', ...)](#addlistenerphonecodesent-)
- [removeAllListeners()](#removealllisteners)
- [Interfaces](#interfaces)
- [ApplyActionCodeOptions](#applyactioncodeoptions)
- [ConfirmPasswordResetOptions](#confirmpasswordresetoptions)
- [SignInResult](#signinresult)
- [User](#user)
- [UserMetadata](#usermetadata)
- [UserInfo](#userinfo)
- [AuthCredential](#authcredential)
- [AdditionalUserInfo](#additionaluserinfo)
- [ConfirmVerificationCodeOptions](#confirmverificationcodeoptions)
- [CreateUserWithEmailAndPasswordOptions](#createuserwithemailandpasswordoptions)
- [GetCurrentUserResult](#getcurrentuserresult)
- [GetIdTokenResult](#getidtokenresult)
- [GetIdTokenOptions](#getidtokenoptions)
- [GetTenantIdResult](#gettenantidresult)
- [IsSignInWithEmailLinkResult](#issigninwithemaillinkresult)
- [IsSignInWithEmailLinkOptions](#issigninwithemaillinkoptions)
- [SignInWithOAuthOptions](#signinwithoauthoptions)
- [SignInCustomParameter](#signincustomparameter)
- [LinkWithEmailAndPasswordOptions](#linkwithemailandpasswordoptions)
- [LinkWithEmailLinkOptions](#linkwithemaillinkoptions)
- [SignInWithPhoneNumberOptions](#signinwithphonenumberoptions)
- [SendPasswordResetEmailOptions](#sendpasswordresetemailoptions)
- [SendSignInLinkToEmailOptions](#sendsigninlinktoemailoptions)
- [ActionCodeSettings](#actioncodesettings)
- [SetLanguageCodeOptions](#setlanguagecodeoptions)
- [SetPersistenceOptions](#setpersistenceoptions)
- [Persistence](#persistence)
- [SetTenantIdOptions](#settenantidoptions)
- [SignInWithCustomTokenOptions](#signinwithcustomtokenoptions)
- [SignInWithEmailAndPasswordOptions](#signinwithemailandpasswordoptions)
- [SignInWithEmailLinkOptions](#signinwithemaillinkoptions)
- [SignInOptions](#signinoptions)
- [UnlinkResult](#unlinkresult)
- [UnlinkOptions](#unlinkoptions)
- [UpdateEmailOptions](#updateemailoptions)
- [UpdatePasswordOptions](#updatepasswordoptions)
- [UpdateProfileOptions](#updateprofileoptions)
- [UseEmulatorOptions](#useemulatoroptions)
- [PluginListenerHandle](#pluginlistenerhandle)
- [AuthStateChange](#authstatechange)
- [PhoneVerificationCompletedEvent](#phoneverificationcompletedevent)
- [PhoneVerificationFailedEvent](#phoneverificationfailedevent)
- [PhoneCodeSentEvent](#phonecodesentevent)
- [Type Aliases](#type-aliases)
- [LinkWithOAuthOptions](#linkwithoauthoptions)
- [LinkResult](#linkresult)
- [LinkWithPhoneNumberOptions](#linkwithphonenumberoptions)
- [AuthStateChangeListener](#authstatechangelistener)
- [PhoneVerificationCompletedListener](#phoneverificationcompletedlistener)
- [PhoneVerificationFailedListener](#phoneverificationfailedlistener)
- [PhoneCodeSentListener](#phonecodesentlistener)
- [Enums](#enums)
- [Persistence](#persistence-1)
- [ProviderId](#providerid)
- [Changelog](#changelog)
- [License](#license)
- [Credits](#credits)
* [`applyActionCode(...)`](#applyactioncode)
* [`confirmPasswordReset(...)`](#confirmpasswordreset)
* [`confirmVerificationCode(...)`](#confirmverificationcode)
* [`createUserWithEmailAndPassword(...)`](#createuserwithemailandpassword)
* [`deleteUser()`](#deleteuser)
* [`fetchSignInMethodsForEmail(...)`](#fetchsigninmethodsforemail)
* [`getCurrentUser()`](#getcurrentuser)
* [`getIdToken(...)`](#getidtoken)
* [`getRedirectResult()`](#getredirectresult)
* [`getTenantId()`](#gettenantid)
* [`isSignInWithEmailLink(...)`](#issigninwithemaillink)
* [`linkWithApple(...)`](#linkwithapple)
* [`linkWithEmailAndPassword(...)`](#linkwithemailandpassword)
* [`linkWithEmailLink(...)`](#linkwithemaillink)
* [`linkWithFacebook(...)`](#linkwithfacebook)
* [`linkWithGameCenter(...)`](#linkwithgamecenter)
* [`linkWithGithub(...)`](#linkwithgithub)
* [`linkWithGoogle(...)`](#linkwithgoogle)
* [`linkWithMicrosoft(...)`](#linkwithmicrosoft)
* [`linkWithPhoneNumber(...)`](#linkwithphonenumber)
* [`linkWithPlayGames(...)`](#linkwithplaygames)
* [`linkWithTwitter(...)`](#linkwithtwitter)
* [`linkWithYahoo(...)`](#linkwithyahoo)
* [`reload()`](#reload)
* [`sendEmailVerification()`](#sendemailverification)
* [`sendPasswordResetEmail(...)`](#sendpasswordresetemail)
* [`sendSignInLinkToEmail(...)`](#sendsigninlinktoemail)
* [`setLanguageCode(...)`](#setlanguagecode)
* [`setPersistence(...)`](#setpersistence)
* [`setTenantId(...)`](#settenantid)
* [`signInAnonymously()`](#signinanonymously)
* [`signInWithApple(...)`](#signinwithapple)
* [`signInWithCustomToken(...)`](#signinwithcustomtoken)
* [`signInWithEmailAndPassword(...)`](#signinwithemailandpassword)
* [`signInWithEmailLink(...)`](#signinwithemaillink)
* [`signInWithFacebook(...)`](#signinwithfacebook)
* [`signInWithGameCenter(...)`](#signinwithgamecenter)
* [`signInWithGithub(...)`](#signinwithgithub)
* [`signInWithGoogle(...)`](#signinwithgoogle)
* [`signInWithMicrosoft(...)`](#signinwithmicrosoft)
* [`signInWithPhoneNumber(...)`](#signinwithphonenumber)
* [`signInWithPlayGames(...)`](#signinwithplaygames)
* [`signInWithTwitter(...)`](#signinwithtwitter)
* [`signInWithYahoo(...)`](#signinwithyahoo)
* [`signOut()`](#signout)
* [`unlink(...)`](#unlink)
* [`updateEmail(...)`](#updateemail)
* [`updatePassword(...)`](#updatepassword)
* [`updateProfile(...)`](#updateprofile)
* [`useAppLanguage()`](#useapplanguage)
* [`useEmulator(...)`](#useemulator)
* [`addListener('authStateChange', ...)`](#addlistenerauthstatechange)
* [`addListener('phoneVerificationCompleted', ...)`](#addlistenerphoneverificationcompleted)
* [`addListener('phoneVerificationFailed', ...)`](#addlistenerphoneverificationfailed)
* [`addListener('phoneCodeSent', ...)`](#addlistenerphonecodesent)
* [`removeAllListeners()`](#removealllisteners)
* [Interfaces](#interfaces)
* [Type Aliases](#type-aliases)
* [Enums](#enums)

</docgen-index>

Expand Down Expand Up @@ -592,6 +539,25 @@ Deletes and signs out the user.
--------------------


### fetchSignInMethodsForEmail(...)

```typescript
fetchSignInMethodsForEmail(options: FetchSignInMethodsForEmailOptions) => Promise<FetchSignInMethodsForEmailResult>
```

Fetches the sign-in methods for an email address.

| Param | Type |
| ------------- | ----------------------------------------------------------------------------------------------- |
| **`options`** | <code><a href="#fetchsigninmethodsforemailoptions">FetchSignInMethodsForEmailOptions</a></code> |

**Returns:** <code>Promise&lt;<a href="#fetchsigninmethodsforemailresult">FetchSignInMethodsForEmailResult</a>&gt;</code>

**Since:** 6.0.0

--------------------


### getCurrentUser()

```typescript
Expand Down Expand Up @@ -1658,6 +1624,20 @@ Remove all listeners for this plugin.
| **`password`** | <code>string</code> | 0.2.2 |


#### FetchSignInMethodsForEmailResult

| Prop | Type | Description | Since |
| ------------------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`signInMethods`** | <code>string[]</code> | The sign-in methods for the specified email address. This list is empty when [Email Enumeration Protection](https://cloud.google.com/identity-platform/docs/admin/email-enumeration-protection) is enabled, irrespective of the number of authentication methods available for the given email. | 6.0.0 |


#### FetchSignInMethodsForEmailOptions

| Prop | Type | Description | Since |
| ----------- | ------------------- | ------------------------- | ----- |
| **`email`** | <code>string</code> | The user's email address. | 6.0.0 |


#### GetCurrentUserResult

| Prop | Type | Description | Since |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import io.capawesome.capacitorjs.plugins.firebase.authentication.classes.SignInOptions;
import io.capawesome.capacitorjs.plugins.firebase.authentication.classes.SignInResult;
import io.capawesome.capacitorjs.plugins.firebase.authentication.classes.SignInWithPhoneNumberOptions;
import io.capawesome.capacitorjs.plugins.firebase.authentication.classes.options.FetchSignInMethodsForEmailOptions;
import io.capawesome.capacitorjs.plugins.firebase.authentication.classes.results.FetchSignInMethodsForEmailResult;
import io.capawesome.capacitorjs.plugins.firebase.authentication.handlers.AppleAuthProviderHandler;
import io.capawesome.capacitorjs.plugins.firebase.authentication.handlers.FacebookAuthProviderHandler;
import io.capawesome.capacitorjs.plugins.firebase.authentication.handlers.GoogleAuthProviderHandler;
Expand Down Expand Up @@ -135,6 +137,25 @@ public void deleteUser(FirebaseUser user, @NonNull Runnable callback) {
);
}

public void fetchSignInMethodsForEmail(FetchSignInMethodsForEmailOptions options, @NonNull final ResultCallback resultCallback) {
String email = options.getEmail();

getFirebaseAuthInstance()
.fetchSignInMethodsForEmail(email)
.addOnCompleteListener(
task -> {
if (task.isSuccessful()) {
List<String> signInMethods = task.getResult().getSignInMethods();
FetchSignInMethodsForEmailResult result = new FetchSignInMethodsForEmailResult(signInMethods);
resultCallback.success(result);
} else {
Exception exception = task.getException();
resultCallback.error(exception);
}
}
);
}

@Nullable
public FirebaseUser getCurrentUser() {
return getFirebaseAuthInstance().getCurrentUser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.capawesome.capacitorjs.plugins.firebase.authentication.classes.PhoneVerificationCompletedEvent;
import io.capawesome.capacitorjs.plugins.firebase.authentication.classes.SignInResult;
import io.capawesome.capacitorjs.plugins.firebase.authentication.classes.SignInWithPhoneNumberOptions;
import io.capawesome.capacitorjs.plugins.firebase.authentication.classes.options.FetchSignInMethodsForEmailOptions;
import io.capawesome.capacitorjs.plugins.firebase.authentication.handlers.FacebookAuthProviderHandler;
import io.capawesome.capacitorjs.plugins.firebase.authentication.interfaces.Result;
import io.capawesome.capacitorjs.plugins.firebase.authentication.interfaces.ResultCallback;
Expand Down Expand Up @@ -166,6 +167,40 @@ public void deleteUser(PluginCall call) {
}
}

@PluginMethod
public void fetchSignInMethodsForEmail(PluginCall call) {
try {
String email = call.getString("email");
if (email == null) {
call.reject(ERROR_EMAIL_MISSING);
return;
}

FetchSignInMethodsForEmailOptions options = new FetchSignInMethodsForEmailOptions(email);

implementation.fetchSignInMethodsForEmail(
options,
new ResultCallback() {
@Override
public void success(Result result) {
call.resolve(result.toJSObject());
}

@Override
public void error(Exception exception) {
Logger.error(TAG, exception.getMessage(), exception);
String code = FirebaseAuthenticationHelper.createErrorCode(exception);
call.reject(exception.getMessage(), code);
}
}
);
} catch (Exception exception) {
Logger.error(TAG, exception.getMessage(), exception);
String code = FirebaseAuthenticationHelper.createErrorCode(exception);
call.reject(exception.getMessage(), code);
}
}

@PluginMethod
public void getCurrentUser(PluginCall call) {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.capawesome.capacitorjs.plugins.firebase.authentication.classes.options;

import androidx.annotation.NonNull;

public class FetchSignInMethodsForEmailOptions {

@NonNull
private String email;

public FetchSignInMethodsForEmailOptions(@NonNull String email) {
this.email = email;
}

@NonNull
public String getEmail() {
return this.email;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.capawesome.capacitorjs.plugins.firebase.authentication.classes.results;

import com.getcapacitor.JSArray;
import com.getcapacitor.JSObject;
import io.capawesome.capacitorjs.plugins.firebase.authentication.interfaces.Result;
import java.util.List;

public class FetchSignInMethodsForEmailResult implements Result {

private List<String> signInMethods;

public FetchSignInMethodsForEmailResult(List<String> signInMethods) {
this.signInMethods = signInMethods;
}

public JSObject toJSObject() {
JSArray signInMethodsResult = new JSArray();
for (String signInMethod : signInMethods) {
signInMethodsResult.put(signInMethod);
}

JSObject result = new JSObject();
result.put("signInMethods", signInMethodsResult);
return result;
}
}
Loading
Loading