react-aws-cognito-auth
TypeScript icon, indicating that this package has built-in type declarations

2.0.3 • Public • Published

React AWS Cognito Auth

React authentication wrapper for AWS Cognito User Pool

Githubnpm

npm version npm downloads Known Vulnerabilities

This library is helper to aws amplify (with Cognito user pool) authentication with react

How To Use

first of all you need to create user pool on aws cognito

https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pool-as-user-directory.html


Provider

On top of your app need to add react-aws-cognito-auth Provider as describe below

First of all you need to import provider

import { ReactCognitoAuthProvider } from 'react-aws-cognito-auth';

Then impliment like this (for example)

<ReactCognitoAuthProvider>
  <React.StrictMode>
    <App />
  </React.StrictMode>
</ReactCognitoAuthProvider>

Configure Amplify

import { ReactCognitoAuthConfig } from 'react-aws-cognito-auth';

And the configuration itself

ReactCognitoAuthConfig({
  region: '###',
  userPoolId: '###',
  userPoolWebClientId: '###',
  idleTime: 10000 // Optinal, time in milliseconds. default = 3600000 (1 hour)
});

That's It! 🚀

Now you can call useAuth wherever you want to use.

import { useAuth } from 'react-aws-cognito-auth';

Uses

🔴 2.0 news

now you can get idle time out. by default JWT token of cognito user is 1 hour.

if the user is idle for 1 hour so auth.idle will be true

you can check if idle and the token is out of date.

if (auth.isIdle()) {
  // do somthing... like popup to reload page
}
const auth = useAuth();

auth.isLoading();
auth.isIdle();
auth.getCurrentUser();
auth.login('username', 'password');
auth.signup('email', 'username', 'password');
auth.confirmSignup('username', 'code');
auth.logout();
auth.resetPassword('username', 'password', 'resetCode');

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.0.30latest

Version History

VersionDownloads (Last 7 Days)Published
2.0.30
2.0.20
2.0.2-s0
2.0.10
2.0.00

Package Sidebar

Install

npm i react-aws-cognito-auth

Weekly Downloads

0

Version

2.0.3

License

MIT

Unpacked Size

28.2 kB

Total Files

10

Last publish

Collaborators

  • mittinga