import { useRef, useState } from "react"; import prisma from "@lib/prisma"; import Modal from "@components/Modal"; import Shell from "@components/Shell"; import SettingsShell from "@components/Settings"; import { useSession } from "next-auth/client"; import Loader from "@components/Loader"; import { getSession } from "@lib/auth"; export default function Settings() { // eslint-disable-next-line @typescript-eslint/no-unused-vars const [session, loading] = useSession(); const [successModalOpen, setSuccessModalOpen] = useState(false); const oldPasswordRef = useRef(); const newPasswordRef = useRef(); if (loading) { return ; } const closeSuccessModal = () => { setSuccessModalOpen(false); }; async function changePasswordHandler(event) { event.preventDefault(); const enteredOldPassword = oldPasswordRef.current.value; const enteredNewPassword = newPasswordRef.current.value; // TODO: Add validation /*eslint-disable */ const response = await fetch("/api/auth/changepw", { method: "PATCH", body: JSON.stringify({ oldPassword: enteredOldPassword, newPassword: enteredNewPassword }), headers: { "Content-Type": "application/json", }, }); /*eslint-enable */ setSuccessModalOpen(true); } return (

); } export async function getServerSideProps(context) { const session = await getSession(context); if (!session) { return { redirect: { permanent: false, destination: "/auth/login" } }; } const user = await prisma.user.findFirst({ where: { email: session.user.email, }, select: { id: true, username: true, name: true, }, }); return { props: { user }, // will be passed to the page component as props }; }