From 9fb09d95852e3324bd5b6911ebaed47d6f45e405 Mon Sep 17 00:00:00 2001 From: Brandon Egger Date: Thu, 18 May 2023 20:59:39 -0500 Subject: [PATCH] fix issue with ssg for resources --- src/components/Footer.tsx | 20 +++++++++++++++++--- src/pages/resources/[id].tsx | 9 +++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/components/Footer.tsx b/src/components/Footer.tsx index 1014fd2..46d8489 100644 --- a/src/components/Footer.tsx +++ b/src/components/Footer.tsx @@ -1,7 +1,7 @@ import { type NextPage } from "next/types"; import Image from "next/image"; import Link from "next/link"; -import { useSession } from "next-auth/react"; +import { signOut, useSession } from "next-auth/react"; interface QuickLink { label: string; @@ -97,12 +97,26 @@ const ContactInfo = ({ name, title, email, phone }: ContactInfo) => { const AdminLogin = () => { const { data: sessionData } = useSession(); + if (sessionData?.user) { + return ( + + ); + } + return ( - {sessionData?.user ? "Logout of Site Admin" : "Site Admin Login"} + Site Admin Login ); }; diff --git a/src/pages/resources/[id].tsx b/src/pages/resources/[id].tsx index 8a16ffb..a727eaf 100644 --- a/src/pages/resources/[id].tsx +++ b/src/pages/resources/[id].tsx @@ -1,6 +1,6 @@ import { type InferGetStaticPropsType, type GetStaticPropsContext } from "next"; import { GlobeAltIcon, DocumentIcon } from "@heroicons/react/24/solid"; -import { createProxySSGHelpers } from "@trpc/react-query/ssg"; +import { createServerSideHelpers } from "@trpc/react-query/server"; import { appRouter } from "~/server/api/root"; import { prisma } from "~/server/db"; import { api } from "~/utils/api"; @@ -31,20 +31,21 @@ export const getStaticPaths = async () => { export async function getStaticProps( context: GetStaticPropsContext<{ id: string }> ) { - const ssg = createProxySSGHelpers({ + const helpers = createServerSideHelpers({ router: appRouter, ctx: { prisma, session: null, }, }); + const id = context.params?.id as string; - await ssg.auditoryResource.byId.prefetch({ id }); + await helpers.auditoryResource.byId.prefetch({ id }); return { props: { - trpcState: ssg.dehydrate(), + trpcState: helpers.dehydrate(), id, }, revalidate: 1,