Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase redirect user to a page after clicking verification link

I'm using firebase in my web app with Ionic and I would like to redirect the user to a specific page (the login page, in my case) after he clicks on the link in the verification email.
At the moment, when the user clicks on the verification link, he is redirected on another browser page that says that he has confirmed the email.

enter image description here

I would like to redirect him directly to a page of my web app, without passing through that confirmation.
Is it possible to do that?

like image 512
Usr Avatar asked Nov 16 '17 12:11

Usr


People also ask

How do you configure Firebase dynamic links to open email action links via mobile apps?

The Android app needs to be registered in the Console. Whether the email action link will be opened in a mobile app or a web link first. The default is false. When set to true, the action code link will be be sent as a Universal Link or Android App Link and will be opened by the app if installed.

What is oobCode?

oobCode. A one-time code, used to identify and verify a request. apiKey. Your Firebase project's API key, provided for convenience.

How does Firebase email verification work?

You can use Firebase Authentication to sign in a user by sending them an email containing a link, which they can click to sign in. In the process, the user's email address is also verified. There are numerous benefits to signing in by email: Low friction sign-up and sign-in.


2 Answers

I couldn't get any of the solutions here to work. So after looking up the docs I found that you add a continue URL after the email verification to which the firebase will redirect to after confirming. https://firebase.google.com/docs/auth/web/passing-state-in-email-actions

After email is verified you might also have to force refresh the firebase token if you use email_verified in your firebase rules.

You can do what I did.

  1. Pass ActionCodeSettings to sendEmailVerification.
  auth.createUserWithEmailAndPassword(email, password)
  .then((res) => {
    res.user.sendEmailVerification({
      url: "https://example.com/path?confirm_email=true",
    });
    return createUser({ email, uid: res.user.uid, name });
  })

This will make firebase redirect to https://example.com/path?confirm_email=true after email verification. The confirm_email is so that I know when to force refresh the firebase token.

(Optional)

  1. Once redirected to the page you want you can check for the confirm_email param and force refresh the token accordingly.
const urlParams = new URLSearchParams(window.location.search);
const isConfirmingEmail = urlParams.get('confirm_email');


auth.currentUser.getIdToken(!!isConfirmingEmail).then(() => {
  // Refreshed Token
})
like image 97
Milan Muhammed Avatar answered Sep 20 '22 17:09

Milan Muhammed


Yes it's possible. Look in the firebase.console on the left for "Authentication". Then find "Templates" and look for "Email address verification". I think it's default opened. On the template you will see a small pencil, click on it. After that you can change your template however you want. At the bottom you will find the link "customize action URL". Open this link, paste your URL in the modal window and save. That's it.

First Steps

Last Steps

like image 40
Rasidre Avatar answered Sep 21 '22 17:09

Rasidre