bjx-auth 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bjx-auth",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "exports": {
5
5
  ".": {
6
6
  "require": "./dist/bjx-auth-api.umd.js",
@@ -23,12 +23,14 @@
23
23
  "license": "ISC",
24
24
  "description": "",
25
25
  "dependencies": {
26
+ "@rollup/plugin-babel": "^6.0.4",
26
27
  "axios": "^1.11.0",
27
28
  "crypto-js": "^4.2.0",
28
29
  "jsencrypt": "^3.5.4",
29
30
  "passport": "^0.4.0"
30
31
  },
31
32
  "devDependencies": {
33
+ "@babel/preset-env": "^7.28.3",
32
34
  "@rollup/plugin-commonjs": "^28.0.6",
33
35
  "@rollup/plugin-node-resolve": "^16.0.1",
34
36
  "@rollup/plugin-replace": "^6.0.2",
package/src/config.js CHANGED
@@ -20,6 +20,9 @@ const config = {
20
20
  // logger.js
21
21
  debug: false,
22
22
  debugApiUrl: '',
23
+
24
+ // 缓存koa的app对象
25
+ app: null,
23
26
  }
24
27
 
25
28
  function setKey(key, val) {
@@ -44,7 +44,8 @@ class BjxStrategy extends Strategy {
44
44
 
45
45
  // 假如不存在 则认证失败
46
46
  if (!hasRequiredCookies && !(this.handleHeadrToken && hasRequiredHeaders)) {
47
- return this.fail(new Error('Missing required cookies or headers'))
47
+ debugLogger('认证失败', hasRequiredCookies, '(', this.handleHeadrToken, hasRequiredHeaders, ')')
48
+ return this.fail()
48
49
  }
49
50
 
50
51
  if (this.handleHeadrToken && hasRequiredHeaders) {
@@ -190,7 +191,7 @@ class BjxStrategy extends Strategy {
190
191
  // 假如存在token 还到这一步 说明是刷新token
191
192
  const isRefresh = !!su.token
192
193
  if (isRefresh) {
193
- debugLogger('更新令牌')
194
+ debugLogger('刷新令牌')
194
195
  }
195
196
 
196
197
  // 获取新token
@@ -231,22 +232,28 @@ class BjxStrategy extends Strategy {
231
232
  // Koa中间件
232
233
  function createBjxAuthMiddleware(passport) {
233
234
  return async (ctx, next) => {
235
+ // 缓存app对象 方便打印日志
236
+ if (!getConfig('app')) {
237
+ setConfig('app', ctx.app)
238
+ }
239
+
240
+ // 等待每次鉴权结果
234
241
  await new Promise((resolve) => {
235
242
  passport.authenticate('bjx', (err, user, info, status) => {
236
243
  if (err) {
237
- // this.error()
244
+ // this.error()进到这里
238
245
  errorLogger(err)
239
246
  ctx.logout()
240
247
  } else if (user) {
241
- // this.success()
248
+ // this.success()进到这里
242
249
  ctx.login(user)
243
250
  } else {
244
- // this.fail()
251
+ // this.fail()进到这里
245
252
  ctx.logout()
246
253
  }
247
254
  resolve()
248
255
  })(ctx, () => {
249
- // this.pass()
256
+ // this.pass()进到这里
250
257
  resolve()
251
258
  })
252
259
  })