On this page
Atlas App Services provides an API for authenticating users using any enabled
authentication provider. Instantiate a Credentials
object and pass it to App.logIn()
to authenticate and create a User
object for that user.
Each authentication provider corresponds to a static constructor method
used to instantiate
Credentials objects for that authentication provider.
Realm registers accounts differently depending on the authentication provider:
- You do not need to register anonymous users.
- To register an email/password user, refer to Email/Password User Registration.
- If you are using Google, Facebook, Apple, or Custom JWT authentication, registration is handled by these third-party services.
You can authenticate users with App.logIn().
app.logIn returns a
The anonymous authentication provider
enables users to log in to your application with short-term accounts
that store no persistent personal information. To log in with anonymous
authentication, create an anonymous credential by calling
and then pass the generated credential to
Credentials anonCredentials = Credentials.anonymous(); await app.logIn(anonCredentials);
The Email/Password authentication provider
enables users to log in to your application with an email username and
a password. To log in with email/password authentication, create an
email/password credential by calling Credentials.emailPassword()
with the user's email and password. Then pass the generated credential
Credentials emailPwCredentials = Credentials.emailPassword("firstname.lastname@example.org", "myStr0ngPassw0rd"); await app.logIn(emailPwCredentials);
To learn more about the complete flow of using App Services Email/Password authentication, refer to the Email/Password Users documentation.
You can log out any user, regardless of the authentication provider used to log in, using User.logOut(). This method:
- Deletes locally stored user credentials from the device
- Immediately halts any synchronization to and from the user's realms
Because logging out halts synchronization, you should only log out after all local Realm updates have uploaded to the server.
Once you have an authenticated user, you can retrieve the User object with the
currentUser object is persisted in local storage, so even if
the app shuts down after the initial authentication, you do not need to call
logIn again (unless the user logged out).
User? user = app.currentUser;