Skip to content

mattfroese/vue-identity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vue-identity

vue-identity is a vue plugin that uses JSON Web Tokens to make authentication easy.

Installation

NPM

$ npm install vue-identity

Example

import VueIdentity from 'vue-identity'
Vue.use(VueIdentity, {
    url: "/auth", // full url to your auth endpoint
})

Authenticate

This will ask the server for an accessToken by passing it a refreshToken. Cookies are sent with this request if you prefer.

this.$identity.authenticate().then(function(){ console.log( "Logged in!" ) })

Login

Request a new accessToken and refreshToken by passing credentials to the server. Credentials are sent as parameters of login and are POSTed to the server.

this.$identity.login({user: "salty",password:"quark"}).then(function(){ console.log( "Logged in!" ) })

In your html, you can access the user state

<div v-if="$identity.user">
  <p>Hello {{$identity.user.name}}</p>
</div>

Vue Resource Interceptor

After authenticating, an interceptor is added to vue-resource that sends the accessToken in the Authorization header as a Bearer token.

Documentation

License

MIT

About

Simple Json Web Tokens (JWT) authentication system in Vue.

Resources

License

Stars

Watchers

Forks

Packages

No packages published