fix passwd change
This commit is contained in:
parent
c2417c31da
commit
9b6b5cdda9
@ -3,6 +3,7 @@
|
|||||||
import { useState, useEffect, useCallback } from 'react'
|
import { useState, useEffect, useCallback } from 'react'
|
||||||
import { useTranslations } from 'next-intl'
|
import { useTranslations } from 'next-intl'
|
||||||
import { useBetterAuth } from '@/hooks/useBetterAuth'
|
import { useBetterAuth } from '@/hooks/useBetterAuth'
|
||||||
|
import { changePassword } from '@/lib/auth-client'
|
||||||
import { Header } from '@/components/layout/Header'
|
import { Header } from '@/components/layout/Header'
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { Input } from '@/components/ui/input'
|
import { Input } from '@/components/ui/input'
|
||||||
@ -193,9 +194,19 @@ export default function ProfilePage() {
|
|||||||
setSaveStatus({ type: null, message: '' })
|
setSaveStatus({ type: null, message: '' })
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// TODO: 实现Better Auth密码更新
|
// 使用Better Auth的changePassword方法
|
||||||
// Better Auth的密码更新需要通过特殊的API端点
|
const { data, error } = await changePassword({
|
||||||
setSaveStatus({ type: 'error', message: 'Password update is not yet implemented for Better Auth' })
|
newPassword: formData.newPassword,
|
||||||
|
currentPassword: formData.currentPassword,
|
||||||
|
revokeOtherSessions: false, // 保持其他会话不被撤销
|
||||||
|
})
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
throw new Error(error.message || 'Failed to change password')
|
||||||
|
}
|
||||||
|
|
||||||
|
setSaveStatus({ type: 'success', message: t('passwordUpdatedSuccessfully') })
|
||||||
|
setFormData({ ...formData, currentPassword: '', newPassword: '', confirmPassword: '' })
|
||||||
|
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
setSaveStatus({ type: 'error', message: (error instanceof Error ? error.message : 'Unknown error') || t('failedToUpdatePassword') })
|
setSaveStatus({ type: 'error', message: (error instanceof Error ? error.message : 'Unknown error') || t('failedToUpdatePassword') })
|
||||||
|
@ -11,5 +11,6 @@ export const {
|
|||||||
signUp,
|
signUp,
|
||||||
signOut,
|
signOut,
|
||||||
useSession,
|
useSession,
|
||||||
getSession
|
getSession,
|
||||||
|
changePassword
|
||||||
} = authClient
|
} = authClient
|
Loading…
Reference in New Issue
Block a user