- Stitch >
- Users & Authentication >
- Authentication Providers
Anonymous Authentication¶
On this page
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. For this reason, you should not use Anonymous authentication in a situation where you want to persist a user’s data. Instead, you can associate an existing Anonymous identity with a user account created by a different authentication provider. Linking these identities allows you to persist the data from the anonymous account. See Linking User Accounts for more information on how to accomplish this.
Anonymous user expiration
Stitch 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¶
- Stitch UI
- Import/Export
You can enable the Anonymous authentication provider from the Stitch UI by selecting Anonymous from the Users > Providers page.
You can enable the Anonymous authentication provider with stitch-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:
Note
The anonymous authentication provider does not have any provider-specific configuration options.
Usage¶
Authenticate a User¶
- JavaScript SDK
- Android SDK
- iOS SDK
To authenticate a user anonymously, call
StitchAppClient.auth.loginWithCredential() with an
instance of AnonymousCredential,
returning a Promise
instance. If the authentication
succeeds, the Promise
resolves with an
instance of StitchUser:
To authenticate a user anonymously, instantiate an AnonymousCredential and pass it as the argument to StitchAuth.loginWithCredential().
To authenticate a user anonymously, call StitchAuth.login() with an instance of AnonymousCredential: