Skip to content

Empty CognitoSignUpOptions are required when using the Amplify.Auth.signUp() #292

@LeFrosch

Description

@LeFrosch

Only the username and password are marked with required for Amplify.Auth.signUp, but when I don’t pass an empty instance SignUpOptions I get the following error.

Invocation:

Future<bool> register(String email, String password) async {
  final result = await Amplify.Auth.signUp(
    username: email,
    assword: password,
  );

  return result.isSignUpComplete;
}

Error:

E/amplify:flutter:auth_cognito(23284): java.lang.Exception: AMPLIFY_REQUEST_MALFORMED
E/amplify:flutter:auth_cognito(23284): 	at com.amazonaws.amplify.amplify_auth_cognito.AuthCognito.onSignUp(AuthCognito.kt:218)
E/amplify:flutter:auth_cognito(23284): 	at com.amazonaws.amplify.amplify_auth_cognito.AuthCognito.onMethodCall(AuthCognito.kt:128)
E/amplify:flutter:auth_cognito(23284): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/amplify:flutter:auth_cognito(23284): 	at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/amplify:flutter:auth_cognito(23284): 	at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692)
E/amplify:flutter:auth_cognito(23284): 	at android.os.MessageQueue.nativePollOnce(Native Method)
E/amplify:flutter:auth_cognito(23284): 	at android.os.MessageQueue.next(MessageQueue.java:336)
E/amplify:flutter:auth_cognito(23284): 	at android.os.Looper.loop(Looper.java:174)
E/amplify:flutter:auth_cognito(23284): 	at android.app.ActivityThread.main(ActivityThread.java:7710)
E/amplify:flutter:auth_cognito(23284): 	at java.lang.reflect.Method.invoke(Native Method)
E/amplify:flutter:auth_cognito(23284): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
E/amplify:flutter:auth_cognito(23284): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
I/flutter (23284): Unrecognized auth error returned from platform. See logs for details

I personally don’t think the error message conveys that the SignUpOptions are missing and additionally the options are not marked as required. To fix this error I created an empty map and passed it to the SignUpOptions, like that:

Future<bool> register(String email, String password) async {
  final result = await Amplify.Auth.signUp(
    username: email,
    password: password,
    options: CognitoSignUpOptions(userAttributes: <String, dynamic>{}),
  );

  return result.isSignUpComplete;
}

I don’t know if this is relevant but I configured the Cognito User Pool to use an email address as the username to sign up and sign in. Also I did not select any standard attributes.

Platform: Android
Device: OnePlus 7T (HD1903)
Android Version: 10
SDK Version: 29

Flutter Version: 1.22.5
Amplify Version: 0.0.1-dev.5

Metadata

Metadata

Assignees

Labels

authIssues related to the Auth Category

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions