Skip to content

Instantly share code, notes, and snippets.

@lakshya-sky
Last active March 20, 2020 15:18
Show Gist options
  • Save lakshya-sky/4e663f70c30f23f2ec4054902794b232 to your computer and use it in GitHub Desktop.
Save lakshya-sky/4e663f70c30f23f2ec4054902794b232 to your computer and use it in GitHub Desktop.
Connect React with AWS Cognito.
/*
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