import { type NextPage } from "next"; import Image from "next/image"; import Head from "next/head"; import { type GetServerSideProps } from "next"; import { getServerAuthSession } from "../../server/auth"; import { api } from "~/utils/api"; import { signIn, useSession } from "next-auth/react"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; import Loading from "~/components/Loading"; import { FaGithub, FaGoogle } from "react-icons/fa"; export const getServerSideProps: GetServerSideProps = async (ctx) => { const session = await getServerAuthSession(ctx); // Redirect to login if not signed in if (!session) { return { redirect: { destination: `/api/auth/signin?callbackUrl=${ctx.resolvedUrl}`, permanent: false, }, }; } // Return session if logged in return { props: { session }, }; }; const Profile: NextPage = () => { return ( <> Sprint Padawan - Profile
); }; export default Profile; const ProfileBody: React.FC = () => { const { data: sessionData } = useSession(); const [nameText, setNameText] = useState(""); const router = useRouter(); const { data: providers, isLoading: providersLoading } = api.user.getProviders.useQuery(); const deleteUserMutation = api.user.delete.useMutation({}); const saveUserMutation = api.user.save.useMutation({}); const deleteCurrentUser = async () => { await deleteUserMutation.mutateAsync(); (document.querySelector("#delete-user-modal") as HTMLInputElement).checked = false; router.reload(); }; const saveUser = async () => { await saveUserMutation.mutateAsync({ name: nameText, }); router.reload(); }; useEffect(() => { setNameText(sessionData?.user.name || ""); }, [sessionData]); if (sessionData) { return ( <>

This action will delete ALL data associated with your account. The same GitHub Account can be used, but none of your existing data will be available. If you are sure, please confirm below:

Profile:

{sessionData.user.image && ( Profile picture. )} {providersLoading ? (
) : (
)} {sessionData.user.name && ( setNameText(event.target.value)} /> )} {sessionData.user.email && ( )} {/* */}
); } else { return

Error getting login session!

; } };