fix: improve registration error messages with specific validation feedback
Extract PocketBase validation errors (duplicate email/username/password) and display them in Chinese. Also improve login error message. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -42,7 +42,7 @@ export const useUserStore = defineStore('user', () => {
|
|||||||
await pb.collection('users').authWithPassword(email, password)
|
await pb.collection('users').authWithPassword(email, password)
|
||||||
await initUser()
|
await initUser()
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
throw new Error(error.message || '登录失败')
|
throw new Error('邮箱或密码错误')
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
}
|
}
|
||||||
@@ -55,6 +55,14 @@ export const useUserStore = defineStore('user', () => {
|
|||||||
await pb.collection('users').create(data)
|
await pb.collection('users').create(data)
|
||||||
await login(data.email, data.password)
|
await login(data.email, data.password)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
const validation = error?.data?.data || error?.data
|
||||||
|
if (validation) {
|
||||||
|
const messages: string[] = []
|
||||||
|
if (validation.email) messages.push('邮箱无效或已被使用')
|
||||||
|
if (validation.username) messages.push('用户名无效或已被使用')
|
||||||
|
if (validation.password) messages.push('密码不符合要求')
|
||||||
|
if (messages.length > 0) throw new Error(messages.join(';'))
|
||||||
|
}
|
||||||
throw new Error(error.message || '注册失败')
|
throw new Error(error.message || '注册失败')
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
|
|||||||
Reference in New Issue
Block a user