feat: add control plane authentication baseline

This commit is contained in:
wlx committed 2026-08-21 15:47:57 +08:00
1 parent a4c93ff1a7
commit 0d10e2d124
21 files changed
+1403 -18

No files matched your search

+22 -10
View File
@@ -16,12 +16,13 @@ import {
Sparkles,
Zap,
} from 'lucide-vue-next'
import { AuthApiError, authClient, type AuthUser } from '../services/auth'
type AuthMode = 'login' | 'register' | 'forgot'
type RegisterChannel = 'email' | 'phone'
const emit = defineEmits<{
success: [name: string]
success: [user: AuthUser]
notify: [message: string]
}>()
@@ -61,28 +62,39 @@ function sendCode() {
emit('notify', '验证码已发送,原型阶段可输入任意 6 位数字')
}
function submitLogin() {
async function submitLogin() {
if (!account.value.trim() || !password.value) return emit('notify', '请输入账号和密码')
loading.value = true
window.setTimeout(() => {
try {
const user = await authClient.login({ account: account.value, password: password.value })
loading.value = false
emit('success', '林默')
}, 650)
emit('success', user)
} catch (error) {
loading.value = false
emit('notify', error instanceof AuthApiError ? error.message : '登录失败,请稍后重试')
}
}
function submitRegister() {
async function submitRegister() {
if (!invitationCode.value.trim()) return emit('notify', '第一版内测需要填写邀请码')
if (!account.value.trim()) return emit('notify', `请输入${accountLabel.value}`)
if (verificationCode.value.trim().length < 4) return emit('notify', '请输入收到的验证码')
if (password.value.length < 8) return emit('notify', '密码至少需要 8 位')
if (password.value !== confirmPassword.value) return emit('notify', '两次输入的密码不一致')
if (!agreeTerms.value) return emit('notify', '请先同意服务协议与隐私政策')
loading.value = true
window.setTimeout(() => {
try {
const user = await authClient.register({
invitationCode: invitationCode.value,
account: account.value,
password: password.value,
})
loading.value = false
switchMode('login')
emit('notify', '注册成功,请使用新账号登录')
}, 700)
emit('notify', '注册成功,欢迎 ' + user.displayName + '。请使用新账号登录')
} catch (error) {
loading.value = false
emit('notify', error instanceof AuthApiError ? error.message : '注册失败,请稍后重试')
}
}
function submitReset() {