Skip to content

Instantly share code, notes, and snippets.

@jaisonfdo
Last active Mar 9, 2020
Embed
What would you like to do?
Firebase Auth - Password-less Email - Demo
implementation 'com.google.android.gms:play-services-auth:17.0.0'
implementation 'com.google.firebase:firebase-auth:19.2.0'
<uses-permission android:name="android.permission.INTERNET"/>
private FirebaseAuth mAuth;
mAuth = FirebaseAuth.getInstance();
ActionCodeSettings actionCodeSettings;
actionCodeSettings = ActionCodeSettings.newBuilder()
.setUrl("https://droidmentor.com/finishSignUp")
.setHandleCodeInApp(true)
.setAndroidPackageName("com.droidmentor.firebaseservicesdemo", false, null)
.build();
mAuth.sendSignInLinkToEmail(emailID, actionCodeSettings)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Log.d(TAG, "onComplete: ");
if (task.isSuccessful()) {
Log.d(TAG, "Email sent.");
} else {
Objects.requireNonNull(task.getException()).printStackTrace();
}
}
});
System.err: com.google.firebase.FirebaseException: An internal error has occurred.
[ UNAUTHORIZED_DOMAIN:Domain not whitelisted by project ]
com.google.firebase.auth.FirebaseAuthException: Please activate Dynamic Links in the
Firebase Console and agree to the terms and conditions.
<activity android:name=".MailAuthenticationActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="droidmentor.com" android:scheme="https"/>
</intent-filter>
</activity>
Intent intent = getIntent();
String emailLink = intent.getData().toString();
mAuth.isSignInWithEmailLink(emailLink)
mAuth.signInWithEmailLink(emailID, emailLink)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Toast.makeText(activity, "Successfully signed in with email link!", Toast.LENGTH_SHORT).show();
if (task.getResult() != null && task.getResult().getUser() != null) {
FirebaseUser user = task.getResult().getUser();
if (!TextUtils.isEmpty(user.getUid()))
Log.d(TAG, "signInWithCredential: " + user.getUid());
}
}
}
});
// For example use *es* for Spanish
mAuth.setLanguageCode("YOUR_LANGUAGE_CODE");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment