1.0.0 • Published 3 years ago

jsonwebtoken2021 v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

const jwt = require('jsonwebtoken')

const whiteList = '/loagin', '/regiest', '/gitee_userinfo', '/loagin2'

module.exports = () => {

return async (ctx, next) => {

    if (whiteList.includes(ctx.path)) {

        await next()

    } else {

        const { token } = ctx.headers

        if (!token) {

            ctx.body = {
                code: 401,
                msg: '没有权限'
            }

        }

        try {
            jwt.verify(token, ctx.app.config.keys)

            await next()

        } catch (error) {

            ctx.body = {
                code: 403,
                msg: '校验失败'
            }
        }
    }
}

}