Skip to content

Commit

Permalink
Fix cookie domain issue for persisting setting (#73)
Browse files Browse the repository at this point in the history
Co-authored-by: AceDataCloud <[email protected]>
  • Loading branch information
Germey and AceDataCloud authored Jul 7, 2024
1 parent 19e1d01 commit b6d26c1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix the cookie domain",
"packageName": "@acedatacloud/nexior",
"email": "[email protected]",
"dependentChangeType": "patch"
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"highlight.js": "^11.7.0",
"mac-scrollbar": "^0.13.5",
"markdown-it": "^13.0.1",
"psl": "^1.9.0",
"qrcode": "^1.5.1",
"qs": "^6.11.2",
"query-string": "^8.1.0",
Expand All @@ -65,6 +66,7 @@
"@types/lodash": "^4.14.172",
"@types/markdown-it": "^12.2.3",
"@types/node": "^16.7.4",
"@types/psl": "^1.1.3",
"@types/qs": "^6.9.9",
"@types/uuid": "^8.3.4",
"@typescript-eslint/eslint-plugin": "^5.17.0",
Expand Down
21 changes: 13 additions & 8 deletions src/utils/initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ import { getLocale } from '@/i18n';
import store from '@/store';
import { log } from './log';
import { IToken } from '@/models';
import psl from 'psl';

export const getDomain = () => {
const host = window.location.hostname;
// process test env and prod env, for example:
// hub.acedata.cloud -> .acedata.cloud
// hub.test.acedata.cloud -> .acedata.cloud
const domain = host.replace(/^\S+?\.(test\.|local\.)?/, '.');
console.log('cookies domain', domain);
return domain;
export const getDomain = (host: string = window.location.hostname) => {
if (host === 'localhost') {
return host;
}
const parsed = psl.parse(host);
if (parsed.error) {
return host;
}
if (parsed.domain === host) {
return host;
}
return '.' + parsed.domain;
};

export const initializeCookies = async () => {
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,11 @@
resolved "https://registry.npmjs.org/@types/node/-/node-16.11.22.tgz"
integrity sha512-DYNtJWauMQ9RNpesl4aVothr97/tIJM8HbyOXJ0AYT1Z2bEjLHyfjOBPAQQVMLf8h3kSShYfNk8Wnto8B2zHUA==

"@types/psl@^1.1.3":
version "1.1.3"
resolved "https://registry.yarnpkg.com/@types/psl/-/psl-1.1.3.tgz#c1e9febd70e7df248ac9911cdd145454643aa28f"
integrity sha512-Iu174JHfLd7i/XkXY6VDrqSlPvTDQOtQI7wNAXKKOAADJ9TduRLkNdMgjGiMxSttUIZnomv81JAbAbC0DhggxA==

"@types/qs@^6.9.9":
version "6.9.9"
resolved "https://registry.npmjs.org/@types/qs/-/qs-6.9.9.tgz"
Expand Down Expand Up @@ -3718,6 +3723,11 @@ proxy-from-env@^1.1.0:
resolved "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz"
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==

psl@^1.9.0:
version "1.9.0"
resolved "https://registry.yarnpkg.com/psl/-/psl-1.9.0.tgz#d0df2a137f00794565fcaf3b2c00cd09f8d5a5a7"
integrity sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag==

punycode@^2.1.0:
version "2.3.1"
resolved "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz"
Expand Down

0 comments on commit b6d26c1

Please sign in to comment.