4

My Firebase verification emails work just fine. However, as soon as I try add actionCodeSettings they don't. The issue may be the url that I set, given that I don't know what I should actually be setting this to.

What I am trying to achieve is that when a link is clicked on, on the Android device on which the app is installed, it bounces the user back to the app.

If clicked anywhere else then nothing other than the usual message stating that the account is verified needs to happen.

How should I be using actionCodeSettings to get this behaviour?

                        String url = "com.app/verify?uid=" + user.getUid();
                        ActionCodeSettings actionCodeSettings = ActionCodeSettings.newBuilder()
                                .setUrl(url)
                                .setAndroidPackageName("com.app", false, null)
                                .build();



                        user.sendEmailVerification(actionCodeSettings) 
                                .addOnCompleteListener(new OnCompleteListener<Void>() {
                                    @Override
                                    public void onComplete(@NonNull Task<Void> task) {
                                        if (task.isSuccessful()) {
                                            Log.d(TAG, "Email sent.");
                                            Toast.makeText(MainActivity.this, "Registration successful. Please verify your account by clicking on the link sent to your email address.",
                                                    Toast.LENGTH_LONG).show();
                                        }else {

                                            Log.d(TAG, "Email not sent");
                                            Toast.makeText(MainActivity.this, "Registration successful. However, verification email could not be send.",
                                                    Toast.LENGTH_LONG).show();
                                        }
                                    }
                                });
Christopher Mills
  • 711
  • 10
  • 28

1 Answers1

0

You should use an actual URL instead of com.app/verify?uid. You can use Firebase hosting for that. It should already be configured for your project. This is used as a fallback URL in case the user opens the app on another device where mobile app is not available. Also you need to set canHandleCodeInApp to true in your ActionCodeSettings, so when the user clicks the link it opens directly in your mobile app instead of handling the link in the default webpage Firebase Auth provisions for your project with a continue button back to your app.

bojeil
  • 29,642
  • 4
  • 69
  • 76
  • I've added `.setHandleCodeInApp(true)` and I've set my url to that of my project, and tried it in both formats: `"projectId.firebaseapp.com/verify?uid=" + user.getUid()` and `"projectId.firebaseapp.com"`. It is still not working – Christopher Mills Sep 18 '18 at 18:19
  • Update your code above and provide more details on what is happening. – bojeil Sep 18 '18 at 21:07