From a64e6865dc716439bd4b05f1bfb8489e9912d449 Mon Sep 17 00:00:00 2001 From: Alexey Dudarev <24899236+d-alex171@users.noreply.github.com> Date: Sat, 24 Jan 2026 11:28:05 -0800 Subject: [PATCH 1/2] added change password dialog --- .../pages/security-settings-content.tsx | 199 +++++++++++++++++- 1 file changed, 197 insertions(+), 2 deletions(-) diff --git a/src/components/settings/pages/security-settings-content.tsx b/src/components/settings/pages/security-settings-content.tsx index 05718669..b6e45b26 100644 --- a/src/components/settings/pages/security-settings-content.tsx +++ b/src/components/settings/pages/security-settings-content.tsx @@ -1,3 +1,198 @@ +import React, { useState } from 'react'; +import { createAuthClient } from 'better-auth/client'; +import { Button } from '@/components/ui/button'; +import { Input } from '@/components/ui/input'; +import { Label } from '@/components/ui/label'; +import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; +import { Separator } from '@/components/ui/separator'; +import { AlertCircle, LogOut, Shield, Lock } from 'lucide-react'; +import { Alert, AlertDescription } from '@/components/ui/alert'; + export function SecuritySettingsContent() { - return <>Security coming soon...>; -} + const [currentPassword, setCurrentPassword] = useState(''); + const [newPassword, setNewPassword] = useState(''); + const [confirmPassword, setConfirmPassword] = useState(''); + const [loading, setLoading] = useState(false); + const [message, setMessage] = useState<{ type: 'success' | 'error'; text: string } | null>(null); + + const authClient = createAuthClient() + + const handleLogout = async () => { + try { + setLoading(true); + await authClient.signOut(); + setMessage({ type: 'success', text: 'Successfully logged out' }); + // Redirect to login page + window.location.href = '/login'; + } catch (error) { + setMessage({ type: 'error', text: 'Failed to logout. Please try again.' }); + } finally { + setLoading(false); + } + }; + + const handleRevokeAllSessions = async () => { + try { + setLoading(true); + await authClient.revokeOtherSessions(); + setMessage({ type: 'success', text: 'All other sessions have been revoked' }); + } catch (error) { + setMessage({ type: 'error', text: 'Failed to revoke sessions. Please try again.' }); + } finally { + setLoading(false); + } + }; + + const handleChangePassword = async () => { + setMessage(null); + + if (newPassword !== confirmPassword) { + setMessage({ type: 'error', text: 'New passwords do not match' }); + return; + } + + if (newPassword.length < 8) { + setMessage({ type: 'error', text: 'Password must be at least 8 characters long' }); + return; + } + + try { + setLoading(true); + await authClient.changePassword({ + currentPassword, + newPassword, + revokeOtherSessions: false, + }); + setMessage({ type: 'success', text: 'Password changed successfully' }); + setCurrentPassword(''); + setNewPassword(''); + setConfirmPassword(''); + } catch (error) { + setMessage({ type: 'error', text: 'Failed to change password. Please check your current password.' }); + } finally { + setLoading(false); + } + }; + + return ( +
+ Manage your account security and sessions +
+Logout from all devices
++ End all sessions except the current one +
+
@@ -140,7 +132,6 @@ export function SecuritySettingsContent() {
- {/* Session Management Section */}