Authenticate Users
{+service+} provides an API for authenticating users using any enabled
authentication provider. Instantiate a Credentials object and pass
it to app.login()
method to authenticate a user and create a User
object for that user.
Each authentication provider corresponds to a
static helper method
used to instantiate Credentials objects for that
authentication provider.
Log In​
You can authenticate users with app.login().
If successful, app.login()returns a User object.
In the event of a failure, app.login() throws an
exception of type AppException.
Anonymous User​
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
AuthenticationProvider.ANONYMOUS().
Then pass the generated credential to app.login().
val app: App = App.create(YOUR_APP_ID)
runBlocking {
val user = app.login(Credentials.anonymous())
}
Email/Password User​
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 AuthenticationProvider.EMAIL_PROVIDER()
with the user's email and password. Then pass the generated credential
to app.login().
val app: App = App.create(YOUR_APP_ID)
runBlocking {
val user = app.login(Credentials.emailPassword(email, password))
}
Log Out​
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 updates have uploaded to the server.
user.logOut()