Skip to content

Commit 69e5768

Browse files
authored
feat(authentication): add fetchSignInMethodsForEmail(...) method (#593)
* feat(authentication): add `fetchSignInMethodsForEmail(...)` method * rename prop to `signInMethods` * fix android * wip
1 parent 12e86c8 commit 69e5768

14 files changed

+346
-123
lines changed

.changeset/khaki-seals-buy.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@capacitor-firebase/authentication': minor
3+
---
4+
5+
feat: add `fetchSignInMethodsForEmail(...)` method

packages/authentication/README.md

+103-123
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,17 @@ const confirmPasswordReset = async () => {
156156
});
157157
};
158158

159+
const deleteUser = async () => {
160+
await FirebaseAuthentication.deleteUser();
161+
};
162+
163+
const fetchSignInMethodsForEmail = async () => {
164+
const result = await FirebaseAuthentication.fetchSignInMethodsForEmail({
165+
166+
});
167+
return result.signInMethods;
168+
};
169+
159170
const getCurrentUser = async () => {
160171
const result = await FirebaseAuthentication.getCurrentUser();
161172
return result.user;
@@ -377,129 +388,65 @@ const useEmulator = async () => {
377388

378389
<docgen-index>
379390

380-
- [@capacitor-firebase/authentication](#capacitor-firebaseauthentication)
381-
- [Installation](#installation)
382-
- [Configuration](#configuration)
383-
- [Examples](#examples)
384-
- [FAQ](#faq)
385-
- [Firebase JavaScript SDK](#firebase-javascript-sdk)
386-
- [Demo](#demo)
387-
- [Starter Templates](#starter-templates)
388-
- [Usage](#usage)
389-
- [API](#api)
390-
- [applyActionCode(...)](#applyactioncode)
391-
- [confirmPasswordReset(...)](#confirmpasswordreset)
392-
- [confirmVerificationCode(...)](#confirmverificationcode)
393-
- [createUserWithEmailAndPassword(...)](#createuserwithemailandpassword)
394-
- [deleteUser()](#deleteuser)
395-
- [getCurrentUser()](#getcurrentuser)
396-
- [getIdToken(...)](#getidtoken)
397-
- [getRedirectResult()](#getredirectresult)
398-
- [getTenantId()](#gettenantid)
399-
- [isSignInWithEmailLink(...)](#issigninwithemaillink)
400-
- [linkWithApple(...)](#linkwithapple)
401-
- [linkWithEmailAndPassword(...)](#linkwithemailandpassword)
402-
- [linkWithEmailLink(...)](#linkwithemaillink)
403-
- [linkWithFacebook(...)](#linkwithfacebook)
404-
- [linkWithGameCenter(...)](#linkwithgamecenter)
405-
- [linkWithGithub(...)](#linkwithgithub)
406-
- [linkWithGoogle(...)](#linkwithgoogle)
407-
- [linkWithMicrosoft(...)](#linkwithmicrosoft)
408-
- [linkWithPhoneNumber(...)](#linkwithphonenumber)
409-
- [linkWithPlayGames(...)](#linkwithplaygames)
410-
- [linkWithTwitter(...)](#linkwithtwitter)
411-
- [linkWithYahoo(...)](#linkwithyahoo)
412-
- [reload()](#reload)
413-
- [sendEmailVerification()](#sendemailverification)
414-
- [sendPasswordResetEmail(...)](#sendpasswordresetemail)
415-
- [sendSignInLinkToEmail(...)](#sendsigninlinktoemail)
416-
- [setLanguageCode(...)](#setlanguagecode)
417-
- [setPersistence(...)](#setpersistence)
418-
- [setTenantId(...)](#settenantid)
419-
- [signInAnonymously()](#signinanonymously)
420-
- [signInWithApple(...)](#signinwithapple)
421-
- [signInWithCustomToken(...)](#signinwithcustomtoken)
422-
- [signInWithEmailAndPassword(...)](#signinwithemailandpassword)
423-
- [signInWithEmailLink(...)](#signinwithemaillink)
424-
- [signInWithFacebook(...)](#signinwithfacebook)
425-
- [signInWithGameCenter(...)](#signinwithgamecenter)
426-
- [signInWithGithub(...)](#signinwithgithub)
427-
- [signInWithGoogle(...)](#signinwithgoogle)
428-
- [signInWithMicrosoft(...)](#signinwithmicrosoft)
429-
- [signInWithPhoneNumber(...)](#signinwithphonenumber)
430-
- [signInWithPlayGames(...)](#signinwithplaygames)
431-
- [signInWithTwitter(...)](#signinwithtwitter)
432-
- [signInWithYahoo(...)](#signinwithyahoo)
433-
- [signOut()](#signout)
434-
- [unlink(...)](#unlink)
435-
- [updateEmail(...)](#updateemail)
436-
- [updatePassword(...)](#updatepassword)
437-
- [updateProfile(...)](#updateprofile)
438-
- [useAppLanguage()](#useapplanguage)
439-
- [useEmulator(...)](#useemulator)
440-
- [addListener('authStateChange', ...)](#addlistenerauthstatechange-)
441-
- [addListener('phoneVerificationCompleted', ...)](#addlistenerphoneverificationcompleted-)
442-
- [addListener('phoneVerificationFailed', ...)](#addlistenerphoneverificationfailed-)
443-
- [addListener('phoneCodeSent', ...)](#addlistenerphonecodesent-)
444-
- [removeAllListeners()](#removealllisteners)
445-
- [Interfaces](#interfaces)
446-
- [ApplyActionCodeOptions](#applyactioncodeoptions)
447-
- [ConfirmPasswordResetOptions](#confirmpasswordresetoptions)
448-
- [SignInResult](#signinresult)
449-
- [User](#user)
450-
- [UserMetadata](#usermetadata)
451-
- [UserInfo](#userinfo)
452-
- [AuthCredential](#authcredential)
453-
- [AdditionalUserInfo](#additionaluserinfo)
454-
- [ConfirmVerificationCodeOptions](#confirmverificationcodeoptions)
455-
- [CreateUserWithEmailAndPasswordOptions](#createuserwithemailandpasswordoptions)
456-
- [GetCurrentUserResult](#getcurrentuserresult)
457-
- [GetIdTokenResult](#getidtokenresult)
458-
- [GetIdTokenOptions](#getidtokenoptions)
459-
- [GetTenantIdResult](#gettenantidresult)
460-
- [IsSignInWithEmailLinkResult](#issigninwithemaillinkresult)
461-
- [IsSignInWithEmailLinkOptions](#issigninwithemaillinkoptions)
462-
- [SignInWithOAuthOptions](#signinwithoauthoptions)
463-
- [SignInCustomParameter](#signincustomparameter)
464-
- [LinkWithEmailAndPasswordOptions](#linkwithemailandpasswordoptions)
465-
- [LinkWithEmailLinkOptions](#linkwithemaillinkoptions)
466-
- [SignInWithPhoneNumberOptions](#signinwithphonenumberoptions)
467-
- [SendPasswordResetEmailOptions](#sendpasswordresetemailoptions)
468-
- [SendSignInLinkToEmailOptions](#sendsigninlinktoemailoptions)
469-
- [ActionCodeSettings](#actioncodesettings)
470-
- [SetLanguageCodeOptions](#setlanguagecodeoptions)
471-
- [SetPersistenceOptions](#setpersistenceoptions)
472-
- [Persistence](#persistence)
473-
- [SetTenantIdOptions](#settenantidoptions)
474-
- [SignInWithCustomTokenOptions](#signinwithcustomtokenoptions)
475-
- [SignInWithEmailAndPasswordOptions](#signinwithemailandpasswordoptions)
476-
- [SignInWithEmailLinkOptions](#signinwithemaillinkoptions)
477-
- [SignInOptions](#signinoptions)
478-
- [UnlinkResult](#unlinkresult)
479-
- [UnlinkOptions](#unlinkoptions)
480-
- [UpdateEmailOptions](#updateemailoptions)
481-
- [UpdatePasswordOptions](#updatepasswordoptions)
482-
- [UpdateProfileOptions](#updateprofileoptions)
483-
- [UseEmulatorOptions](#useemulatoroptions)
484-
- [PluginListenerHandle](#pluginlistenerhandle)
485-
- [AuthStateChange](#authstatechange)
486-
- [PhoneVerificationCompletedEvent](#phoneverificationcompletedevent)
487-
- [PhoneVerificationFailedEvent](#phoneverificationfailedevent)
488-
- [PhoneCodeSentEvent](#phonecodesentevent)
489-
- [Type Aliases](#type-aliases)
490-
- [LinkWithOAuthOptions](#linkwithoauthoptions)
491-
- [LinkResult](#linkresult)
492-
- [LinkWithPhoneNumberOptions](#linkwithphonenumberoptions)
493-
- [AuthStateChangeListener](#authstatechangelistener)
494-
- [PhoneVerificationCompletedListener](#phoneverificationcompletedlistener)
495-
- [PhoneVerificationFailedListener](#phoneverificationfailedlistener)
496-
- [PhoneCodeSentListener](#phonecodesentlistener)
497-
- [Enums](#enums)
498-
- [Persistence](#persistence-1)
499-
- [ProviderId](#providerid)
500-
- [Changelog](#changelog)
501-
- [License](#license)
502-
- [Credits](#credits)
391+
* [`applyActionCode(...)`](#applyactioncode)
392+
* [`confirmPasswordReset(...)`](#confirmpasswordreset)
393+
* [`confirmVerificationCode(...)`](#confirmverificationcode)
394+
* [`createUserWithEmailAndPassword(...)`](#createuserwithemailandpassword)
395+
* [`deleteUser()`](#deleteuser)
396+
* [`fetchSignInMethodsForEmail(...)`](#fetchsigninmethodsforemail)
397+
* [`getCurrentUser()`](#getcurrentuser)
398+
* [`getIdToken(...)`](#getidtoken)
399+
* [`getRedirectResult()`](#getredirectresult)
400+
* [`getTenantId()`](#gettenantid)
401+
* [`isSignInWithEmailLink(...)`](#issigninwithemaillink)
402+
* [`linkWithApple(...)`](#linkwithapple)
403+
* [`linkWithEmailAndPassword(...)`](#linkwithemailandpassword)
404+
* [`linkWithEmailLink(...)`](#linkwithemaillink)
405+
* [`linkWithFacebook(...)`](#linkwithfacebook)
406+
* [`linkWithGameCenter(...)`](#linkwithgamecenter)
407+
* [`linkWithGithub(...)`](#linkwithgithub)
408+
* [`linkWithGoogle(...)`](#linkwithgoogle)
409+
* [`linkWithMicrosoft(...)`](#linkwithmicrosoft)
410+
* [`linkWithPhoneNumber(...)`](#linkwithphonenumber)
411+
* [`linkWithPlayGames(...)`](#linkwithplaygames)
412+
* [`linkWithTwitter(...)`](#linkwithtwitter)
413+
* [`linkWithYahoo(...)`](#linkwithyahoo)
414+
* [`reload()`](#reload)
415+
* [`sendEmailVerification()`](#sendemailverification)
416+
* [`sendPasswordResetEmail(...)`](#sendpasswordresetemail)
417+
* [`sendSignInLinkToEmail(...)`](#sendsigninlinktoemail)
418+
* [`setLanguageCode(...)`](#setlanguagecode)
419+
* [`setPersistence(...)`](#setpersistence)
420+
* [`setTenantId(...)`](#settenantid)
421+
* [`signInAnonymously()`](#signinanonymously)
422+
* [`signInWithApple(...)`](#signinwithapple)
423+
* [`signInWithCustomToken(...)`](#signinwithcustomtoken)
424+
* [`signInWithEmailAndPassword(...)`](#signinwithemailandpassword)
425+
* [`signInWithEmailLink(...)`](#signinwithemaillink)
426+
* [`signInWithFacebook(...)`](#signinwithfacebook)
427+
* [`signInWithGameCenter(...)`](#signinwithgamecenter)
428+
* [`signInWithGithub(...)`](#signinwithgithub)
429+
* [`signInWithGoogle(...)`](#signinwithgoogle)
430+
* [`signInWithMicrosoft(...)`](#signinwithmicrosoft)
431+
* [`signInWithPhoneNumber(...)`](#signinwithphonenumber)
432+
* [`signInWithPlayGames(...)`](#signinwithplaygames)
433+
* [`signInWithTwitter(...)`](#signinwithtwitter)
434+
* [`signInWithYahoo(...)`](#signinwithyahoo)
435+
* [`signOut()`](#signout)
436+
* [`unlink(...)`](#unlink)
437+
* [`updateEmail(...)`](#updateemail)
438+
* [`updatePassword(...)`](#updatepassword)
439+
* [`updateProfile(...)`](#updateprofile)
440+
* [`useAppLanguage()`](#useapplanguage)
441+
* [`useEmulator(...)`](#useemulator)
442+
* [`addListener('authStateChange', ...)`](#addlistenerauthstatechange)
443+
* [`addListener('phoneVerificationCompleted', ...)`](#addlistenerphoneverificationcompleted)
444+
* [`addListener('phoneVerificationFailed', ...)`](#addlistenerphoneverificationfailed)
445+
* [`addListener('phoneCodeSent', ...)`](#addlistenerphonecodesent)
446+
* [`removeAllListeners()`](#removealllisteners)
447+
* [Interfaces](#interfaces)
448+
* [Type Aliases](#type-aliases)
449+
* [Enums](#enums)
503450

504451
</docgen-index>
505452

@@ -592,6 +539,25 @@ Deletes and signs out the user.
592539
--------------------
593540

594541

542+
### fetchSignInMethodsForEmail(...)
543+
544+
```typescript
545+
fetchSignInMethodsForEmail(options: FetchSignInMethodsForEmailOptions) => Promise<FetchSignInMethodsForEmailResult>
546+
```
547+
548+
Fetches the sign-in methods for an email address.
549+
550+
| Param | Type |
551+
| ------------- | ----------------------------------------------------------------------------------------------- |
552+
| **`options`** | <code><a href="#fetchsigninmethodsforemailoptions">FetchSignInMethodsForEmailOptions</a></code> |
553+
554+
**Returns:** <code>Promise&lt;<a href="#fetchsigninmethodsforemailresult">FetchSignInMethodsForEmailResult</a>&gt;</code>
555+
556+
**Since:** 6.0.0
557+
558+
--------------------
559+
560+
595561
### getCurrentUser()
596562

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

16601626

1627+
#### FetchSignInMethodsForEmailResult
1628+
1629+
| Prop | Type | Description | Since |
1630+
| ------------------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
1631+
| **`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 |
1632+
1633+
1634+
#### FetchSignInMethodsForEmailOptions
1635+
1636+
| Prop | Type | Description | Since |
1637+
| ----------- | ------------------- | ------------------------- | ----- |
1638+
| **`email`** | <code>string</code> | The user's email address. | 6.0.0 |
1639+
1640+
16611641
#### GetCurrentUserResult
16621642

16631643
| Prop | Type | Description | Since |

packages/authentication/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/authentication/FirebaseAuthentication.java

+21
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import io.capawesome.capacitorjs.plugins.firebase.authentication.classes.SignInOptions;
3030
import io.capawesome.capacitorjs.plugins.firebase.authentication.classes.SignInResult;
3131
import io.capawesome.capacitorjs.plugins.firebase.authentication.classes.SignInWithPhoneNumberOptions;
32+
import io.capawesome.capacitorjs.plugins.firebase.authentication.classes.options.FetchSignInMethodsForEmailOptions;
33+
import io.capawesome.capacitorjs.plugins.firebase.authentication.classes.results.FetchSignInMethodsForEmailResult;
3234
import io.capawesome.capacitorjs.plugins.firebase.authentication.handlers.AppleAuthProviderHandler;
3335
import io.capawesome.capacitorjs.plugins.firebase.authentication.handlers.FacebookAuthProviderHandler;
3436
import io.capawesome.capacitorjs.plugins.firebase.authentication.handlers.GoogleAuthProviderHandler;
@@ -135,6 +137,25 @@ public void deleteUser(FirebaseUser user, @NonNull Runnable callback) {
135137
);
136138
}
137139

140+
public void fetchSignInMethodsForEmail(FetchSignInMethodsForEmailOptions options, @NonNull final ResultCallback resultCallback) {
141+
String email = options.getEmail();
142+
143+
getFirebaseAuthInstance()
144+
.fetchSignInMethodsForEmail(email)
145+
.addOnCompleteListener(
146+
task -> {
147+
if (task.isSuccessful()) {
148+
List<String> signInMethods = task.getResult().getSignInMethods();
149+
FetchSignInMethodsForEmailResult result = new FetchSignInMethodsForEmailResult(signInMethods);
150+
resultCallback.success(result);
151+
} else {
152+
Exception exception = task.getException();
153+
resultCallback.error(exception);
154+
}
155+
}
156+
);
157+
}
158+
138159
@Nullable
139160
public FirebaseUser getCurrentUser() {
140161
return getFirebaseAuthInstance().getCurrentUser();

packages/authentication/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/authentication/FirebaseAuthenticationPlugin.java

+35
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.capawesome.capacitorjs.plugins.firebase.authentication.classes.PhoneVerificationCompletedEvent;
2020
import io.capawesome.capacitorjs.plugins.firebase.authentication.classes.SignInResult;
2121
import io.capawesome.capacitorjs.plugins.firebase.authentication.classes.SignInWithPhoneNumberOptions;
22+
import io.capawesome.capacitorjs.plugins.firebase.authentication.classes.options.FetchSignInMethodsForEmailOptions;
2223
import io.capawesome.capacitorjs.plugins.firebase.authentication.handlers.FacebookAuthProviderHandler;
2324
import io.capawesome.capacitorjs.plugins.firebase.authentication.interfaces.Result;
2425
import io.capawesome.capacitorjs.plugins.firebase.authentication.interfaces.ResultCallback;
@@ -166,6 +167,40 @@ public void deleteUser(PluginCall call) {
166167
}
167168
}
168169

170+
@PluginMethod
171+
public void fetchSignInMethodsForEmail(PluginCall call) {
172+
try {
173+
String email = call.getString("email");
174+
if (email == null) {
175+
call.reject(ERROR_EMAIL_MISSING);
176+
return;
177+
}
178+
179+
FetchSignInMethodsForEmailOptions options = new FetchSignInMethodsForEmailOptions(email);
180+
181+
implementation.fetchSignInMethodsForEmail(
182+
options,
183+
new ResultCallback() {
184+
@Override
185+
public void success(Result result) {
186+
call.resolve(result.toJSObject());
187+
}
188+
189+
@Override
190+
public void error(Exception exception) {
191+
Logger.error(TAG, exception.getMessage(), exception);
192+
String code = FirebaseAuthenticationHelper.createErrorCode(exception);
193+
call.reject(exception.getMessage(), code);
194+
}
195+
}
196+
);
197+
} catch (Exception exception) {
198+
Logger.error(TAG, exception.getMessage(), exception);
199+
String code = FirebaseAuthenticationHelper.createErrorCode(exception);
200+
call.reject(exception.getMessage(), code);
201+
}
202+
}
203+
169204
@PluginMethod
170205
public void getCurrentUser(PluginCall call) {
171206
try {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package io.capawesome.capacitorjs.plugins.firebase.authentication.classes.options;
2+
3+
import androidx.annotation.NonNull;
4+
5+
public class FetchSignInMethodsForEmailOptions {
6+
7+
@NonNull
8+
private String email;
9+
10+
public FetchSignInMethodsForEmailOptions(@NonNull String email) {
11+
this.email = email;
12+
}
13+
14+
@NonNull
15+
public String getEmail() {
16+
return this.email;
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package io.capawesome.capacitorjs.plugins.firebase.authentication.classes.results;
2+
3+
import com.getcapacitor.JSArray;
4+
import com.getcapacitor.JSObject;
5+
import io.capawesome.capacitorjs.plugins.firebase.authentication.interfaces.Result;
6+
import java.util.List;
7+
8+
public class FetchSignInMethodsForEmailResult implements Result {
9+
10+
private List<String> signInMethods;
11+
12+
public FetchSignInMethodsForEmailResult(List<String> signInMethods) {
13+
this.signInMethods = signInMethods;
14+
}
15+
16+
public JSObject toJSObject() {
17+
JSArray signInMethodsResult = new JSArray();
18+
for (String signInMethod : signInMethods) {
19+
signInMethodsResult.put(signInMethod);
20+
}
21+
22+
JSObject result = new JSObject();
23+
result.put("signInMethods", signInMethodsResult);
24+
return result;
25+
}
26+
}

0 commit comments

Comments
 (0)