0.0.13 • Published 6 years ago

@dsbn/vue-auth v0.0.13

Weekly downloads
8
License
-
Repository
-
Last release
6 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

6 years ago

0.0.12

6 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago