diff --git a/app/api/user/login/route.ts b/app/api/user/login/route.ts index c47f991..71c93f4 100644 --- a/app/api/user/login/route.ts +++ b/app/api/user/login/route.ts @@ -39,6 +39,17 @@ export async function POST(request: NextRequest) { const token = jwt.sign({ id: user.id }, process.env.JWT_SECRET, { expiresIn: body.remember ? "7d" : "1h" }); + const lastLogin = new Date(); + + await prisma.user.update({ + where: { + id: user.id, + }, + data: { + lastLogin, + }, + }); + return NextResponse.json({ message: "Login successful", token }, { status: 200 }); } catch (error: any) { diff --git a/components/Success.tsx b/components/Success.tsx new file mode 100644 index 0000000..0bf8fe8 --- /dev/null +++ b/components/Success.tsx @@ -0,0 +1,46 @@ +"use client"; + +import { useEffect } from "react"; + +type SuccessToastProps = { + message: string; + show: boolean; + onClose: () => void; +}; + +export default function SuccessToast({ message, show, onClose }: SuccessToastProps) { + useEffect(() => { + if (show) { + const timer = setTimeout(() => { + onClose(); + }, 5000); + return () => clearTimeout(timer); + } + }, [show, onClose]); + + if (!show) return null; + + return ( +
+
+ + + +
+ SUCCESS: + {message} +
+
+
+ ); +} \ No newline at end of file diff --git a/components/settings/PasswordSettings.tsx b/components/settings/PasswordSettings.tsx index 070e160..e3b0f2f 100644 --- a/components/settings/PasswordSettings.tsx +++ b/components/settings/PasswordSettings.tsx @@ -3,11 +3,13 @@ import { useState } from 'react'; import axios from 'axios'; import Cookies from 'js-cookie'; +import SuccessToast from '../Success'; export const PasswordSettings = ({ onError }: { onError: (message: string) => void }) => { const [oldPassword, setOldPassword] = useState(''); const [password, setPassword] = useState(''); const [passwordConfirm, setPasswordConfirm] = useState(''); + const [success, setSuccess] = useState(''); const handleSave = async () => { if (password !== passwordConfirm) return onError('Passwords do not match'); @@ -23,52 +25,59 @@ export const PasswordSettings = ({ onError }: { onError: (message: string) => vo if (response.data.message !== 'Password updated successfully') { onError('Failed to update password'); } + setSuccess('Password updated successfully'); + setOldPassword(''); + setPassword(''); + setPasswordConfirm(''); } catch (error: any) { onError(error.response?.data?.error || 'An error occurred'); } }; return ( -
-

Password Settings

-

Manage your password

- -
-
- - setOldPassword(e.target.value)} - className="input w-full" - /> -
-
- - setPassword(e.target.value)} - className="input w-full" - /> -
-
- - setPasswordConfirm(e.target.value)} - className="input w-full" - /> +
+
+

Password Settings

+

Manage your password

+ +
+
+ + setOldPassword(e.target.value)} + className="input w-full" + /> +
+
+ + setPassword(e.target.value)} + className="input w-full" + /> +
+
+ + setPasswordConfirm(e.target.value)} + className="input w-full" + /> +
+ +
- - + setSuccess('')} />
); }; \ No newline at end of file