From 9b6b5cdda9796e245c08c9bc6c6d4432073d5681 Mon Sep 17 00:00:00 2001 From: songtianlun Date: Mon, 1 Sep 2025 23:13:11 +0800 Subject: [PATCH] fix passwd change --- src/app/profile/page.tsx | 17 ++++++++++++++--- src/lib/auth-client.ts | 3 ++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/app/profile/page.tsx b/src/app/profile/page.tsx index f399bac..5bc7586 100644 --- a/src/app/profile/page.tsx +++ b/src/app/profile/page.tsx @@ -3,6 +3,7 @@ import { useState, useEffect, useCallback } from 'react' import { useTranslations } from 'next-intl' import { useBetterAuth } from '@/hooks/useBetterAuth' +import { changePassword } from '@/lib/auth-client' import { Header } from '@/components/layout/Header' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' @@ -193,9 +194,19 @@ export default function ProfilePage() { setSaveStatus({ type: null, message: '' }) try { - // TODO: 实现Better Auth密码更新 - // Better Auth的密码更新需要通过特殊的API端点 - setSaveStatus({ type: 'error', message: 'Password update is not yet implemented for Better Auth' }) + // 使用Better Auth的changePassword方法 + const { data, error } = await changePassword({ + 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) { setSaveStatus({ type: 'error', message: (error instanceof Error ? error.message : 'Unknown error') || t('failedToUpdatePassword') }) diff --git a/src/lib/auth-client.ts b/src/lib/auth-client.ts index bb818c2..e13a248 100644 --- a/src/lib/auth-client.ts +++ b/src/lib/auth-client.ts @@ -11,5 +11,6 @@ export const { signUp, signOut, useSession, - getSession + getSession, + changePassword } = authClient \ No newline at end of file