I can not generate aws-exports.js file using existing User Pool of AWS Cognito. How to do it?
I tried to generate aws-exports.js file with creating new User Pool of AWS Cognito. But it is not correct thing that I want. Also, I found some explanation of problem on github:
I can not generate aws-exports.js file using existing User Pool of AWS Cognito. How to do it?
I tried to generate aws-exports.js file with creating new User Pool of AWS Cognito. But it is not correct thing that I want. Also, I found some explanation of problem on github: https://github.com/aws-amplify/amplify-cli/issues/779#issuecomment-458080804
Share Improve this question asked Jun 5, 2019 at 14:41 Bulat UsmanovBulat Usmanov 5131 gold badge5 silver badges13 bronze badges 1- Have you read this? medium.com/@danielcender/… It should help. – yiksanchan Commented Jun 6, 2019 at 0:06
4 Answers
Reset to default 14From this page in the docs:
If you want to re-use an existing authentication resource from AWS (e.g. Amazon Cognito UserPool or Identity Pool), update Amplify.configure() method with the following information.
import Amplify, { Auth } from 'aws-amplify';
Amplify.configure({
Auth: {
// REQUIRED only for Federated Authentication - Amazon Cognito Identity Pool ID
identityPoolId: 'XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab',
// REQUIRED - Amazon Cognito Region
region: 'XX-XXXX-X',
// OPTIONAL - Amazon Cognito Federated Identity Pool Region
// Required only if it's different from Amazon Cognito Region
identityPoolRegion: 'XX-XXXX-X',
// OPTIONAL - Amazon Cognito User Pool ID
userPoolId: 'XX-XXXX-X_abcd1234',
// OPTIONAL - Amazon Cognito Web Client ID (26-char alphanumeric string)
userPoolWebClientId: 'a1b2c3d4e5f6g7h8i9j0k1l2m3',
// OPTIONAL - Enforce user authentication prior to accessing AWS resources or not
mandatorySignIn: false,
// OPTIONAL - Configuration for cookie storage
// Note: if the secure flag is set to true, then the cookie transmission requires a secure protocol
cookieStorage: {
// REQUIRED - Cookie domain (only required if cookieStorage is provided)
domain: '.yourdomain.com',
// OPTIONAL - Cookie path
path: '/',
// OPTIONAL - Cookie expiration in days
expires: 365,
// OPTIONAL - See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite
sameSite: "strict" | "lax",
// OPTIONAL - Cookie secure flag
// Either true or false, indicating if the cookie transmission requires a secure protocol (https).
secure: true
},
// OPTIONAL - customized storage object
storage: MyStorage,
// OPTIONAL - Manually set the authentication flow type. Default is 'USER_SRP_AUTH'
authenticationFlowType: 'USER_PASSWORD_AUTH',
// OPTIONAL - Manually set key value pairs that can be passed to Cognito Lambda Triggers
clientMetadata: { myCustomKey: 'myCustomValue' },
// OPTIONAL - Hosted UI configuration
oauth: {
domain: 'your_cognito_domain',
scope: ['phone', 'email', 'profile', 'openid', 'aws.cognito.signin.user.admin'],
redirectSignIn: 'http://localhost:3000/',
redirectSignOut: 'http://localhost:3000/',
responseType: 'code' // or 'token', note that REFRESH token will only be generated when the responseType is code
}
}
});
// You can get the current config object
const currentConfig = Auth.configure();
You don't need to generate the code. You can simply add this code to the index.js
or App.js
file.
#react-native #aws-cognito
import { Amplify } from 'aws-amplify';
Amplify.configure({
Auth: {
identityPoolId: xx-xxxx-x:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,
region: xx-xxxx-x,
userPoolId: xx-xxxx-x_xxxxxxxxx,
userPoolWebClientId: xxxxxxxxxxxxxxxxxxxxxxxxxx,
}});
/**
* You can get this ID's from AWS console panel.
* identityPoolId - AWS > Cognito > Federated Identities > Select the identity pool > Sample code > Get AWS Credentials.
* region - xx-xxxx-x
* userPoolId - AWS > Cognito > User pools (Select the user pool) > User pool ID
* userPoolWebClientId - AWS > Cognito > User pools (Select the user pool) > Select App Integration tab > App client list > Select the App client name > Client ID
*/
Try running from the command line in your project directory:
amplify import auth
and then after you go through the steps to import an existing user pool, run:
amplify push
and your aws-exports.js file will get updated with the right connection params.
You can do it: Amplify.configure({ Auth: { identityPoolId: 'xxxxxx', region: 'xxxxx', userPoolId: 'xxxxxxx', userPoolWebClientId: 'xxxxx' } });