In this tutorial we will be covering how to add authentication to your React apps using AWS Cognito user pools and the Amplify Framework.
You can test the app here
I used several sources for this.
it was demonstrated with v1 I was able to upgade it to v2
cd .\amplify-react-app npm run build aws s3 sync build/ s3://react.amazoninstructor.info --delete
npm install -g @aws-amplify/cli
npm install react react-dom --save
npx create-react-app name-amplify-react-app
amplify configure
amplify init
The folder amplify is created and a file /src/aws-exports.js.
amplify add auth
amplify push
Open the file /src/App.js
We need to import a couple of things:
replace the import codeblock at the top of the file:
import { Amplify } from 'aws-amplify';
import { withAuthenticator } from '@aws-amplify/ui-react';
import '@aws-amplify/ui-react/styles.css';
import awsExports from './aws-exports';
import React from 'react';
import './App.css'
Amplify.configure(awsExports);
Remove all content between <header classname=App-header>
and </header>
elements.
and replace it by the following:
<div>
<h1>Hello {user.username}{user.emailaddress}</h1>
<p>this is just a test to see if it works</p>
<p>Is it automaticly deployed?</p>
<button class="amplify-button amplify-field-group__control amplify-button--primary" onClick={signOut}>Sign out</button>
</div>
export default withAuthenticator(App);
npm install --save aws-amplify @aws-amplify/ui-react
npm start
Your application should start localy