Android - Login & Session
yuu Login
Integrating yuu Login Launcher
To integrate yuu Login into your app:
- Register the launcher provided by the SDK in your
ActivityorFragment. - Launch it when you're ready to start the yuu login flow.
Note:
Make sure you register the launcher before the component reaches the STARTED state, typically inside the onCreate() method of your Activity or Fragment.
private lateinit var yuuLoginLauncher: ActivityResultLauncher<Unit>
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
yuuLoginLauncher = YuuSdk.registerLoginLaunch(this) { result ->
when (result) {
is LoginResult.Success -> {
val jwt = result.data.jwt
// Handle success
}
is LoginResult.Cancelled -> {
// Handle cancel
}
is LoginResult.Error -> {
val exception = result.exception
// Handle error
}
}
}
}
// To launch the login flow:
yuuLoginLauncher.launch(Unit)
Token Login
Enables login by heightening an existing token from the client's side for a JWT from our side.
- The SDK handles the two-side backend token exchange and provides a JWT for accessing our services.
YuuSdk.loginByToken(token = "USER_TOKEN") { loginResult ->
when (loginResult) {
is LoginResult.Success -> {
// Handle success
}
is LoginResult.Error -> {
// Handle error with exception
}
}
}
Login status
Check if a user is currently logged in:
val isLoggedIn = YuuSdk.isLogin()
yuu Session
Once the user grants the yuu session, you can retrieve the JWT (access token) to authenticate and access yuu APIs. You can then use the provided SDK methods to retrieve the user's profile and point balance.
JWT (access token)
YuuSdk.getJwt(object : ApiCallListener<String> {
override fun success(data: String) {
// Handle success
}
override fun fail(exception: Exception?) {
// Handle error
}
})
User profile
YuuSdk.getUserProfile(object : ApiCallListener<UserProfileResponse> {
override fun success(data: UserProfileResponse) {
// Handle success: access data.firstName, data.lastName, etc.
}
override fun fail(exception: Exception?) {
// Handle error
}
})
User Point Balance
YuuSdk.getUserPointBalance(object : ApiCallListener<PointBalanceResponse> {
override fun success(data: PointBalanceResponse) {
// Handle success: access data.totalPoints
}
override fun fail(exception: Exception?) {
// Handle error
}
})
Logout
To logout, simply call the following method to clear all related member session data.
YuuSdk.logout()