Vue.js 3的轻量级身份验证库 - vue-auth

Vue.js 3的轻量级身份验证库 - vue-auth
插件名称 vue-auth
发布时间 2020年11月19日
插件作者 websanova

一个简单而轻巧的身份验证库,可简化Vue.js 2或Vue.js 3应用程序的身份验证任务。

安装和下载:

# NPM
$ npm i @websanova/vue-auth --save

基本用法:

1.将必要的组件导入您的应用程序。

import {createApp} from 'vue';
import {createRouter} from 'vue-router';
import axios from 'axios';
import App from 'App.vue';
import {createAuth} from '@websanova/vue-auth';
import driverAuthBearer from '@websanova/vue-auth/dist/drivers/auth/bearer.esm.js';
import driverHttpAxios from '@websanova/vue-auth/dist/drivers/http/axios.1.x.esm.js';
import driverRouterVueRouter from '@websanova/vue-auth/dist/drivers/router/vue-router.2.x.esm.js';
import driverOAuth2Google from '@websanova/vue-auth/dist/drivers/oauth2/google.esm.js';
import driverOAuth2Facebook from '@websanova/vue-auth/dist/drivers/oauth2/facebook.esm.js';

2.基本用法:

var router = createRouter({
    ...
})
var auth = createAuth({
    plugins: {
        http: axios,
        router: router
    },
    drivers: {
        http: driverHttpAxios,
        auth: driverAuthBearer,
        router: driverRouterVueRouter,
        oauth2: {
            google: driverOAuth2Google,
            facebook: driverOAuth2Facebook,
        }
    },
    options: {
        rolesKey: 'type',
        notFoundRedirect: {name: 'user-account'},
    }
});
createApp(App)
    .use(router)
    .use(auth)
    .mount('#app');