refine auth

This commit is contained in:
AceDataCloud committed 2023-01-26 00:24:23 +08:00
1 parent 679faf9fc2
commit 6bd5bb0aa0
9 files changed
+20 -98

No files matched your search

+9 -2
View File
@@ -19,19 +19,26 @@ export default defineComponent({
};
},
async mounted() {
// get tokens from cookies
this.accessToken = getCookie('ACCESS_TOKEN');
this.refreshToken = getCookie('REFRESH_TOKEN');
if (this.accessToken && this.refreshToken) {
await this.$store.dispatch('setAccessToken', this.accessToken);
await this.$store.dispatch('setRefreshToken', this.refreshToken);
// store token to global store
this.$store.dispatch('setAccessToken', this.accessToken);
this.$store.dispatch('setRefreshToken', this.refreshToken);
console.debug('set token successfully');
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\.)?/, '.');
const path = '/';
// remove tokens from cookies
removeCookie('ACCESS_TOKEN', { domain, path });
removeCookie('REFRESH_TOKEN', { domain, path });
console.debug('remove cookie for tokens successfully');
// get user info after get access token
this.$store.dispatch('getMe');
if (this.redirect) {
this.$router.push(this.redirect);
}