add verification check and support

This commit is contained in:
AceDataCloud committed 2023-02-11 12:18:53 +08:00
1 parent 538dfd283e
commit 91c6792c5c
10 files changed
+90 -16

No files matched your search

+19 -5
View File
@@ -8,6 +8,7 @@
import { defineComponent } from 'vue';
import { ElConfigProvider } from 'element-plus';
import zhCn from 'element-plus/dist/locale/zh-cn.mjs';
import { authOperator } from './operators/auth/operator';
export default defineComponent({
components: {
@@ -18,11 +19,24 @@ export default defineComponent({
locale: zhCn
};
},
mounted() {
// if access token is already set, try to get user info
const accessToken = this.$store.getters.accessToken;
if (accessToken) {
this.$store.dispatch('getMe');
async mounted() {
// if refresh token is already set, try to refresh it and get user info
const currentRefreshToken = this.$store.getters.refreshToken;
const currentAccessToken = this.$store.getters.accessToken;
if (!currentAccessToken) {
console.log('user not login');
}
if (currentRefreshToken) {
const {
data: { access: accessToken, refresh: refreshToken }
} = await authOperator.refreshToken({
refresh: currentRefreshToken
});
await this.$store.dispatch('setAccessToken', accessToken);
await this.$store.dispatch('setRefreshToken', refreshToken);
await this.$store.dispatch('getMe');
} else {
console.error('refresh token does not exist');
}
}
});