diff --git a/app/api/user/validate/route.ts b/app/api/user/validate/route.ts index 9573f4e..f985fd3 100644 --- a/app/api/user/validate/route.ts +++ b/app/api/user/validate/route.ts @@ -30,7 +30,7 @@ export async function POST(request: NextRequest) { return NextResponse.json({ error: "User not found" }, { status: 404 }); } - return NextResponse.json({ message: "Valid", username: user.username, name: user.name }, { status: 200 }); + return NextResponse.json({ message: "Valid", username: user.username, name: user.name, email: user.email }, { status: 200 }); } catch (error: any) { return NextResponse.json({ error: "Internal Server Error" }, { status: 500 }); diff --git a/app/dashboard/settings/SettingsPage.tsx b/app/dashboard/settings/SettingsPage.tsx index b16fe65..3f6f862 100644 --- a/app/dashboard/settings/SettingsPage.tsx +++ b/app/dashboard/settings/SettingsPage.tsx @@ -1,13 +1,37 @@ "use client"; import Sidebar from "@/components/Sidebar"; +import { useState } from "react"; +import axios from "axios"; +import Cookies from "js-cookie"; interface DashboardPageProps { username: string; name: string; + email: string; } -export default function DashboardPage({ username, name }: DashboardPageProps) { +export default function DashboardPage({ username, name, email }: DashboardPageProps) { + const [profileUsername, setProfileUsername] = useState(username); + const [profileName, setProfileName] = useState(name); + const [profileEmail, setProfileEmail] = useState(email); + const [password, setPassword] = useState(""); + const [passwordConfirm, setPasswordConfirm] = useState(""); + + const saveProfile = async () => { + const response = await axios.post("/api/user/change/profile", { token: Cookies.get("token"), username: profileUsername, name: profileName, email: profileEmail }); + if (response.data.message !== "Profile updated successfully") { + alert("Failed to update profile"); + } + } + + const savePassword = async () => { + const response = await axios.post("/api/user/change/password", { token: Cookies.get("token"), old_password: password, password: passwordConfirm }); + if (response.data.message !== "Password updated successfully") { + alert("Failed to update password"); + } + } + return (
Manage your profile settings
+Manage your password
+