Giter VIP home page Giter VIP logo

vue-auth-cognito's Introduction

vue-auth-cognito

npm Build Status Code Climate Coverage Status

This small library serves as a wrapper of Amazon Cognito for Vuex.

Actions for dispatch method

All actions return a promise to be able to easily control execution flow.

getCurrentUser

Retrieve current user and save user schema to store.

Returned promise rejects with an error if there is no previously authenticated user:

{
  message: "Can't retrieve current user",
}

authenticateUser

Authenticates a user with username and password.

Usage:

this.$store.dispatch('authenticateUser', {
  username: "[email protected]",
  password: "testbatmanpass"
});

Returned promise resolves with an object with userConfirmationNecessary flag:

this.$store.dispatch('signUp', { ... }).then(({ userConfirmationNecessary }) => { ... })

Returned promise rejects with the following error object:

{
  code: "NotAuthorizedException", // Amazon Cognito error code
  message: "..." // Error message returned from Amazon Cognito servers
}

signUp

Creates user with the following payload:

{
  username: 'test',
  password: 'Qwerty123!',
  attributes: {
    email: '[email protected]',
    name: 'MegaTest',
    phone_number: '+15553334444',
  }
}

You can change username to be any value, for example, an email address or UUID. It's important to know that Amazon Cognito doesn't allow changing username after signing up.

Usage:

this.$store.dispatch('signUp', { ... });

Returned promise resolves with an object with userConfirmationNecessary flag:

this.$store.dispatch('signUp', { ... }).then(({ userConfirmationNecessary }) => { ... })

Returned promise rejects with the following error object:

{
  code: "NotAuthorizedException", // Amazon Cognito error code
  message: "..." // Error message returned from Amazon Cognito servers
}

confirmRegistration

Confirms user registration with username and code:

Usage:

this.$store.dispatch('confirmRegistration', {
  username: 'testusername',
  code: '123456'
});

Returned promise rejects with the following error object:

{
  code: "NotAuthorizedException", // Amazon Cognito error code
  message: "..." // Error message returned from Amazon Cognito servers
}

resendConfirmationCode

Resends user confirmation code:

Usage:

this.$store.dispatch('resendConfirmationCode', {
  username: 'testusername'
});

Returned promise rejects with the following error object:

{
  code: "NotAuthorizedException", // Amazon Cognito error code
  message: "..." // Error message returned from Amazon Cognito servers
}

forgotPassword

Starts forgot password flow:

Usage:

this.$store.dispatch('forgotPassword', {
  username: 'testusername'
});

Returned promise rejects with the following error object:

{
  code: "NotAuthorizedException", // Amazon Cognito error code
  message: "..." // Error message returned from Amazon Cognito servers
}

confirmPassword

Sets a new password with the code received after calling forgotPassword action:

Usage:

this.$store.dispatch('confirmPassword', {
  username: 'testusername',
  code: '123456',
  newPassword: 'qwerty123'
});

Returned promise rejects with the following error object:

{
  code: "NotAuthorizedException", // Amazon Cognito error code
  message: "..." // Error message returned from Amazon Cognito servers
}

changePassword

Only for authenticated users

Changes user password:

Usage:

this.$store.dispatch('changePassword', {
  oldPassword: '123qwerty',
  newPassword: 'qwerty123'
});

Returned promise rejects with the following error object:

{
  code: "NotAuthorizedException", // Amazon Cognito error code
  message: "..." // Error message returned from Amazon Cognito servers
}

updateAttributes

Only for authenticated users

Updates user attributes. Payload is an object where key is an attribute name:

{
  email: 'value',
  phone_number: '[email protected]',
  username: 'batman' // see documentation on Cognito attributes
}

Usage:

this.$store.dispatch('updateAttributes', {
  email: '[email protected]',
  name: 'Bruce',
  phone_number: '+15551234567',
});

Returned promise rejects with the following error object:

{
  code: "NotAuthorizedException", // Amazon Cognito error code
  message: "..." // Error message returned from Amazon Cognito servers
}

signOut

Removes user from the store (for example, $store.cognito.user) and Cognito session from Local Storage.

Returned promise rejects with an error if there is no previously authenticated user:

{
  message: "User is unauthenticated",
}

Build Setup

# install dependencies
npm install

# serve examples with hot reload at localhost:8080
npm run dev

# run all tests
npm test

Credits

vue-auth-cognito's People

Contributors

kesor avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.