Skip to content
This repository has been archived by the owner on May 17, 2022. It is now read-only.

D.7 State in Email Actions

Hadi Tavakoli edited this page Jun 16, 2019 · 4 revisions

Passing State in Email Actions

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.

⭐ To use ActionCodeSettings, your app must have Firebase Dynamic Links enabled and ready: https://github.com/myflashlab/Firebase-ANE/wiki/I.1-Add-Dynamic-links

This can be extremely useful in the following common scenarios:

  1. 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.

  2. 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.

  3. In general, when a user begins a password reset or email verification flow on an iOS 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 whitelisted in the Firebase console. This is done in the Authentication section by adding this domain to the list of OAuth redirect domains if it is not already there.

A ActionCodeSettings instance needs to be provided when sending a password reset email or a verification email. This interface takes the following parameters:

Parameter type Description
url String Sets the link (state/continue URL) which has different meanings in different contexts: 1. When the link is handled in the web action widgets, this is the deep link in the continueUrl query parameter. 2. When the link is handled in the app directly, this is the continueUrl query parameter in the deep link of the Dynamic Link.
iOSBundleID String Sets the iOS bundle ID. This will try to open the link in an iOS app if it is installed. The iOS app needs to be registered in the Console.
androidPackageName String Sets the Android package name. This will try to open the link in an android app if it is installed.
androidInstallIfNotAvailable Boolean specifies whether to install the Android app if the device supports it and the app is not already installed. If this field is provided without a packageName, an error is thrown explaining that the packageName must be provided in conjunction with this field.
androidMinVersion String The minimum version of the app that is supported in this flow. If minimumVersion is specified, and an older version of the app is installed, the user is taken to the Play Store to upgrade the app. The Android app needs to be registered in the Console.
handleCodeInApp Boolean 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. In the false case, the code will be sent to the web widget first and then on continue will redirect to the app if installed.

The following example illustrates how to send an email verification link that will open in a mobile app first as a Firebase Dynamic 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].

// get the user's email
var userEmail:String = FirebaseUser.email;

// build the continueUrl
var url:String = "https://www.example.com/?email=" + userEmail;

// pass the continueUrl to ActionCodeSettings
var settings:ActionCodeSettings = new ActionCodeSettings(url);
settings.dynamicLinkDomain = "yourURLPrefix.page.link";
settings.handleCodeInApp = true;
settings.androidPackageName = "air.com.example.app"; // if not manually set, it will be set automatically
settings.androidInstallIfNotAvailable = true;
settings.androidMinVersion = "12";
settings.iOSBundleID = "com.example.app"; // if not manually set, it will be set automatically

FirebaseUser.listener.addEventListener(FirebaseUserEvents.SEND_EMAIL_VERIFICATION_RESULT, onSendEmailVerification);
FirebaseUser.sendEmailVerification(settings);

function onSendEmailVerification(e:FirebaseUserEvents):void
{
	if(e.result == Auth.RESULT_SUCCESS)
	{
		trace("onSendEmailVerification successful");
	}
	else
	{
		trace("onSendEmailVerification: " + e.msg);
	}
}

find more information here: https://firebase.google.com/docs/auth/ios/passing-state-in-email-actions

Introduction to Firebase ANEs collection for Adobe Air apps


Get Started with Firebase Core in AIR

  1. Prerequisites
  2. Add Firebase to your app
  3. Add the Firebase SDK
  4. Init Firebase Core
  5. Available ANEs
  6. Managing Firebase iid

Get Started with Analytics

  1. Add Analytics ANE
  2. Init Analytics ANE
  3. Log Events
  4. Set User Properties

Get Started with Crashlytics

  1. Add Crashlytics ANE
  2. Test Your Implementation
  3. Customize Crash Reports
  4. Upload .dSYM for iOS apps

Get Started with DynamicLinks

  1. Add DynamicLinks ANE
  2. Init DynamicLinks ANE
  3. Create DynamicLinks
  4. Receive DynamicLinks
  5. View Analytics

Get Started with Authentication

  1. Add Authentication
  2. Init Authentication
  3. Manage Users
  4. Phone Number
  5. Custom Auth
  6. Anonymous Auth
  7. State in Email Actions
  8. Email Link Authentication

Get Started with FCM + OneSignal

  1. Add FCM ANE
  2. Init FCM ANE
  3. Send Your 1st Message
  4. Send Msg to Topics
  5. Understanding FCM Messages
  6. init OneSignal

Get Started with Firestore

  1. Add Firestore
  2. Init Firestore
  3. Add Data
  4. Transactions & Batches
  5. Delete Data
  6. Manage the Console
  7. Get Data
  8. Get Realtime Updates
  9. Simple and Compound
  10. Order and Limit Data
  11. Paginate Data
  12. Manage Indexes
  13. Secure Data
  14. Offline Data
  15. Where to Go From Here

Get Started with Realtime Database

  1. Add Realtime Database
  2. Init Realtime Database
  3. Structure Your Database
  4. Save Data
  5. Retrieve Data
  6. Enable Offline Capabilities

Get Started with Remote Config

  1. Parameters and Conditions
  2. Add Remote Config
  3. Init Remote Config

Get Started with Performance

  1. Add Performance ANE
  2. Init & Start Monitoring

Get Started with Storage

  1. Add Storage ANE
  2. Init Storage ANE
  3. Upload Files to Storage
  4. Download Files to Air
  5. Use File Metadata
  6. Delete Files

Get Started with Functions

  1. Write & Deploy Functions
  2. Add Functions ANE
  3. Init Functions
Clone this wiki locally