fix issue with ssg for resources

This commit is contained in:
Brandon Egger 2023-05-18 20:59:39 -05:00
parent a174aafbf2
commit 9fb09d9585
2 changed files with 22 additions and 7 deletions

View File

@ -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 (
<button
onClick={() => {
void signOut();
}}
className="text-sm text-neutral-300 hover:underline"
type="submit"
>
Logout of Site Admin
</button>
);
}
return (
<Link
className="text-sm text-neutral-300 hover:underline"
href={sessionData?.user ? "/admin/logout" : "/admin/login"}
href="/admin/login"
>
{sessionData?.user ? "Logout of Site Admin" : "Site Admin Login"}
Site Admin Login
</Link>
);
};

View File

@ -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,