🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more
Socket
Book a DemoInstallSign in
Socket

klg-auth

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

klg-auth

用于考拉用户登陆校验和简单的权限控制

latest
npmnpm
Version
2.1.0
Version published
Maintainers
1
Created
Source

klg-auth

用于考拉用户登陆校验和简单的权限控制

只适配 Koa2

##Getting Start

  • 校验登陆状态
const auth = require('klg-auth')
app.use(auth.validate({
  errHandle: async function (ctx) {
    console.log('授权错误')
    // 检测到用户没有登陆时会触发此 handle
    // 跳转到SSO的登陆页面或者 返回url给前端跳转
    ctx.body = {
      code: 1,
      message: '授权错误',
      url: 'http://'
    }
    ctx.status = 200
  },
  cookieDomain: 'localhost' // 更新cookie domain
  cookieMaxAge: 30 * 60 * 1000 // 更新cookie时间(30分钟)
}))
  • 根据权限控制访问 demo: 在 router 里添加
import { allow } from 'klg-auth'
router.get('/user/:username', allow('管理员', '开发'), UserController.getUserByName)

allow('管理员', '开发') 表示此 url 只允许 管理员 和 开发 角色访问 非以上角色访问会默认返回(后面会开放自定义处理函数): 200

{ code: 1, message: '该用户没有权限执行此操作' }

ban('实习') 表示此 url 不允许 实习 角色访问 非以上角色访问会默认返回:200

{ code: 1, message: '该用户没有权限执行此操作' }

Keywords

auth

FAQs

Package last updated on 23 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts