update callback
This commit is contained in:
1 parent
09f7a36edd
commit
a63c85796b
9 files changed
+99
-44
No files matched your search
@@ -0,0 +1,49 @@
|
||||
<template>
|
||||
<div></div>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { getCookie } from 'typescript-cookie';
|
||||
|
||||
interface IData {
|
||||
accessToken: string | undefined;
|
||||
refreshToken: string | undefined;
|
||||
redirect: string | undefined;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'Login',
|
||||
data(): IData {
|
||||
return {
|
||||
accessToken: undefined,
|
||||
refreshToken: undefined,
|
||||
redirect: this.$route.query.redirect?.toString()
|
||||
};
|
||||
},
|
||||
async mounted() {
|
||||
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);
|
||||
if (this.redirect) {
|
||||
this.$router.push(this.redirect);
|
||||
}
|
||||
} else {
|
||||
const currentUrl = window.location.href;
|
||||
const targetUrl = `https://auth.zhishuyun.com?redirect=${currentUrl}`;
|
||||
window.location.href = targetUrl;
|
||||
}
|
||||
},
|
||||
methods: {}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.panel {
|
||||
.title {
|
||||
text-align: center;
|
||||
font-size: 22px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -5,8 +5,6 @@
|
||||
import { defineComponent } from 'vue';
|
||||
|
||||
interface IData {
|
||||
accessToken: string | undefined;
|
||||
refreshToken: string | undefined;
|
||||
redirect: string | undefined;
|
||||
}
|
||||
|
||||
@@ -14,23 +12,17 @@ export default defineComponent({
|
||||
name: 'Login',
|
||||
data(): IData {
|
||||
return {
|
||||
accessToken: this.$route.query['access-token']?.toString(),
|
||||
refreshToken: this.$route.query['refresh-token']?.toString(),
|
||||
redirect: this.$route.query.redirect?.toString()
|
||||
};
|
||||
},
|
||||
async mounted() {
|
||||
if (this.accessToken && this.refreshToken) {
|
||||
await this.$store.dispatch('setAccessToken', this.accessToken);
|
||||
await this.$store.dispatch('setRefreshToken', this.refreshToken);
|
||||
if (this.redirect) {
|
||||
this.$router.push(this.redirect);
|
||||
}
|
||||
} else {
|
||||
const currentUrl = window.location.href;
|
||||
const targetUrl = `https://auth.zhishuyun.com?redirect=${currentUrl}`;
|
||||
window.location.href = targetUrl;
|
||||
}
|
||||
const host = window.location.host;
|
||||
const subDomain = host.substring(host.indexOf('.') + 1);
|
||||
// callback url used to init access token and then redirect back of `redirect`
|
||||
const callbackUrl = `https://${host}/auth/callback?redirect=${this.redirect}`;
|
||||
// redirect to auth service to get access token then redirect back
|
||||
const targetUrl = `https://auth.${subDomain}?redirect=${callbackUrl}`;
|
||||
window.location.href = targetUrl;
|
||||
},
|
||||
methods: {}
|
||||
});
|
||||
|
||||
+9
-1
@@ -10,11 +10,19 @@ export default {
|
||||
children: [
|
||||
{
|
||||
path: 'login',
|
||||
name: 'login',
|
||||
name: 'auth-login',
|
||||
meta: {
|
||||
title: t('common.nav.article')
|
||||
},
|
||||
component: () => import('@/pages/auth/Login.vue')
|
||||
},
|
||||
{
|
||||
path: 'callback',
|
||||
name: 'auth-callback',
|
||||
meta: {
|
||||
title: t('common.nav.article')
|
||||
},
|
||||
component: () => import('@/pages/auth/Callback.vue')
|
||||
}
|
||||
]
|
||||
};
|
||||
Reference in new issue
Block a user