jonsaw / amazon-cognito-identity-dart

Unofficial Amazon Cognito Identity Provider Dart SDK, to easily add user sign-up and sign-in to your mobile and web apps with AWS.
MIT License
205 stars 93 forks source link

CognitoUser.authenticateUser keeps throwing an exception. #16

Open ncb000gt opened 6 years ago

ncb000gt commented 6 years ago

Thanks for putting this out there. I ran into an issue trying to authenticate using the library so I broke the code out into an example application and was able to isolate the issue to lib/cognito_user.dart:144.

Receiver: Instance of 'Future'
Tried calling: []("UserConfirmationNecessary") - #0      Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:46:5)
#1      CognitoUser._authenticateUserInternal (package:amazon_cognito_identity_dart/src/cognito_user.dart:144:20)
<asynchronous suspension>
#2      CognitoUser._authenticateUserDefaultAuth (package:amazon_cognito_identity_dart/src/cognito_user.dart:627:12)
<asynchronous suspension>
#3      CognitoUser.authenticateUser (package:amazon_cognito_identity_dart/src/cognito_user.dart:436:20)
<asynchronous suspension>
#4      AuthService.login (file:///Users/ncampbell/Code/flutter_cognito_auth_test/lib/auth.dart:122:34)
<asynchronous suspension>
#5      _AuthGatewayState.submit (file:///Users/ncampbell/Code/flutter_cognito_auth_test/lib/main.dart:68:23)
<asynchronous suspension>
#6      _AuthGatewayState.build.<anonymous closure>.<anonymous closure> (file:///Users/<…>

I noticed the issue in 0.0.17 and pulled master to double check. The issue exists there as well.

I have a fix in a branch I'm working on and will push a PR up for it once I'm comfortable that all the issues are resolved.

ncb000gt commented 6 years ago

Even with the fix in GH-17 I am still running into an issue:

flutter: errrr: CognitoUserException: User Confirmation Necessary - #0      CognitoUser._authenticateUserInternal (package:amazon_cognito_identity_dart/src/cognito_user.dart:146:7)
<asynchronous suspension>
#1      CognitoUser._authenticateUserDefaultAuth (package:amazon_cognito_identity_dart/src/cognito_user.dart:628:12)
<asynchronous suspension>
#2      CognitoUser.authenticateUser (package:amazon_cognito_identity_dart/src/cognito_user.dart:437:20)
<asynchronous suspension>
#3      AuthService.login (file:///Users/ncampbell/Code/flutter_cognito_auth_test/lib/auth.dart:122:34)
<asynchronous suspension>
#4      _AuthGatewayState.submit (file:///Users/ncampbell/Code/flutter_cognito_auth_test/lib/main.dart:68:23)
<asynchronous suspension>
#5      _AuthGatewayState.build.<anonymous closure>.<anonymous closure> (file:///Users/ncampbell/Code/flutter_cognito_auth_test/lib/main.dart:148:13)
#6      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:494:14)
#7      _InkResponseSta<…>

It seems as though it isn't confirming the device, but I'm not really sure why that's not working. Any ideas?

ncb000gt commented 6 years ago

I added && !_signInUserSession.isValid() to line cognito_user.dart:145 which seems to be the right approach. But, I didn't want to push that up as I've only spent a small amount of time with the code.

I can add that to the PR if you agree.

jonsaw commented 6 years ago

Thanks for the find + feedback. Will look into it!

ncb000gt commented 6 years ago

@jonsaw any thoughts regarding the && !_signInUserSession.isValid() bit?

jonsaw commented 5 years ago

Sorry for the late reply. Is your setup close to the one found on Serverless Stack?

ncb000gt commented 5 years ago

@jonsaw yea. it's very similar except that i'm not using a custom domain for the the app auth because i'm handling it internally through two means, a flutter mobile app (using this lib) and through the web using amplify.

I haven't spent much more time digging into this either on my end. I suppose I should put it on my roadmap. ;D If I find anything else about this I'll post here.

MashaFomina commented 5 years ago

I have the same problem. I also added && !_signInUserSession.isValid() to line cognito_user.dart:145 to temporary resolve this problem.