All Projects → kopterio → Vue Auth Cognito

kopterio / Vue Auth Cognito

A Vue.js Vuex module for authentication using Amazon AWS Cognito

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Vue Auth Cognito

Iview Vue Admin
iView vue Admin / An admin management system template
Stars: ✭ 105 (-8.7%)
Mutual labels:  vuex
Vue Meizi
vue最新实战项目,vue2 + vuex + webpack + es6 干货多多,新手福利
Stars: ✭ 1,476 (+1183.48%)
Mutual labels:  vuex
Seemusic
Vue 云音乐播放器,网易云音乐API,可听网易云高品质付费歌曲。 Vue music player
Stars: ✭ 112 (-2.61%)
Mutual labels:  vuex
Vue Cli Multipage Bootstrap
vue-cli-multipage-bootstrap demo with vue2+vue-router+vuex+bootstrap+markdown for learning vue2.0
Stars: ✭ 105 (-8.7%)
Mutual labels:  vuex
Vue2 Elm
基于 vue2 + vuex 构建一个具有 45 个页面的大型单页面应用
Stars: ✭ 37,325 (+32356.52%)
Mutual labels:  vuex
Vlackjack
Blackjack built with Vue.js and vuex
Stars: ✭ 109 (-5.22%)
Mutual labels:  vuex
Vue2 Shop
A shop developed with Vue2 + Vue-router + Axios + Vuex + Node + Express + MongoDB + Webpack
Stars: ✭ 103 (-10.43%)
Mutual labels:  vuex
Vue Ruby China
使用Vue.js框架搭建的ruby china山寨版,集成vue-router+vuex等
Stars: ✭ 113 (-1.74%)
Mutual labels:  vuex
Vue Crypto Dashboard
Cryptocurrency Dashboard made with Vue
Stars: ✭ 107 (-6.96%)
Mutual labels:  vuex
Mpvue Vuex Demo
用mpvue构建的小程序-vue模板项目,还引入了vuex,sass,flyio等
Stars: ✭ 112 (-2.61%)
Mutual labels:  vuex
Webchat
A realtime chat for web
Stars: ✭ 106 (-7.83%)
Mutual labels:  vuex
Vue Laravel Spa
Single Page Application made with Vue.JS2, Vue Router, Vuex and Laravel 5.6.
Stars: ✭ 107 (-6.96%)
Mutual labels:  vuex
Electron Vue Cloud Music
🚀Electron + Vue 仿网易云音乐windows客户端
Stars: ✭ 1,894 (+1546.96%)
Mutual labels:  vuex
Vue Mobile Starter
☘ A starter project structure for Vue.js app.
Stars: ✭ 105 (-8.7%)
Mutual labels:  vuex
Vue Mobile Cli
🚀 Vue移动端多页应用脚手架
Stars: ✭ 112 (-2.61%)
Mutual labels:  vuex
Multivisor
Centralized supervisor WebUI and CLI
Stars: ✭ 104 (-9.57%)
Mutual labels:  vuex
Ruoyi Vue Fast
(RuoYi)官方仓库 基于SpringBoot,Spring Security,JWT,Vue & Element 的前后端分离权限管理系统
Stars: ✭ 107 (-6.96%)
Mutual labels:  vuex
Vuex Module Decorators
TypeScript/ES7 Decorators to create Vuex modules declaratively
Stars: ✭ 1,714 (+1390.43%)
Mutual labels:  vuex
Learn Vuex
🗂Source code for the Vuex for Everyone course
Stars: ✭ 113 (-1.74%)
Mutual labels:  vuex
Vue Generator
A CLI generator for Vue components, views and store modules
Stars: ✭ 111 (-3.48%)
Mutual labels:  vuex

vue-auth-cognito

npm Build Status Code Climate Coverage Status Greenkeeper Badge

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

As pointed out in #65 the aws-amplify/amplify-js project officially supported by AWS has Vue.js integration. The example project is at aws-samples/aws-amplify-vue.

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",
}

Examples

Before checking examples, please copy examples/.env.example to examples/.env and add the correct AWS crendentials to it.

npm start command uses node-foreman package to run both API and Vue.js front-end servers.

cd examples

# install dependencies
npm install

# serve API server and examples with hot reload at localhost
npm start

UUID

Cognito's username could be anything: email, a randomly generated integer, UUID, etc. It cannot be changed later so it's wise to use something unique like UUID and use attributes to keep email addresses, phone numbers and other information.

For now, Cognito doesn't support some features like resending confirmation code using email attribute. It requires a username for that operation and it could be a problem if it's a generated UUID. We can potentially keep username in localStorage or a cookie but it can easily be lost if a user switches computers or browsers.

That's why we need a little API endpoint to convert an email address stored in email attribute to a username by using Cognito API. You can find an example server in examples/servers/index.js.

Tests

# run all tests
npm test

Credits

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].