createUserPoolDomain method

Future<CreateUserPoolDomainResponse> createUserPoolDomain({
  1. required String domain,
  2. required String userPoolId,
  3. CustomDomainConfigType? customDomainConfig,
})

Creates a new domain for a user pool.

May throw InvalidParameterException. May throw NotAuthorizedException. May throw ResourceNotFoundException. May throw LimitExceededException. May throw InternalErrorException.

Parameter domain : The domain string.

Parameter userPoolId : The user pool ID.

Parameter customDomainConfig : The configuration for a custom domain that hosts the sign-up and sign-in webpages for your application.

Provide this parameter only if you want to use a custom domain for your user pool. Otherwise, you can exclude this parameter and use the Amazon Cognito hosted domain instead.

For more information about the hosted domain and custom domains, see Configuring a User Pool Domain.

Implementation

Future<CreateUserPoolDomainResponse> createUserPoolDomain({
  required String domain,
  required String userPoolId,
  CustomDomainConfigType? customDomainConfig,
}) async {
  ArgumentError.checkNotNull(domain, 'domain');
  _s.validateStringLength(
    'domain',
    domain,
    1,
    63,
    isRequired: true,
  );
  ArgumentError.checkNotNull(userPoolId, 'userPoolId');
  _s.validateStringLength(
    'userPoolId',
    userPoolId,
    1,
    55,
    isRequired: true,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'AWSCognitoIdentityProviderService.CreateUserPoolDomain'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'Domain': domain,
      'UserPoolId': userPoolId,
      if (customDomainConfig != null)
        'CustomDomainConfig': customDomainConfig,
    },
  );

  return CreateUserPoolDomainResponse.fromJson(jsonResponse.body);
}