Fix bug of cookies settings for inviter id (#18)
This commit is contained in:
1 parent
6a871cfdab
commit
b0faf7def1
5 files changed
+25
-21
No files matched your search
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "patch",
|
||||
"comment": "fix bug of setting cookie of inviter id",
|
||||
"packageName": "@zhishuyun/hub",
|
||||
"email": "cqc@germey.cn",
|
||||
"dependentChangeType": "patch"
|
||||
}
|
||||
+1
-19
@@ -10,7 +10,6 @@ import { defineComponent } from 'vue';
|
||||
import { ElConfigProvider } from 'element-plus';
|
||||
import zhCn from 'element-plus/dist/locale/zh-cn.mjs';
|
||||
import AuthPanel from './components/common/AuthPanel.vue';
|
||||
import { setCookie } from 'typescript-cookie';
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
@@ -19,25 +18,8 @@ export default defineComponent({
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
locale: zhCn,
|
||||
inviterId: this.$route.query.inviter_id?.toString()
|
||||
locale: zhCn
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
this.onSetCookie();
|
||||
},
|
||||
methods: {
|
||||
onSetCookie() {
|
||||
// set inviter to cookies to persist
|
||||
if (this.inviterId) {
|
||||
// current date + 7 days
|
||||
const expiration = new Date();
|
||||
expiration.setDate(expiration.getDate() + 7);
|
||||
setCookie('INVITER_ID', this.inviterId, {
|
||||
expires: expiration
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@@ -27,8 +27,7 @@ export default defineComponent({
|
||||
return `${getBaseUrlAuth()}/auth/login?inviter_id=${this.inviterId}`;
|
||||
},
|
||||
inviterId() {
|
||||
const result = getCookie('INVITER_ID') || this.$route.query.inviter_id?.toString();
|
||||
console.debug('inviterId', result);
|
||||
const result = this.$route.query.inviter_id?.toString() || getCookie('INVITER_ID');
|
||||
return result;
|
||||
},
|
||||
authenticated() {
|
||||
|
||||
@@ -12,6 +12,9 @@ import { vLoading } from 'element-plus';
|
||||
import hl from 'highlight.js';
|
||||
import 'highlight.js/styles/night-owl.css';
|
||||
import copyToClipboard from 'copy-to-clipboard';
|
||||
import { initializeCookies } from './utils/initializer';
|
||||
|
||||
initializeCookies();
|
||||
|
||||
const app = createApp(App);
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { setCookie } from 'typescript-cookie';
|
||||
|
||||
export const initializeCookies = () => {
|
||||
// parse the query string and set to cookies
|
||||
const query = new URLSearchParams(window.location.search);
|
||||
const inviterId = query.get('inviter_id');
|
||||
const expiration = new Date();
|
||||
expiration.setDate(expiration.getDate() + 7);
|
||||
console.log('set INVITER_ID to cookies', inviterId);
|
||||
setCookie('INVITER_ID', inviterId, {
|
||||
expires: expiration
|
||||
});
|
||||
};
|
||||
Reference in new issue
Block a user