feat: support auto login with url query parameter (#606)

This commit is contained in:
Dream Hunter
2025-03-16 14:20:24 +08:00
committed by GitHub
parent 908fc0cc86
commit 525f5e2dce
6 changed files with 42 additions and 17 deletions

View File

@@ -2,6 +2,10 @@ import { createRouter, createWebHistory } from 'vue-router'
import Index from '../views/Index.vue'
import User from '../views/User.vue'
import UserOauth2Callback from '../views/user/UserOauth2Callback.vue'
import i18n from '../i18n'
import { useGlobalState } from '../store'
const { jwt } = useGlobalState()
const router = createRouter({
history: createWebHistory(),
@@ -37,6 +41,20 @@ const router = createRouter({
redirect: '/'
}
]
})
});
router.beforeEach((to, from, next) => {
if (to.params.lang && ['en', 'zh'].includes(to.params.lang)) {
i18n.global.locale.value = to.params.lang
} else {
i18n.global.locale.value = 'zh'
}
// check if query parameter has jwt, set it to store
if (to.query.jwt) {
jwt.value = to.query.jwt;
}
next()
});
export default router