Fix inviter id setting (#17)

This commit is contained in:
AceDataCloud committed 2024-01-03 02:22:40 +08:00
1 parent fa0250beca
commit 140a585316
5 files changed
+20 -40

No files matched your search

@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix inviter id setting",
"packageName": "@zhishuyun/hub",
"email": "cqc@germey.cn",
"dependentChangeType": "patch"
}
+4 -3
View File
@@ -9,8 +9,8 @@
import { defineComponent } from 'vue';
import { ElConfigProvider } from 'element-plus';
import zhCn from 'element-plus/dist/locale/zh-cn.mjs';
import { getDomain, getPath, setCookie } from './utils';
import AuthPanel from './components/common/AuthPanel.vue';
import { setCookie } from 'typescript-cookie';
export default defineComponent({
components: {
@@ -23,6 +23,9 @@ export default defineComponent({
inviterId: this.$route.query.inviter_id?.toString()
};
},
mounted() {
this.onSetCookie();
},
methods: {
onSetCookie() {
// set inviter to cookies to persist
@@ -31,8 +34,6 @@ export default defineComponent({
const expiration = new Date();
expiration.setDate(expiration.getDate() + 7);
setCookie('INVITER_ID', this.inviterId, {
domain: getDomain(),
path: getPath(),
expires: expiration
});
}
+9 -5
View File
@@ -15,18 +15,22 @@
import { defineComponent } from 'vue';
import { ElDialog } from 'element-plus';
import { getBaseUrlAuth } from '@/utils';
import { getCookie } from 'typescript-cookie';
export default defineComponent({
name: 'AuthPanel',
components: {
ElDialog
},
data() {
return {
iframeUrl: `${getBaseUrlAuth()}/auth/login`
};
},
computed: {
iframeUrl() {
return `${getBaseUrlAuth()}/auth/login?inviter_id=${this.inviterId}`;
},
inviterId() {
const result = getCookie('INVITER_ID') || this.$route.query.inviter_id?.toString();
console.debug('inviterId', result);
return result;
},
authenticated() {
return !!this.$store.state.token.access;
}
-31
View File
@@ -1,31 +0,0 @@
import { removeCookie, setCookie as baseSetCookie } from 'typescript-cookie';
import { CookieAttributes } from 'typescript-cookie/dist/types';
export const getDomain = () => {
const host = window.location.host;
// process test env and prod env, for example:
// auth.zhishuyun.com -> .zhishuyun.com
// auth.test.zhishuyun.com -> .zhishuyun.com
const domain = host.replace(/^\S+?\.(test\.|local\.)?/, '.');
return domain;
};
export const getPath = () => {
return '/';
};
export const setCookie = (key: string, value: string, attributes: CookieAttributes) => {
baseSetCookie(key, value, {
domain: attributes?.domain || getDomain(),
path: attributes?.path || getPath(),
expires: attributes?.expires,
sameSite: attributes?.sameSite,
secure: attributes?.secure
});
};
export const resetCookies = () => {
// remove tokens from cookies
removeCookie('ACCESS_TOKEN', { domain: getDomain(), path: getPath() });
removeCookie('REFRESH_TOKEN', { domain: getDomain(), path: getPath() });
};
-1
View File
@@ -1,4 +1,3 @@
export * from './baseUrl';
export * from './mode';
export * from './log';
export * from './cookies';