Navigation

Anonymous Authentication

Overview

The Anonymous authentication provider allows users to log in to your application without providing credentials. Each time someone authenticates anonymously, the provider generates a new anonymous user object for that session. Anonymous user objects have a unique ID value but no other metadata fields or configuration options.

Potential use cases for anonymous authentication include:

  • Authenticating the readers of a blog or news service.
  • Allowing end users to try the features of an application before registering for an account.
  • Simplifying the creation of users while developing and testing the client application.

Account Linking

An Anonymous user object is not intended to be reused, and once a user logs out, they will not be able to retrieve any previous user data. To persist data associated with an Anonymous user, you can associate that existing Anonymous identity with a user account created by a different authentication provider.

Anonymous user expiration

Realm may delete an Anonymous user object that is 90 days old (or older). When an account is deleted, it is not recoverable and any associated user data is lost. Documents created or modified by the user remain unaffected.

Configuration

You can enable the Anonymous authentication provider from the Realm UI in the Authentication options.

  1. Select Authentication in the left sidebar.
  2. Select the “Allow users to log in anonymously” entry of the Provider list.
  3. Click the Provider Enabled toggle to move it into the “On” state.
  4. Click the Save button in the lower right of the page to save your changes to the Realm app configuration.
  5. Click Review & Deploy Changes in the dropdown that appears at the top of the page.
  6. Review the changes to your app’s configuration and click Deploy in the lower right of the dialog to make your changes available to application users.

You can enable the Anonymous authentication provider with realm-cli by importing an application directory that contains a configuration file for the provider.

The configuration file must be named anon-user.json and stored in the /auth_providers directory. Configuration files for the Anonymous authentication provider have the following form:

/auth_providers/anon-user.json
{
  "name": "anon-user",
  "type": "anon-user",
  "disabled": <boolean>,
}

Note

The anonymous authentication provider does not have any provider-specific configuration options.

Examples

For code examples that demonstrate how to register and log in using anonymous authentication, see the documentation for the Realm SDKs:

To register or log in an anonymous user from the iOS Client SDK, see the iOS SDK guide to anonymous authentication.

To register or log in an anonymous user from the Android Client SDK, see the Android SDK guide to anonymous authentication.

To register or log in an anonymous user from the .NET Client SDK, see the .NET SDK guide to anonymous authentication.

To register or log in an anonymous user from the Node Client SDK, see the Node SDK guide to anonymous authentication.

To register or log in an anonymous user from the React Native Client SDK, see the React Native SDK guide to anonymous authentication.

To register or log in an anonymous user from the Web Client SDK, see the Web SDK guide to anonymous authentication.

Summary

  • Anonymous authentication allows users to interact with your application creating an identity.
  • To persist data from an anonymous session after a user creates an identity with a different authentication provider, you can link the two identities.