Last active
March 20, 2020 15:18
-
-
Save lakshya-sky/4e663f70c30f23f2ec4054902794b232 to your computer and use it in GitHub Desktop.
Connect React with AWS Cognito.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
yarn add aws-amplify aws-amplify-react | |
*/ | |
/* Add Imports */ | |
import Amplify, { Auth } from "aws-amplify"; | |
import { withAuthenticator } from "aws-amplify-react"; | |
/* Add following code outside App component */ | |
Amplify.configure({ | |
Auth: { | |
mandatorySignIn: false, | |
region: 'us-east-1', | |
userPoolId: '<poolID>', | |
identityPoolId: '<identityPoolId>', | |
userPoolWebClientId: '<clientID>', | |
} | |
}); | |
const signUpConfig = { | |
hideAllDefaults: true, | |
signUpFields: [ | |
{ | |
label: "Email", | |
key: "email", | |
required: true, | |
displayOrder: 1, | |
type: "string" | |
}, | |
{ | |
label: "Password", | |
key: "password", | |
required: true, | |
displayOrder: 2, | |
type: "password" | |
} | |
] | |
}; | |
const usernameAttributes = "email"; | |
/* Replace export default App with following snippet */ | |
export default withAuthenticator(App, { | |
signUpConfig, | |
usernameAttributes | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment