# @dsbn/vue-auth

> ```bash npm i -S @dsbn/vue-auth ```

Latest version **0.0.13** (published 2019-09-26) · 0 weekly downloads

## Install

```sh
npm install @dsbn/vue-auth
pnpm add @dsbn/vue-auth
yarn add @dsbn/vue-auth
bun add @dsbn/vue-auth
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.13 |
| Published | 2019-09-26 |
| First published | 2018-05-23 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 33.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | saltyquark, xori |

## Links

- npm: https://www.npmjs.com/package/@dsbn/vue-auth
- npm.io page: https://npm.io/package/@dsbn/vue-auth

## Recent versions

- 0.0.13 (latest) — 2019-09-26
- 0.0.12 — 2019-09-26
- 0.0.11 — 2018-11-30
- 0.0.10 — 2018-10-26
- 0.0.9 — 2018-10-26
- 0.0.8 — 2018-10-25
- 0.0.7 — 2018-07-12
- 0.0.6 — 2018-05-23
- 0.0.5 — 2018-05-23
- 0.0.4 — 2018-05-23
- 0.0.3 — 2018-05-23
- 0.0.2 — 2018-05-23
- 0.0.1 — 2018-05-23

## README

# @dsbn/vue-auth

## Usage
```bash
npm i -S @dsbn/vue-auth
```

```js
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'] } }
}
```

---
_Source: https://npm.io/package/@dsbn/vue-auth · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
