I'm using AWS Amplify SDK for Cognito integration. Actually, I successfully integrated user sign in and sign up flows based on the documentation available here. However, after the successful login if we restart the app the user session is not persisting. Amplify.Auth.fetchAuthSession()
always returns isSignedIn
as false
. I have no idea where I'm making a problem. Please find the 'sign in' snippet below.
fun onSingIn(view: View) {
Amplify.Auth.signIn(
email.value,
password.value,
{ result ->
Log.i(TAG, if (result.isSignInComplete) "Sign in succeeded" else "Sign in not complete")
if (result.isSignInComplete) {
view.context.let {
it.startActivity(Intent(it, FeedActivity::class.java))
signInStatus.postValue(true)
}
}
},
{ error ->
view.context.let {
var message = it.getString(R.string.something_went_wrong)
when (error.cause) {
is UserNotConfirmedException ->{
email.value?.let {emailAddress ->
val direction =LoginFragmentDirections
.actionLoginFragmentToEmailVerificationCodeFragment(emailAddress)
view.findNavController().navigate(direction)
}
}
is UserNotFoundException ->
message = it.getString(R.string.credentilas_incorrect)
else->
viewModelScope.launch(Dispatchers.Main) { it.showToast(message) }
}
Log.e(TAG, error.toString())
}
}
)
}