-
Notifications
You must be signed in to change notification settings - Fork 16
D.6 Anonymous Auth
You can use Firebase Authentication to create and use temporary anonymous accounts to authenticate with Firebase. These temporary anonymous accounts can be used to allow users who haven't yet signed up to your app to to work with data protected by security rules. If an anonymous user decides to sign up to your app, you can link their sign-in credentials to the anonymous account so that they can continue to work with their protected data in future sessions.
- In the Firebase console, open the Auth section.
- On the Sign-in Methods page, enable the Anonymous sign-in method.
When a signed-out user uses an app feature that requires authentication with Firebase, sign in the user anonymously like below:
Auth.listener.addEventListener(AuthEvents.SIGN_IN_RESULT, onSignInResult);
Auth.signIn(null); // instead of passing the login credential, just pass null
function onSignInResult(e:AuthEvents):void
{
if(e.result == Auth.RESULT_SUCCESS)
{
trace("signed in successfully");
/*
When sign in is successful, the AUTH_STATE_CHANGED event will be dispatched which
you can use to read user's information.
*/
}
else
{
trace("onSignInResult: " + e.msg);
}
}
:start: To protect your project from abuse, Firebase limits the number of new email/password and anonymous sign-ups that your application can have from the same IP address in a short period of time. You can request and schedule temporary changes to this quota from the Firebase console.
When an anonymous user signs up to your app, you might want to allow them to continue their work with their new account—for example, you might want to make the items the user added to their shopping cart before they signed up available in their new account's shopping cart. To do so, complete the following steps:
- When the user signs up, complete the sign-in flow for the user's authentication provider up to, but not including, calling one of the
Auth.signInWith
methods. For example, get the user's Google ID token, Facebook access token, or email address and password. - Get an
authProvider.getCredential()
for the new authentication provider:
var authProvider:AuthProvider = new AuthProvider();
// Google Sign-In
authProvider.setGoogleAuthProvider("id_token", "access_token");
// Facebook Login
authProvider.setFacebookAuthProvider("access_token");
// Email-password sign-in
authProvider.setEmailAuthProvider("email", "password");
// other auth providers...
Pass the authProvider.getCredential()
object to the sign-in user's linkWithCredential
method:
FirebaseUser.listener.addEventListener(FirebaseUserEvents.LINK_WITH_RESULT, onLink);
FirebaseUser.linkWithCredential(authProvider.getCredential());
function onLink(e:FirebaseUserEvents):void
{
C.log("onLink result=" + e.result, " msg=" + e.msg);
}
⭐ This technique can also be used to link any two accounts.
Enjoy building Air apps – With ♥ from MyFlashLabs Team
Introduction to Firebase ANEs collection for Adobe Air apps
Get Started with Firebase Core in AIR
- Prerequisites
- Add Firebase to your app
- Add the Firebase SDK
- Init Firebase Core
- Available ANEs
- Managing Firebase iid
Get Started with Authentication
- Add Authentication
- Init Authentication
- Manage Users
- Phone Number
- Custom Auth
- Anonymous Auth
- State in Email Actions
- Email Link Authentication
Get Started with FCM + OneSignal
- Add FCM ANE
- Init FCM ANE
- Send Your 1st Message
- Send Msg to Topics
- Understanding FCM Messages
- init OneSignal
- Add Firestore
- Init Firestore
- Add Data
- Transactions & Batches
- Delete Data
- Manage the Console
- Get Data
- Get Realtime Updates
- Simple and Compound
- Order and Limit Data
- Paginate Data
- Manage Indexes
- Secure Data
- Offline Data
- Where to Go From Here
Get Started with Realtime Database
- Add Realtime Database
- Init Realtime Database
- Structure Your Database
- Save Data
- Retrieve Data
- Enable Offline Capabilities
Get Started with Remote Config
- Add Storage ANE
- Init Storage ANE
- Upload Files to Storage
- Download Files to Air
- Use File Metadata
- Delete Files