Compare commits

..

3 Commits
v2 ... master

Author SHA1 Message Date
yutent 7fbf720e62 优化jwt验证方式 2024-07-11 11:47:36 +08:00
yutent 655c5e34fa update 2023-11-01 15:51:45 +08:00
yutent 52b8e3553e 更新readme 2023-11-01 14:26:18 +08:00
3 changed files with 8 additions and 6 deletions

View File

@ -1,12 +1,14 @@
![module info](https://nodei.co/npm/@gm5/controller.png?downloads=true&downloadRank=true&stars=true) ![downloads](https://img.shields.io/npm/dt/@gm5/controller.svg)
![version](https://img.shields.io/npm/v/@gm5/controller.svg)
# @gm5/controller # @gm5/controller
> 控制器基类。 > 控制器基类。
## 安装 ## 安装
> 一般不需要单独安装, 该模块包含在`@gm5/core`的依赖里。
```bash ```bash
npm install @gm5/controller npm i @gm5/controller
``` ```

View File

@ -30,10 +30,10 @@ export default class Controller {
let { __mix_key__ } = this.request let { __mix_key__ } = this.request
return this.context.$$jwt.sign(data, __mix_key__) return this.context.$$jwt.sign(data, __mix_key__)
}, },
verify: () => { verify: token => {
this.#auth = null this.#auth = null
let token = this.request.header('authorization')
let { __mix_key__ } = this.request let { __mix_key__ } = this.request
token ??= this.request.header('authorization')
if (token) { if (token) {
this.#auth = this.context.$$jwt.verify(token, __mix_key__) this.#auth = this.context.$$jwt.verify(token, __mix_key__)
@ -94,7 +94,7 @@ export default class Controller {
this.response.cookie(key, val, opt) this.response.cookie(key, val, opt)
} }
// 会话读写 // 会话读写, 返回的是Promise对象
session(key, val) { session(key, val) {
let { ssid } = this.request let { ssid } = this.request
if (this.context.$$session) { if (this.context.$$session) {

View File

@ -1,6 +1,6 @@
{ {
"name": "@gm5/controller", "name": "@gm5/controller",
"version": "2.0.0", "version": "2.0.3",
"type": "module", "type": "module",
"description": "控制器基类。", "description": "控制器基类。",
"main": "index.js", "main": "index.js",