Last active
March 9, 2020 12:26
-
-
Save jaisonfdo/b35af9d710d1246e0b12bd3c2e402451 to your computer and use it in GitHub Desktop.
Firebase Auth - Password-less Email - Demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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