+
+
+
+
+
+
+ {props.children}
+
+ diff --git a/components/Settings.tsx b/components/Settings.tsx new file mode 100644 index 00000000..e5dd273e --- /dev/null +++ b/components/Settings.tsx @@ -0,0 +1,90 @@ +import Link from 'next/link'; +import { useRouter } from "next/router"; + +export default function SettingsShell(props) { + const router = useRouter(); + return ( +
+ We hope to see you again soon! +
+Loading...
; + } else { + if (!session) { + window.location.href = "/auth/login"; + } + } + + router.push('/settings/profile'); + + return null; +} \ No newline at end of file diff --git a/pages/settings/password.tsx b/pages/settings/password.tsx new file mode 100644 index 00000000..f6daaa9b --- /dev/null +++ b/pages/settings/password.tsx @@ -0,0 +1,104 @@ +import Head from 'next/head'; +import Link from 'next/link'; +import { useRef } from 'react'; +import prisma from '../../lib/prisma'; +import Shell from '../../components/Shell'; +import SettingsShell from '../../components/Settings'; +import { signIn, useSession, getSession } from 'next-auth/client'; + +export default function Settings(props) { + const [ session, loading ] = useSession(); + const oldPasswordRef = useRef(); + const newPasswordRef = useRef(); + + if (loading) { + returnLoading...
; + } else { + if (!session) { + window.location.href = "/auth/login"; + } + } + + async function changePasswordHandler(event) { + event.preventDefault(); + + const enteredOldPassword = oldPasswordRef.current.value; + const enteredNewPassword = newPasswordRef.current.value; + + // TODO: Add validation + + const response = await fetch('/api/auth/changepw', { + method: 'PATCH', + body: JSON.stringify({oldPassword: enteredOldPassword, newPassword: enteredNewPassword}), + headers: { + 'Content-Type': 'application/json' + } + }); + + console.log(response); + } + + return( +Loading...
; + } else { + if (!session) { + window.location.href = "/auth/login"; + } + } + + async function updateProfileHandler(event) { + event.preventDefault(); + + const enteredUsername = usernameRef.current.value; + const enteredName = nameRef.current.value; + const enteredDescription = descriptionRef.current.value; + + // TODO: Add validation + + const response = await fetch('/api/user/profile', { + method: 'PATCH', + body: JSON.stringify({username: enteredUsername, name: enteredName, description: enteredDescription}), + headers: { + 'Content-Type': 'application/json' + } + }); + + console.log(response); + } + + return( +