npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-auths

v0.0.2-beta-1

Published

Authentication library for Vue.js

Downloads

4

Readme

[WARNING]: README file is currently in process of rewrite and will be released soon.

vue-auths

vue-auth is easily configurable solution for Vue.js that provides local login/registration as well as Social login using Github, Facebook, Google and other OAuth providers.

The best part about this library is that it is not strictly coupled to one request handling library like vue-axios. You will be able to use it with different libraries.

For now it is tested to work with vue-resource and axios (using vue-axios wrapper).

WARNING: From version 1.3.0 default request library is axios using vue-axios wrapper plugin.

This library was inspired by well known authentication library for Angular called Satellizer developed by Sahat Yalkabov. They share almost identical configuration and API so you can easily switch from Angular to Vue.js project.

Supported OAuth providers and configurations

  1. Facebook (https://github.com/Chantouch/vue-auth/blob/master/src/options.js#L21)
  2. Google (https://github.com/Chantouch/vue-auth/blob/master/src/options.js#L34)
  3. Github (https://github.com/Chantouch/vue-auth/blob/master/src/options.js#L49)
  4. Instagram (https://github.com/Chantouch/vue-auth/blob/master/src/options.js#L61)
  5. Twitter (https://github.com/Chantouch/vue-auth/blob/master/src/options.js#L72)
  6. Bitbucket (https://github.com/Chantouch/vue-auth/blob/master/src/options.js#L81)
  7. LinkedIn (https://github.com/Chantouch/vue-auth/blob/master/src/options.js#L93)
  8. Microsoft Live (https://github.com/Chantouch/vue-auth/blob/master/src/options.js#L106)

Installation

npm install vue-auths

yarn add  vue-auths

Usage

import Vue from 'vue'
import VueAxios from 'vue-axios'
import VueAuthenticate from 'vue-auths'
import axios from 'axios';

Vue.use(VueAxios, axios)
Vue.use(VueAuthenticate, {
  baseUrl: 'http://localhost:3000', // Your API domain
  
  providers: {
    github: {
      clientId: '',
      redirectUri: 'http://localhost:8080/auth/callback' // Your client app URL
    }
  }
})

Email & password login and registration

new Vue({
  methods: {
    login: function () {
      this.$auth.login({ email, password }).then(function () {
        // Execute application logic after successful login
      })
    },

    register: function () {
      this.$auth.register({ name, email, password }).then(function () {
        // Execute application logic after successful registration
      })
    }
  }
})
<button @click="login()">Login</button>
<button @click="register()">Register</button>

Social account authentication

new Vue({
  methods: {
    auth: function (provider) {
      this.$auth.auth(provider).then(function () {
        // Execute application logic after successful social authentication
      })
    }
  }
})
<button @click="auth('github')">auth Github</button>
<button @click="auth('facebook')">auth Facebook</button>
<button @click="auth('google')">auth Google</button>
<button @click="auth('twitter')">auth Twitter</button>

Vuex authentication

Import and initialize all required libraries

// ES6 example
import Vue from 'vue'
import Vuex from 'vuex'
import VueAxios from 'vue-axios'
import { VueAuthenticate } from 'vue-auths'
import axios from 'axios';

Vue.use(Vuex)
Vue.use(VueAxios, axios)

const vueAuth = new VueAuthenticate(Vue.prototype.$http, {
  baseUrl: 'http://localhost:4000'
})
// CommonJS example
var Vue = require('vue')
var Vuex = require('vuex')
var VueAxios = require('vue-axios')
var VueAuthenticate = require('vue-auths')
var axios = require('axios');

Vue.use(Vuex)
Vue.use(VueAxios, axios)

// ES5, CommonJS example
var vueAuth = VueAuthenticate.factory(Vue.prototype.$http, {
  baseUrl: 'http://localhost:4000'
})

Once you have created VueAuthenticate instance, you can use it in Vuex store like this:

export default new Vuex.Store({
  
  // You can use it as state property
  state: {
    isAuthenticated: false
  },

  // You can use it as a state getter function (probably the best solution)
  getters: {
    isAuthenticated () {
      return vueAuth.isAuthenticated()
    }
  },

  // Mutation for when you use it as state property
  mutations: {
    isAuthenticated (state, payload) {
      state.isAuthenticated = payload.isAuthenticated
    }
  },

  actions: {

    // Perform VueAuthenticate login using Vuex actions
    login (context, payload) {

      vueAuth.login(payload.user, payload.requestOptions).then((response) => {
        context.commit('isAuthenticated', {
          isAuthenticated: vueAuth.isAuthenticated()
        })
      })

    }
  }
})

Later in Vue component, you can dispatch Vuex state action like this

// You define your store logic here
import store from './store.js'

new Vue({
  store,

  computed: {
    isAuthenticated: function () {
      return this.$store.getters.isAuthenticated()
    }
  },

  methods: {
    login () {
      this.$store.dispatch('login', { user, requestOptions })
    }
  }
})

Custom request and response interceptors

You can easily setup custom request and response interceptors if you use different request handling library.

Important: You must set both request and response interceptors at all times.


/**
* This is example for request and response interceptors for axios library
*/

Vue.use(VueAuthenticate, {
  bindRequestInterceptor: function () {
    this.$http.interceptors.request.use((config) => {
      if (this.isAuthenticated()) {
        config.headers['Authorization'] = [
          this.options.tokenType, this.getToken()
        ].join(' ')
      } else {
        delete config.headers['Authorization']
      }
      return config
    })
  },

  bindResponseInterceptor: function () {
    this.$http.interceptors.response.use((response) => {
      this.setToken(response)
      return response
    })
  }
})

License

The MIT License (MIT)

Copyright (c) 2017 Chantouch Sek

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.