s4nt14go / react-cognito

React using Cognito authentication 👮

Home Page:https://react-cognito.netlify.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

React using Cognito authentication 👮

Description

In repo react-starter branch auth0 I showed how can be used Auth0 for authentication. In the case you prefer AWS Cognito you can check here how can be done.

Features:

  • AWS Amplify to comunicate with Cognito
  • AmplifyAuthenticator component from library @aws-amplify/ui-react
  • React.useContext to hold authentication state and data
  • Components AuthenticatedRoute and UnauthenticatedRoute protect routes according user authentication state
  • Redirect: If an unauthenticated user tries to go to an AuthenticatedRoute, first is directed to login and once logged in, it redirects to the intended page

auth.gif

Instructions

  1. Use Node 14 version, using nvm you can:

    # set Node 14 in current terminal
    nvm use 14
    # set Node 14 as default (new terminals will use 14)
    nvm alias default 14
    
  2. Install dependencies

    npm ci
  3. Deploy your Cognito user and identity pool dev stage as in this repo. Once that is deployed you will need to set their values in your .env.local file:

     REACT_APP_STAGE=dev
     REACT_APP_dev_COGNITO_REGION=<your_data>
     REACT_APP_dev_COGNITO_USER_POOL_ID=<your_data>
     REACT_APP_dev_COGNITO_APP_CLIENT_ID=<your_data>
     REACT_APP_dev_COGNITO_IDENTITY_POOL_ID=<your_data>

    In the case you change these env vars, you have to restart your React server and refresh the page in order to have them refreshed.

  4. Run the app

    npm start

About

React using Cognito authentication 👮

https://react-cognito.netlify.app


Languages

Language:TypeScript 84.5%Language:JavaScript 8.0%Language:HTML 6.4%Language:CSS 1.1%