@dragonchain-dev/cognito-wrapper

6.0.6 • Public • Published

"The Doorman"

This cognito wrapper can be added to any project.

Installation

To use this, open the application you would like to use it in and run this command after npm install. This command will also have to be added to your build spec file after npm install.

  • aws s3 cp s3://cognito-wrapper/ node_modules/cognito-wrapper/ --recursive

The necessary role permission for your project is : { "Effect": "Allow", "Resource": [ "arn:aws:s3:::cognito-wrapper", "arn:aws:s3:::cognito-wrapper/" ], "Action": [ "s3:" ] }

Install via NPM like so:

npm install git+ssh://git@github.com:dragonchain-inc/cognito_wrapper.git

or add this to package.json dependencies

"cognito-wrapper": "git+ssh://git@github.com/dragonchain-inc/cognito_wrapper.git",

Publish to NPM Registry

Execute the commands locally:

npm config set 'https://registry.npmjs.org/:_authToken' '${SUPER_SECRET_PUBLISH_TOKEN}'
npm publish

Token Behavior

Once you authenticate, your session token will remain active for one hour. After that hour expires, as long as you have not explicitly logged out, you will be refreshed automatically. The refresh token lasts for 30 days at which point the user will have to login again.

Use

once this code is in your project, create a new instance of the cognito api class like:

import CognitoApi from 'wherever this imported code lives';

const Cognito = new CognitoApi(
  COGNITO_USER_POOL_ID,
  COGNITO_CLIENT_ID,
  COGNITO_REGION,
  COGNITO_IDENTITY_POOL_ID,
  COGNITO_LOGINS_ADDRESS
)

These values must be provided! If you do not have these values, you must go to AWS "Cognito" and create a new user pool and federated identity.

methods:

Exposed methods and params as MOBX store methods:

  @action signUp = (email: string, password: string) => {
    Cognito.signUp(email, password)
      .then(console.log('Signed Up')) // eslint-disable-line
      .catch(new Error());
  }

  @action verifyEmail = (email: string, verificationCode: string) => {
    Cognito.verifyRegistration(email, verificationCode)
      .then(console.log('email verified')) // eslint-disable-line
      .catch(new Error());
  }

  @action login = (email: string, password: string) => {
    Cognito.login(email, password);
      .then(console.log('Logged In')) // eslint-disable-line
      .catch(new Error());
  }

  @action logout = () => Cognito.logout();

  @action checkSession = () => Cognito.checkSession();

  const getCurrentUserObject = (email: string) => Cognito.getCurrentUserObject(email);
  const getSessionDetails = (email: string, password: string) => Cognito.getAuthenticationDetails(email, password);

Package Sidebar

Install

npm i @dragonchain-dev/cognito-wrapper

Weekly Downloads

1

Version

6.0.6

License

ISC

Unpacked Size

134 kB

Total Files

19

Last publish

Collaborators

  • taw1313
  • dragonchain-service-user