@gct-paas/core 6.1.1 → 6.1.2

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.
@@ -1,2 +1,2 @@
1
- /*! @gct-paas/core v6.1.0-fix.0 */
1
+ /*! @gct-paas/core v6.1.2 */
2
2
  import{createElementBlock as e,defineComponent as r,openBlock as t,unref as a}from"vue";import{useRouter as p}from"vue-router";var o=/* @__PURE__ */r({__name:"redirect-index",setup(r){const{currentRoute:o,replace:i}=p(),{params:s,query:u}=a(o),{path:m,_redirect_type:n="path"}=s;Reflect.deleteProperty(s,"_redirect_type"),Reflect.deleteProperty(s,"path");const c=Array.isArray(m)?m.join("/"):m;return i("name"===n?{name:c,query:u,params:JSON.parse(s._origin_params??"{}")}:{path:c.startsWith("/")?c:"/"+c,query:u}),(r,a)=>(t(),e("div"))}});export{o as default};
@@ -21,6 +21,10 @@ export declare class AuthUtil {
21
21
  * @return {*} {Promise<void>}
22
22
  */
23
23
  clearAuthAndGoLogin(): Promise<void>;
24
+ /**
25
+ * 使用当前应用上下文跳转到登录页,供退出登录和认证失效共用。
26
+ */
27
+ private _goLogin;
24
28
  /**
25
29
  * 跳转到首页
26
30
  *
@@ -27,16 +27,7 @@ var AuthUtil = class AuthUtil {
27
27
  }
28
28
  async logout(goLogin) {
29
29
  await useUserStore().submitLoginOut();
30
- if (goLogin) {
31
- const url = new URL(`${location.origin}/paas-front/portal`);
32
- if (_gct.env.isSandbox || _gct.env.isAppSingle) {
33
- if (_gct.store.context.aid) url.searchParams.set("aid", _gct.store.context.aid);
34
- url.searchParams.set("env", _gct.env.getEnv());
35
- if (_gct.env.isAppSingle) url.searchParams.set("mode", "single");
36
- }
37
- url.hash = `/login`;
38
- window.location.href = url.toString();
39
- }
30
+ if (goLogin) this._goLogin();
40
31
  }
41
32
  /**
42
33
  * 清除认证信息并跳转到登录页
@@ -46,7 +37,18 @@ var AuthUtil = class AuthUtil {
46
37
  async clearAuthAndGoLogin() {
47
38
  setToken();
48
39
  setTenant();
40
+ this._goLogin();
41
+ }
42
+ /**
43
+ * 使用当前应用上下文跳转到登录页,供退出登录和认证失效共用。
44
+ */
45
+ _goLogin() {
49
46
  const url = new URL(`${location.origin}/paas-front/portal`);
47
+ if (_gct.env.isSandbox || _gct.env.isAppSingle) {
48
+ if (_gct.store.context.aid) url.searchParams.set("aid", _gct.store.context.aid);
49
+ url.searchParams.set("env", _gct.env.getEnv());
50
+ if (_gct.env.isAppSingle) url.searchParams.set("mode", "single");
51
+ }
50
52
  url.hash = `/login`;
51
53
  window.location.href = url.toString();
52
54
  }
@@ -10,7 +10,8 @@ export declare function getToken(): string | null;
10
10
  /**
11
11
  * 设置认证令牌(目前只有 session 级别生效)
12
12
  *
13
- * cookie 不设置 domain 属性,绑定当前完整 hostname(host-only),按域名隔离
13
+ * cookie 不设置 domain 属性,绑定当前完整 hostname(host-only),按域名隔离;
14
+ * 写入/清除时同步清掉主域等祖先域上的历史同名 cookie,避免读取时被旧值抢先命中
14
15
  *
15
16
  * @export
16
17
  * @param {string} token
@@ -6,9 +6,29 @@ import qs from "qs";
6
6
  import { customRef, readonly } from "vue";
7
7
  //#region src/utils/tools/tools.ts
8
8
  /**
9
+ * 清除主域及祖先域上的同名 cookie
10
+ *
11
+ * 域名隔离改造前认证信息按主域(如 .zhr.cn)写入,与现在绑定当前完整域名的 host-only
12
+ * cookie 并存时,document.cookie 中同名 cookie 按创建时间排序,旧的主域 cookie 会先被
13
+ * getCookie 匹配到,导致读到失效 token 反复跳登录页。子域允许改写父域 cookie,这里逐级
14
+ * 过期祖先域上的同名 cookie,保证只剩当前域的,重新登录后即可正常匹配。
15
+ *
16
+ * @param {string} name cookie 名称
17
+ */
18
+ function clearInheritedDomainCookies(name) {
19
+ const { hostname, protocol } = location;
20
+ if (!hostname.includes(".") || /^\d+(\.\d+){3}$/.test(hostname)) return;
21
+ const parts = hostname.split(".");
22
+ for (let i = 0; i <= parts.length - 2; i++) {
23
+ const domain = parts.slice(i).join(".");
24
+ document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; domain=.${domain}; path=/${protocol === "https:" ? "; secure" : ""}`;
25
+ }
26
+ }
27
+ /**
9
28
  * 租户 cookie 双向绑定响应式引用:get 直接读 cookie,set 直接写 cookie
10
29
  *
11
- * cookie 不设置 domain 属性,绑定当前完整 hostname(host-only),按域名隔离
30
+ * cookie 不设置 domain 属性,绑定当前完整 hostname(host-only),按域名隔离;
31
+ * 写入/清除时同步清掉主域等祖先域上的历史同名 cookie,避免读取时被旧值抢先命中
12
32
  */
13
33
  var _tenantRef = customRef((track, trigger) => ({
14
34
  get() {
@@ -16,8 +36,13 @@ var _tenantRef = customRef((track, trigger) => ({
16
36
  return getCookie(CoreConst.TENANT) || "";
17
37
  },
18
38
  set(value) {
19
- if (value) setCookie(CoreConst.TENANT, value, 7, false);
20
- else clearCookie(CoreConst.TENANT, false);
39
+ if (value) {
40
+ clearInheritedDomainCookies(CoreConst.TENANT);
41
+ setCookie(CoreConst.TENANT, value, 7, false);
42
+ } else {
43
+ clearCookie(CoreConst.TENANT, false);
44
+ clearInheritedDomainCookies(CoreConst.TENANT);
45
+ }
21
46
  trigger();
22
47
  }
23
48
  }));
@@ -34,14 +59,21 @@ function getToken() {
34
59
  /**
35
60
  * 设置认证令牌(目前只有 session 级别生效)
36
61
  *
37
- * cookie 不设置 domain 属性,绑定当前完整 hostname(host-only),按域名隔离
62
+ * cookie 不设置 domain 属性,绑定当前完整 hostname(host-only),按域名隔离;
63
+ * 写入/清除时同步清掉主域等祖先域上的历史同名 cookie,避免读取时被旧值抢先命中
38
64
  *
39
65
  * @export
40
66
  * @param {string} token
41
67
  */
42
68
  function setToken(token) {
43
- if (token) setCookie(CoreConst.TOKEN, token, 7, false);
44
- else clearCookie(CoreConst.TOKEN, false);
69
+ if (token) {
70
+ clearInheritedDomainCookies(CoreConst.TOKEN);
71
+ clearInheritedDomainCookies(CoreConst.TENANT);
72
+ setCookie(CoreConst.TOKEN, token, 7, false);
73
+ } else {
74
+ clearCookie(CoreConst.TOKEN, false);
75
+ clearInheritedDomainCookies(CoreConst.TOKEN);
76
+ }
45
77
  }
46
78
  /**
47
79
  * 从 cookie 获取租户标识
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gct-paas/core",
3
- "version": "6.1.1",
3
+ "version": "6.1.2",
4
4
  "type": "module",
5
5
  "description": "paas 平台核心包",
6
6
  "loader": "dist/index.esm.min.js",
@@ -30,10 +30,24 @@
30
30
  },
31
31
  "license": "MIT",
32
32
  "author": "gct",
33
+ "scripts": {
34
+ "dev": "cross-env NODE_ENV=development vite build --watch --config vite.dev.config.ts",
35
+ "es:build": "vite build --config vite.dev.config.ts",
36
+ "build": "npm run lint && vue-tsc --noEmit && vite build --config vite.dev.config.ts && vite build --config vite.config.ts",
37
+ "lint": "eslint src/",
38
+ "test": "vitest",
39
+ "test:run": "vitest run",
40
+ "test:coverage": "vitest run --coverage",
41
+ "publish:next": "npm run build && npm publish --access public --tag=next --registry=https://registry.npmjs.org/",
42
+ "publish:dev": "npm run build && npm publish --access public --tag=dev --registry=https://registry.npmjs.org/",
43
+ "publish:alpha": "npm run build && npm publish --access public --tag=alpha --registry=https://registry.npmjs.org/",
44
+ "publish:beta": "npm run build && npm publish --access public --tag=beta --registry=https://registry.npmjs.org/",
45
+ "publish:npm": "npm run build && npm publish --access public --registry=https://registry.npmjs.org/"
46
+ },
33
47
  "dependencies": {
34
48
  "@fingerprintjs/fingerprintjs": "^5.1.0",
35
49
  "@floating-ui/dom": "^1.7.6",
36
- "@gct-paas/api": "^6.0.0-dev.17",
50
+ "@gct-paas/api": "catalog:",
37
51
  "@module-federation/runtime": "^2.2.3",
38
52
  "@vueuse/core": "^14.1.0",
39
53
  "async-validator": "^4.2.5",
@@ -60,23 +74,10 @@
60
74
  "playwright": "^1.58.0"
61
75
  },
62
76
  "peerDependencies": {
63
- "@gct-paas/api": "^6.0.0-dev.17",
77
+ "@gct-paas/api": "catalog:",
64
78
  "vue": ">=3",
65
79
  "vue-i18n": ">=11",
66
80
  "vue-router": ">=4"
67
81
  },
68
- "scripts": {
69
- "dev": "cross-env NODE_ENV=development vite build --watch --config vite.dev.config.ts",
70
- "es:build": "vite build --config vite.dev.config.ts",
71
- "build": "npm run lint && vue-tsc --noEmit && vite build --config vite.dev.config.ts && vite build --config vite.config.ts",
72
- "lint": "eslint src/",
73
- "test": "vitest",
74
- "test:run": "vitest run",
75
- "test:coverage": "vitest run --coverage",
76
- "publish:next": "npm run build && npm publish --access public --tag=next --registry=https://registry.npmjs.org/",
77
- "publish:dev": "npm run build && npm publish --access public --tag=dev --registry=https://registry.npmjs.org/",
78
- "publish:alpha": "npm run build && npm publish --access public --tag=alpha --registry=https://registry.npmjs.org/",
79
- "publish:beta": "npm run build && npm publish --access public --tag=beta --registry=https://registry.npmjs.org/",
80
- "publish:npm": "npm run build && npm publish --access public --registry=https://registry.npmjs.org/"
81
- }
82
- }
82
+ "gitHead": "c9d7e05fb13a69062b6b1924292f9ab1546d8664"
83
+ }