Amplify configure V6 is not working with my aws-exports

133 Views Asked by At

in the old versions of Amplify (V5), after init we have an aws-export file under src and we have just to do

Amplify.configure(updatedAwsConfig);```


I use amplify for Cognito and in V5, I have this configuration for multiple callback 

```import awsConfig from './aws-exports';

const isLocalhost = Boolean(
  window.location.hostname === 'localhost' ||
    // [::1] is the IPv6 localhost address.
    window.location.hostname === '[::1]' ||
    // 127.0.0.1/8 is considered localhost for IPv4.
    window.location.hostname.match(
      /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
    )
);

// Assuming you have two redirect URIs, and the first is for localhost and second is for production
const [localRedirectSignIn, productionRedirectSignIn] =
  awsConfig.oauth.redirectSignIn.split(',');

const [localRedirectSignOut, productionRedirectSignOut] =
  awsConfig.oauth.redirectSignOut.split(',');

const updatedAwsConfig = {
  ...awsConfig,
  oauth: {
    ...awsConfig.oauth,
    redirectSignIn: isLocalhost
      ? localRedirectSignIn
      : productionRedirectSignIn,
    redirectSignOut: isLocalhost
      ? localRedirectSignOut
      : productionRedirectSignOut
  }
};

Amplify.configure(updatedAwsConfig);```



But in V6 I have something new and  I don't understand what ` ...oauthConfig` and `...userPoolConfig` means in the below conf and what should be their values ?
```Amplify.configure({
  Auth: {
    Cognito: {
      loginWith: {
        oauth: {
          redirectSignIn: [
            'http://localhost:3000/',
            'https://www.example.com/'
          ],
          redirectSignOut: [
            'http://localhost:3000/',
            'https://www.example.com/'
          ],
          ...oauthConfig
        }
      },
      ...userPoolConfig
    }
  }
});```


My aws-exports file looks like 

```const awsmobile = {
    "aws_project_region": "eu-west-3",
    "aws_cognito_identity_pool_id": "eu-west-3:bXXXXXXXXXXXXXXXXXXXXX",
    "aws_cognito_region": "eu-west-3",
    "aws_user_pools_id": "eu-west-XXXXXXXXXXX",
    "aws_user_pools_web_client_id": "XXXXXXXXXXXXXX",
    "oauth": {
        "domain": "XXXXXXXXXX-f4c110cd-prod.auth.eu-west-3.amazoncognito.com",
        "scope": [
            "aws.cognito.signin.user.admin",
            "email",
            "openid",
            "phone",
            "profile"
        ],
        "redirectSignIn": "http://localhost:4200/,https://garaweb.XXXXXXXXXX.eu-west-3.cs.amazonlightsail.com/,myapp://callback/",
        "redirectSignOut": "http://localhost:4200/,https://garaweb.XXXXXXXXX.eu-west-3.cs.amazonlightsail.com/,myapp://signout/",
        "responseType": "code"
    },
    "federationTarget": "COGNITO_USER_AND_IDENTITY_POOLS",
    "aws_cognito_username_attributes": [
        "EMAIL"
    ],
    "aws_cognito_social_providers": [
        "FACEBOOK",
        "GOOGLE"
    ],
    "aws_cognito_signup_attributes": [],
    "aws_cognito_mfa_configuration": "OFF",
    "aws_cognito_mfa_types": [],
    "aws_cognito_password_protection_settings": {
        "passwordPolicyMinLength": 8,
        "passwordPolicyCharacters": []
    },
    "aws_cognito_verification_mechanisms": [
        "EMAIL",
        "PHONE_NUMBER"
    ]
};


export default awsmobile;

my amplify version is

    "@aws-amplify/ui-angular": "^5.0.3",
    "@types/crypto-js": "^4.1.2",
    "aws-amplify": "^6.0.6",```
0

There are 0 best solutions below