docs/auth/passing-state-in-email-actions.md
Project: /docs/_project.yaml Book: /docs/_book.yaml
<link rel="stylesheet" type="text/css" href="/styles/docs.css" />You can pass state via a continue URL when sending email actions for password resets or verifying a user's email. This provides the user the ability to be returned to the app after the action is completed. In addition, you can specify whether to handle the email action link directly from a mobile application when it is installed instead of a web page.
This can be extremely useful in the following common scenarios:
A user, not currently logged in, may be trying to access content that requires the user to be signed in. However, the user might have forgotten their password and therefore trigger the reset password flow. At the end of the flow, the user expects to go back to the section of the app they were trying to access.
An application may only offer access to verified accounts. For example, a newsletter app may require the user to verify their email before subscribing. The user would go through the email verification flow and expect to be returned to the app to complete their subscription.
In general, when a user begins a password reset or email verification flow on an Apple app they expect to complete the flow within the app; the ability to pass state via continue URL makes this possible.
Having the ability to pass state via a continue URL is a powerful feature that Firebase Auth provides and which can significantly enhance the user experience.
In order to securely pass a continue URL, the domain for the URL will need to be allowlisted in the Firebase console. This is done in the <b>Authentication</b> section by adding this domain to the list of <b>Authorized domains</b> under the <b>Sign-in method</b> tab if it is not already there.
An ActionCodeSettings instance needs to be provided when sending
a password reset email or a verification email. This interface takes the
following parameters:
The following example illustrates how to send an email verification link that
will open in a mobile app first as a Firebase Dynamic Link using the custom
dynamic link domain example.page.link
(iOS app com.example.ios or Android app com.example.android where the app
will install if not already installed and the minimum version is 12). The
deep link will contain the continue URL payload
https://www.example.com/[email protected].
final user = FirebaseAuth.instance.currentUser;
final actionCodeSettings = ActionCodeSettings(
url: "http://www.example.com/verify?email=${user?.email}",
iOSBundleId: "com.example.ios",
androidPackageName: "com.example.android",
);
await user?.sendEmailVerification(actionCodeSettings);
Firebase Auth uses Firebase Dynamic Links when sending a link that is meant to be opened in a mobile application. In order to use this feature, Dynamic Links need to be configured in the Firebase Console.
Enable Firebase Dynamic Links:
In the Firebase console, open the <b>Dynamic Links</b> section.
If you have not yet accepted the Dynamic Links terms and created a Dynamic Links domain, do so now.
If you already created a Dynamic Links domain, take note of it. A Dynamic Links domain typically looks like the following example: <pre>example.page.link</pre>
You will need this value when you configure your Apple or Android app to intercept the incoming link.
Configuring Android applications:
Configuring Apple applications:
You can specify whether you want to handle the action code link from a web
application first and then redirect to another web page or mobile application
after successful completion, provided the mobile application is available.
This is done by setting handleCodeInApp to false in the ActionCodeSettings object. While
a bundle ID
or Android package name are not required, providing them will allow the user
to redirect back to the specified app on email action code completion.
The web URL used here, is the one configured in the email action templates section. A default one is provisioned for all projects. Refer to customizing email handlers to learn more on how to customize the email action handler.
In this case, the link within the continueURL query parameter will be
an FDL link whose payload is the URL specified in the ActionCodeSettings
object. While you can intercept and handle the incoming link from your app
without any additional dependency, we recommend using the FDL client library to
parse the deep link for you.
You can specify whether you want to handle the action code link within your
mobile application first, provided it is installed. With Android applications,
you also have the ability to specify via the androidInstallApp that
the app is to be installed if the device supports it and it is not already
installed.
If the link is clicked from a device that does not support the mobile
application, it is opened from a web page instead.
This is done by setting handleCodeInApp to true in the ActionCodeSettings object. The
mobile application's Android package name or bundle ID will also need to be
specified.The fallback web URL used here, when no mobile app is available, is
the one configured in the email action templates section. A default one is
provisioned for all projects. Refer to
customizing email handlers to learn more on
how to customize the email action handler.
In this case, the mobile app link sent to the user will be an FDL link whose
payload is the action code URL, configured in the Console, with the query
parameters oobCode, mode, apiKey and continueUrl. The latter will be the
original URL specified in the
ActionCodeSettings object. While you can intercept and handle the
incoming link from your app without any additional dependency, we recommend
using the FDL client library to parse the deep link for you. The action code can
be applied directly from a mobile application similar to how it is handled from
the web flow described in the
customizing email handlers section.