@nocobase/auth 1.6.0-beta.10 → 1.6.0-beta.12

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/lib/auth.js CHANGED
@@ -64,6 +64,9 @@ const _Auth = class _Auth {
64
64
  this.ctx = ctx;
65
65
  }
66
66
  async skipCheck() {
67
+ if (this.ctx.skipAuthCheck === true) {
68
+ return true;
69
+ }
67
70
  const token = this.ctx.getBearerToken();
68
71
  if (!token && this.ctx.app.options.acl === false) {
69
72
  return true;
package/lib/base/auth.js CHANGED
@@ -83,6 +83,7 @@ const _BaseAuth = class _BaseAuth extends import_auth.Auth {
83
83
  async check() {
84
84
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
85
85
  const token = this.ctx.getBearerToken();
86
+ const cache = this.ctx.cache;
86
87
  if (!token) {
87
88
  this.ctx.throw(401, {
88
89
  message: this.ctx.t("Unauthenticated. Please sign in to continue.", { ns: localeNamespace }),
@@ -107,15 +108,17 @@ const _BaseAuth = class _BaseAuth extends import_auth.Auth {
107
108
  }
108
109
  }
109
110
  const { userId, roleName, iat, temp, jti, exp, signInTime } = payload ?? {};
110
- const tokenPolicy = await this.tokenController.getConfig();
111
- if (signInTime && Date.now() - signInTime > tokenPolicy.sessionExpirationTime) {
112
- this.ctx.throw(401, {
113
- message: this.ctx.t("Your session has expired. Please sign in again.", { ns: localeNamespace }),
114
- code: import_auth.AuthErrorCode.EXPIRED_SESSION
115
- });
116
- }
117
- if (tokenStatus === "valid" && Date.now() - iat * 1e3 > tokenPolicy.tokenExpirationTime) {
118
- tokenStatus = "expired";
111
+ const user = userId ? await cache.wrap(
112
+ this.getCacheKey(userId),
113
+ () => this.userRepository.findOne({
114
+ filter: {
115
+ id: userId
116
+ },
117
+ raw: true
118
+ })
119
+ ) : null;
120
+ if (roleName) {
121
+ this.ctx.headers["x-role"] = roleName;
119
122
  }
120
123
  const blocked = await this.jwt.blacklist.has(jti ?? token);
121
124
  if (blocked) {
@@ -124,25 +127,26 @@ const _BaseAuth = class _BaseAuth extends import_auth.Auth {
124
127
  code: import_auth.AuthErrorCode.BLOCKED_TOKEN
125
128
  });
126
129
  }
127
- if (roleName) {
128
- this.ctx.headers["x-role"] = roleName;
130
+ if (!temp) {
131
+ if (tokenStatus === "valid") {
132
+ return user;
133
+ } else {
134
+ this.ctx.throw(401, {
135
+ message: this.ctx.t("Your session has expired. Please sign in again.", { ns: localeNamespace }),
136
+ code: import_auth.AuthErrorCode.INVALID_TOKEN
137
+ });
138
+ }
129
139
  }
130
- const cache = this.ctx.cache;
131
- const user = await cache.wrap(
132
- this.getCacheKey(userId),
133
- () => this.userRepository.findOne({
134
- filter: {
135
- id: userId
136
- },
137
- raw: true
138
- })
139
- );
140
- if (!temp && tokenStatus !== "valid") {
140
+ const tokenPolicy = await this.tokenController.getConfig();
141
+ if (signInTime && Date.now() - signInTime > tokenPolicy.sessionExpirationTime) {
141
142
  this.ctx.throw(401, {
142
143
  message: this.ctx.t("Your session has expired. Please sign in again.", { ns: localeNamespace }),
143
- code: import_auth.AuthErrorCode.INVALID_TOKEN
144
+ code: import_auth.AuthErrorCode.EXPIRED_SESSION
144
145
  });
145
146
  }
147
+ if (tokenStatus === "valid" && Date.now() - iat * 1e3 > tokenPolicy.tokenExpirationTime) {
148
+ tokenStatus = "expired";
149
+ }
146
150
  if (tokenStatus === "valid" && user.passwordChangeTz && iat * 1e3 < user.passwordChangeTz) {
147
151
  this.ctx.throw(401, {
148
152
  message: this.ctx.t("User password changed, please signin again.", { ns: localeNamespace }),
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@nocobase/auth",
3
- "version": "1.6.0-beta.10",
3
+ "version": "1.6.0-beta.12",
4
4
  "description": "",
5
5
  "license": "AGPL-3.0",
6
6
  "main": "./lib/index.js",
7
7
  "types": "./lib/index.d.ts",
8
8
  "dependencies": {
9
- "@nocobase/actions": "1.6.0-beta.10",
10
- "@nocobase/cache": "1.6.0-beta.10",
11
- "@nocobase/database": "1.6.0-beta.10",
12
- "@nocobase/resourcer": "1.6.0-beta.10",
13
- "@nocobase/utils": "1.6.0-beta.10",
9
+ "@nocobase/actions": "1.6.0-beta.12",
10
+ "@nocobase/cache": "1.6.0-beta.12",
11
+ "@nocobase/database": "1.6.0-beta.12",
12
+ "@nocobase/resourcer": "1.6.0-beta.12",
13
+ "@nocobase/utils": "1.6.0-beta.12",
14
14
  "@types/jsonwebtoken": "^8.5.8",
15
15
  "jsonwebtoken": "^8.5.1"
16
16
  },
@@ -19,5 +19,5 @@
19
19
  "url": "git+https://github.com/nocobase/nocobase.git",
20
20
  "directory": "packages/auth"
21
21
  },
22
- "gitHead": "72684ad7261e46b67969ecc4db0f1bcbea545a8d"
22
+ "gitHead": "d150a1853eb5e44b1f772b5f3f0463f6c7f061ba"
23
23
  }