feat(auth): 新增合作伙伴 token 认证接口
This commit is contained in:
7
app.vue
7
app.vue
@@ -18,8 +18,9 @@ useSeoMeta({
|
|||||||
})
|
})
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
loginState.checkSession().then(async (res) => {
|
loginState.checkSession().then(async (loggedIn) => {
|
||||||
if (!res && loginState.token) {
|
if (route.meta.preventLoginCheck) return
|
||||||
|
if (!loggedIn && loginState.token) {
|
||||||
toast.add({
|
toast.add({
|
||||||
title: '登录失效',
|
title: '登录失效',
|
||||||
description: '登录已过期,请重新登录',
|
description: '登录已过期,请重新登录',
|
||||||
@@ -27,7 +28,7 @@ onMounted(() => {
|
|||||||
icon: 'i-tabler-alert-triangle',
|
icon: 'i-tabler-alert-triangle',
|
||||||
})
|
})
|
||||||
modal.open(ModalAuthentication)
|
modal.open(ModalAuthentication)
|
||||||
} else if (!res && !loginState.token) {
|
} else if (!loggedIn && !loginState.token) {
|
||||||
// Prevents redirect from register page
|
// Prevents redirect from register page
|
||||||
if (route.path === '/user/register') return
|
if (route.path === '/user/register') return
|
||||||
router.replace('/user/authenticate')
|
router.replace('/user/authenticate')
|
||||||
|
|||||||
@@ -4,12 +4,14 @@ import { object, string, type InferType } from 'yup'
|
|||||||
|
|
||||||
definePageMeta({
|
definePageMeta({
|
||||||
layout: 'authenticate',
|
layout: 'authenticate',
|
||||||
|
preventLoginCheck: true
|
||||||
})
|
})
|
||||||
|
|
||||||
useSeoMeta({
|
useSeoMeta({
|
||||||
title: '登录',
|
title: '登录',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const route = useRoute()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
const loginState = useLoginState()
|
const loginState = useLoginState()
|
||||||
@@ -327,6 +329,39 @@ const onForgetPasswordSubmit = (
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
const { token, user_id } = route.query
|
||||||
|
if (!token || !user_id) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
loginState.token = token.toString()
|
||||||
|
loginState.user.id = user_id as unknown as number
|
||||||
|
loginState
|
||||||
|
.updateProfile()
|
||||||
|
.then(() => {
|
||||||
|
loginState.checkSession()
|
||||||
|
toast.add({
|
||||||
|
title: '登录成功',
|
||||||
|
description: `合作渠道认证成功`,
|
||||||
|
color: 'primary',
|
||||||
|
icon: 'i-tabler-login-2',
|
||||||
|
})
|
||||||
|
router.replace('/')
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
toast.add({
|
||||||
|
title: '认证失败',
|
||||||
|
description: err.msg || 'Token 或 UserID 无效',
|
||||||
|
color: 'red',
|
||||||
|
icon: 'i-tabler-circle-x',
|
||||||
|
})
|
||||||
|
router.replace('/')
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
final_loading.value = false
|
||||||
|
})
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -574,9 +609,11 @@ const onForgetPasswordSubmit = (
|
|||||||
color="gray"
|
color="gray"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
class="!text-gray-500"
|
class="!text-gray-500"
|
||||||
@click="() => {
|
@click="
|
||||||
|
() => {
|
||||||
router.push('/user/register')
|
router.push('/user/register')
|
||||||
}"
|
}
|
||||||
|
"
|
||||||
>
|
>
|
||||||
注册新账号
|
注册新账号
|
||||||
</UButton>
|
</UButton>
|
||||||
|
|||||||
Reference in New Issue
Block a user