0.0.13 • Published 5 years ago

@dsbn/vue-auth v0.0.13

Weekly downloads
8
License
-
Repository
-
Last release
5 years ago

@dsbn/vue-auth

Usage

npm i -S @dsbn/vue-auth
import Auth from '@dsbn/vue-auth'

Vue.use(Auth, {
  router,
  url: 'https://api.dsbn.org/auth/v1',
  loginUrl: `/login/app-slug`,
  refreshUrl: `/refresh/app-slug`,
  unauthorizedRedirect: '/unauthorized',
  failedRedirect: '/authorizefailure',
  cookie: true,
  interceptor: false
})

Vue

vue-auth exposes a global $auth object for your vue components. This gives you access to the reactive user prop along with some methods.

Props

$auth.user

This contains the decoded payload passed by the server along with an authenticating variable to determine if the user is being fetched.

user = {
    authenticating: false,
    token: 'eyJ...'
    name: '',
    username: '',
    email: '',
    ..etc
}

Methods

$auth.authenticated()

Returns a promise to resolve the users current authentication status.

$auth.isValid( token )

Checks if the current token is valid. Returns true|false

$auth.isRole( role1, role2, ... )

Checks if user has any of the passed roles. Returns true|false

$auth.isUser( username1, username2, ... )

Checks if user is any of the passed users. Returns true|false

Vue-router

To safeguard your routes and check user authorization before navigating apply { auth: true in the meta prop of the desired route. You can also check roles and specific users:

{
	path: '/restricted-to-users',
	meta: { auth: true }
}

Only developers or monkeys

{
	path: '/restricted-to-dev-monkeys',
	meta: {	auth: { role: ['Developer','Monkey'] } }
}

Only linus

{
	path: '/restricted-to-dev-monkeys',
	meta: {	auth: { user: ['linus'] } }
}
0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago