# @what-a-faka/vue-authplugin

> an elegant view auth control plugin

Latest version **0.2.5** (published 2018-12-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install @what-a-faka/vue-authplugin
pnpm add @what-a-faka/vue-authplugin
yarn add @what-a-faka/vue-authplugin
bun add @what-a-faka/vue-authplugin
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.5 |
| Published | 2018-12-17 |
| First published | 2018-12-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 24.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | vv13 |
| Maintainers | zwhvv13 |
| Keywords | vue auth, permission |

## Links

- npm: https://www.npmjs.com/package/@what-a-faka/vue-authplugin
- Repository: https://github.com/vv13/vue-authplugin
- Homepage: https://github.com/vv13/vue-authplugin#readme
- Issues: https://github.com/vv13/vue-authplugin/issues
- npm.io page: https://npm.io/package/@what-a-faka/vue-authplugin

## Alternatives

- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads
- [escher-request](https://npm.io/package/escher-request.md) — 545 weekly downloads

## Recent versions

- 0.2.5 (latest) — 2018-12-17
- 0.2.4 — 2018-12-17
- 0.1.3 — 2018-12-14
- 0.1.2 — 2018-12-13
- 0.1.1 — 2018-12-13

## README

> 原仓库：[https://github.com/vv13/vue-authplugin](https://github.com/vv13/vue-authplugin)

# vue-authplugin
用于视图权限显示控制的一款轻量级Vue Plugin，支持指令、原型链等方法。

## 安装
```
$ npm install vue-authplugin
```

## 示例

```
import authPlugin from 'vue-authplugin'

Vue.use(authPlugin, {
    authCode: [101, 102, 103, 104, 105],
    authMap: new Map([
      ['AUTH_LOGIN', 101],
      ['AUTH_SUBMIT', [102, 103]],
    ])
})
```
在初始化完成后，即可使用指令或原型链的形式调用验证方法：
```
<template>
  <!-- show Login btn if 101 is exists -->
  <button v-auth="'101'">Login</button>
  <!-- AUTH_LOGIN is Map to 101 -->
  <button v-auth="'AUTH_LOGIN'">Login</button>

  <!-- show Submit1 btn if 102 or 103 is exists -->
  <button v-auth="[102, 103]">Submit1</button>
  <button v-auth="'AUTH_SUBMIT'">Submit2</button>

  <!-- show Fetch btn if 105:exist and 106:miss -->
  <button v-if"$_auth.verify({105: true, 106: false})">Fetch</button>
</template>
```
### 使用规则
验证权限参数十分灵活，具体有以下形式可使用：
- 传入String，检测权限表是否包含此权限
- 传入Array，检测权限表是否包含数组中的任意一个权限
- 传入Object，检测所有键值是否都通过校验，key为权限名称，value为是否需要此权限
- 传入映射名称，即authMap的Key，则实际检测对象为映射值


## 用法
使用this.$_auth.verify验证成功或失败，则会返回true或false；使用指令形式，验证成功，则会在dom方法上添加data-auth="success"属性，验证失败，则会添加data-auth="fail"，并设置display: none。

### 初始化
在使用Vue.use(authPlugin, options)时，options的各个选项为：

| key      | desc                      | type          | default | required |
| :------- | ------------------------- | ------------- | ------- | -------- |
| name     | 指令名与Vue原型链上的键名 | String        | auth    | false    |
| authCode | 权限表                    | Array \| Map  | []      | true     |
| authMap  | 权限验证映射表            | Object \| Map | {}      | false    |

### API
#### updateAuthCode(authCode)
- 参数
  - { Array | Map } authCode

在初始化插件以后，有时权限表会更改，这是可通过此方法来进行更新。记得在组件初始化之前调用此方法。

#### verify(code)
- 参数
  - {String | Object | Array} code
- 返回值：true or false

查找权限表，验证所需权限是否满足，若满足则返回true，否则返回false。

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