Deploy and Test Cognito Cross Sites

Configure Cognito Environment

  1. Create a app/.env.local file for app1 and app2 with the following content:
REACT_APP_USERPOOL_ID=YOUR_USER_POOL_ID
REACT_APP_CLIENT_ID=YOUR_CLIENT_ID

Cognito

  1. Use Create React App to set up the development process:
    • The next steps will be familiar.
  2. Install and run web1 on port 3000:
cd app
npm install --force
npm start

Note: For MacBook, adjust the package.json file in the app directory as follows:

"scripts": {
  "start": "PORT=3000 && react-scripts start",
  ...
},

Cognito

  1. Install and run web2:
cd app2
npm install --force
npm start

Cognito

  1. After initializing web 1, you access web1 via localhost:3000

    • Then, you log in, select SIGN IN WEB1

Cognito

  1. In the web1 login interface, if you do not have an account, select Register a new account. If you already have an account, fill in all the information and select SIGN IN

Cognito

  1. Successful login, the interface looks like the image.

Cognito

  1. Then access web2 via the address localhost:3001

    • You will be surprised because you do not need to log in to still see the web2 interface (remember to hit load or f5 if you do not see the web2 interface).

Cognito

  1. Go back to the web1 interface and log out by selecting SIGN OUT WEB1

Cognito

  1. When you reload the web2 page, you will no longer be able to see the web2 interface.

Cognito