0.0.7 • Published 8 years ago
vue-identity v0.0.7
vue-identity
vue-identity is a vue plugin that uses JSON Web Tokens to make authentication easy.
Installation
NPM
$ npm install vue-identityExample
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.