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
yarn add @adamldoyle/react-aws-auth-context-core
- Configure aws-amplify Auth prior to mounting
<AuthContextProvider>
- Requires Cognito to be configured with:
- email as username
- given_name, family_name, and allow_marketing attributes (none marked as required)
- 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
yarn install
yarn build
Contributors
Adam Doyle
License
MIT