npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

klg-auth

v2.1.0

Published

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

Downloads

6

Readme

klg-auth

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

只适配 Koa2

##Getting Start

  1. 校验登陆状态
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分钟)
}))
  1. 根据权限控制访问 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: '该用户没有权限执行此操作' }