import { useState, useEffect } from 'react'; import { Authentication } from '../../../scripts/pocketbase/Authentication'; import { SendLog } from '../../../scripts/pocketbase/SendLog'; import { toast } from 'react-hot-toast'; import PasswordChangeSettings from './PasswordChangeSettings'; interface AccountSecuritySettingsProps { logtoAppId: string; logtoAppSecret: string; logtoEndpoint: string; logtoTokenEndpoint: string; logtoApiEndpoint: string; } export default function AccountSecuritySettings({ logtoAppId, logtoAppSecret, logtoEndpoint, logtoTokenEndpoint, logtoApiEndpoint }: AccountSecuritySettingsProps) { const auth = Authentication.getInstance(); const logger = SendLog.getInstance(); const [isAuthenticated, setIsAuthenticated] = useState(false); const [loading, setLoading] = useState(true); const [sessionInfo, setSessionInfo] = useState({ lastLogin: '', browser: '', device: '', }); useEffect(() => { const checkAuth = () => { const authenticated = auth.isAuthenticated(); setIsAuthenticated(authenticated); if (authenticated) { const user = auth.getCurrentUser(); if (user) { // Get last login time const lastLogin = user.last_login || user.updated; // Get browser and device info const userAgent = navigator.userAgent; const browser = detectBrowser(userAgent); const device = detectDevice(userAgent); setSessionInfo({ lastLogin: formatDate(lastLogin), browser, device, }); } } setLoading(false); }; checkAuth(); }, []); // No logout functions needed here as logout is handled in the dashboard menu const detectBrowser = (userAgent: string): string => { if (userAgent.indexOf('Chrome') > -1) return 'Chrome'; if (userAgent.indexOf('Safari') > -1) return 'Safari'; if (userAgent.indexOf('Firefox') > -1) return 'Firefox'; if (userAgent.indexOf('MSIE') > -1 || userAgent.indexOf('Trident') > -1) return 'Internet Explorer'; if (userAgent.indexOf('Edge') > -1) return 'Edge'; return 'Unknown Browser'; }; const detectDevice = (userAgent: string): string => { if (/Android/i.test(userAgent)) return 'Android Device'; if (/iPhone|iPad|iPod/i.test(userAgent)) return 'iOS Device'; if (/Windows/i.test(userAgent)) return 'Windows Device'; if (/Mac/i.test(userAgent)) return 'Mac Device'; if (/Linux/i.test(userAgent)) return 'Linux Device'; return 'Unknown Device'; }; const formatDate = (dateString: string): string => { if (!dateString) return 'Unknown'; const date = new Date(dateString); return new Intl.DateTimeFormat('en-US', { year: 'numeric', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit', second: '2-digit', timeZoneName: 'short' }).format(date); }; if (loading) { return (
); } if (!isAuthenticated) { return (
You must be logged in to access this page.
); } return (
{/* Current Session Information */}

Current Session

Last Login

{sessionInfo.lastLogin}

Browser

{sessionInfo.browser}

Device

{sessionInfo.device}

{/* Password Change Section */}

Change Password

Update your account password. For security reasons, you'll need to provide your current password.

Please note: This will only update your password for the IEEE UCSD SSO. This will not update the password for your @ieeeucsd.org mail account.

{/* Authentication Options */}

Authentication Options

IEEE UCSD uses Single Sign-On (SSO) for authentication. Password management is handled through your IEEEUCSD account.

{/* Account Actions */}

Account Actions

If you need to delete your account or have other account-related issues, please contact an IEEE UCSD administrator.

To log out of your account, use the Logout option in the dashboard menu.

); }