Login
In order to actually send vouchers users need to be authenticated with Vouchrs server. This is done using an AuthLoginManager
.
For nonproduction sandbox usage a JWT example can be seen here: JWTExample.
As mentioned in the Sending Section the AuthManager is what handles login from an app point of view. Additional documentation about callbacks camn be found here
Note: During the create flow, login will automatically be called when a user attempts to create a gift if they are not logged in already. You can also login manually with the following:
/* NetworkName must match the NetworkName in your JwtAuthManager file */
AuthLoginManager authLoginManager = Engine.userManager().getAuthManagerForNetworkName("YOUR_NETWORK_NAME")
Engine.userManager().login(context, authLoginManager)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<Credential>() {
@Override
public void onCompleted() {}
@Override
public void onError(Throwable e) { /* ERROR */ }
@Override
public void onNext(Credential credential) { /* SUCCESS */ }
});
/* NetworkName must matchs the NetworkName in your JwtAuthManager file */
val authLoginManager = Engine.userManager().getAuthManagerForNetworkName("YOUR_NETWORK_NAME") as JwtAuthManager
Engine.userManager().login(context, authLoginManager)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Subscriber<Credential>() {
override fun onCompleted() {}
override fun onError(e: Throwable) { /* ERROR */ }
override fun onNext(credential: Credential) { /* SUCCESS */ }
})
If you login before the create flow Voucher assets can be uploaded to the server as the gift is built decreasing the amount of loading the user sees at the end of the flow.
Check if currently logged in
Boolean loggedIn = Engine.userManager.isLoggedIn()
val loggedIn = Engine.userManager().isLoggedIn
Listening on Login State
Engine.userManager().observerLoginState().subscribe(new Subscriber<Boolean>() {
@Override
public void onNext(Boolean isLoggedIn) {
if(isLoggedIn){
/* Logged In */
}
}
});
Engine.userManager().observerLoginState().subscribe {
if (it) {
/* Logged In */
}
}