Authentication and Authorization
Logging in with InstaVision’s Authentication System
To log in with the user account, the following information is typically required:
email(required): The email address of the userpassword(required): The password of the user
Instavision.userServices.login(
email = "test@example.com", // The email address of the user
password = "password", // The password of the user
onSuccess = { user ->
// The user object contains the user details
},
onError = { apiError ->
// The error object contains the error code and message
}
)
Logging in with Third Party Authentication System
To log in with the user account, the following information is typically required:
token(required): The jwt token of the user
Instavision.userServices.login(
token = "<JWT_TOKEN>", // The email address of the user
)
You will also be required to implement the RefreshListener interface to handle token refresh. The onRefreshToken method should return the new token. and will be triggered when ever the requests fail due to token expiration.
class MainActivity : Activity(), RefreshTokenListener {
override fun onRefreshToken(): String {
// Implement your logic to refresh the token
return "<NEW_JWT_TOKEN>"
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Instavision.userServices.addRefreshTokenListener(this)
}
}
Checking if the user is logged in
To check if the user is logged in, the following code can be used:
viewModelScope.launch {
InstaVision.userServices.isLoggedIn.collectLatest { isLoggedIn ->
if (isLoggedIn) {
// The user is logged in
} else {
// The user is not logged in
}
}
}
Logout
To log out the user, the following code can be used:
pushToken(optional): The push token of the device to unregister for push notifications.
InstaVision.userServices.logout(pushToken = "pushToken")