diff --git a/CHANGELOG.md b/CHANGELOG.md index c975c3321..2e9949b45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,3 +2,4 @@ - Restore `setGithubButtonId` when using custom layouts (#1783) - Improve how network errors display when they are non-fatal (#1803) - Warn instead of crashing when a reserved email is used (#1644) +- Allow `setAllowNewAccounts(false)` to be used with email link sign in (#1762) diff --git a/auth/src/main/java/com/firebase/ui/auth/util/data/ProviderUtils.java b/auth/src/main/java/com/firebase/ui/auth/util/data/ProviderUtils.java index 9ba6dbe43..b00e0f87d 100644 --- a/auth/src/main/java/com/firebase/ui/auth/util/data/ProviderUtils.java +++ b/auth/src/main/java/com/firebase/ui/auth/util/data/ProviderUtils.java @@ -212,6 +212,17 @@ public Task> then(@NonNull Task task) { } } + // In this case the developer has configured EMAIL_LINK sign in but the + // user is a password user. The valid use case here is that the developer + // is using admin-created accounts and combining email-link sign in with + // setAllowNewAccounts(false). So we manually enable EMAIL_LINK. See: + // https://github.com/firebase/FirebaseUI-Android/issues/1762#issuecomment-661115293 + if (allowedProviders.contains(EMAIL_LINK_PROVIDER) + && methods.contains(EmailAuthProvider.EMAIL_PASSWORD_SIGN_IN_METHOD) + && !methods.contains(EMAIL_LINK_PROVIDER)) { + lastSignedInProviders.add(0, signInMethodToProviderId(EMAIL_LINK_PROVIDER)); + } + if (task.isSuccessful() && lastSignedInProviders.isEmpty() && !methods.isEmpty()) { // There is an existing user who only has unsupported sign in methods