@adamldoyle/react-aws-auth-context-core
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

react-aws-auth-context-core

React context for managing authentication flow with AWS. Provides core functionality and relies on separate libraries to implement components that match API.

Usage

  1. yarn add @adamldoyle/react-aws-auth-context-core
  2. Configure aws-amplify Auth prior to mounting <AuthContextProvider>
  3. Requires Cognito to be configured with:
    • email as username
    • given_name, family_name, and allow_marketing attributes (none marked as required)
  4. Wrap portion of app that requires authentication in <AuthContextProvider> (normal usage would be to wrap entire app near the top-level) and provide components for UI (other libraries may provide an equivalent <AuthContextProvider> with the components already wired in)

Component providers

The following libraries provide <AuthContextProvider> as well as components for the entire workflow.

Examples

<AuthContextProvider
   sessionPingDelay={30}
   SignInForm={SignInForm}
   SignUpForm={SignUpForm}
   SignOut={SignOut}
   ForgotPasswordForm={ForgotPasswordForm}
   ResetPasswordForm={ResetPasswordForm}
   ConfirmAccountForm={ConfirmAccountForm}
>
   <AuthContext.Consumer>
   {({ session, signOut }) => (
      <>
         <span>Authenticated</span>
         <span>ID: {session.getIdToken?.().getJwtToken?.()}</span>
         <span>Access: {session.getAccessToken?.().getJwtToken?.()}</span>
         <button type="button" onClick={signOut}>Sign out</button>
      </>
   )}
   </AuthContext.Consumer>
</AuthContextProvider>

Development

  1. yarn install
  2. yarn build

Contributors

Adam Doyle

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i @adamldoyle/react-aws-auth-context-core

Weekly Downloads

3

Version

1.0.0

License

MIT

Unpacked Size

74 kB

Total Files

9

Last publish

Collaborators

  • adamldoyle