WeiKaiLe
WeiKaiLe
TTCTheo's Typesafe Cult
Created by WeiKaiLe on 5/6/2024 in #questions
fresh install - prisma db:push fails when using .env.development & .env.production
Thank you, I've edited the "db:push" script and that has worked.
5 replies
TTCTheo's Typesafe Cult
Created by WeiKaiLe on 2/13/2024 in #questions
App Router - How to wrap a layout in session to require login?
I ended up using the following approach, it works well enough it seems:
// added the following import
import { getServerAuthSession } from "~/server/auth";

export default async function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
const session = await getServerAuthSession();

// Check for session user and redirect if not found.
if (!session?.user) {
redirect("/api/auth/signin");
}
return (
<html lang="en">
<body className={`font-sans ${inter.variable}`}>
<TRPCReactProvider>{children}</TRPCReactProvider>
</body>
</html>
);
}
// added the following import
import { getServerAuthSession } from "~/server/auth";

export default async function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
const session = await getServerAuthSession();

// Check for session user and redirect if not found.
if (!session?.user) {
redirect("/api/auth/signin");
}
return (
<html lang="en">
<body className={`font-sans ${inter.variable}`}>
<TRPCReactProvider>{children}</TRPCReactProvider>
</body>
</html>
);
}
4 replies
TTCTheo's Typesafe Cult
Created by WeiKaiLe on 4/2/2023 in #questions
SSGHelper & GetStaticProps - Not loading data server side?
Sorry mate, I don't know. I've looked around for the last 40 mins to see if I could find anything new but no luck. If you don't manage to find an option to do it that way, could you instead fetch the first 4 items and then pass them from props to the infinite query in your component as initial data?
17 replies
TTCTheo's Typesafe Cult
Created by WeiKaiLe on 4/2/2023 in #questions
SSGHelper & GetStaticProps - Not loading data server side?
No I didn't. I couldn't manage to get ctx: createInnerTRPCContext({}), to work as per the advanced tRPC video in my post but then I saw in Theo's video he posted recently (T3 stack tutorial) that I don't need to use that, I could just give it prisma and session: null, the latter you suggested. This got rid of errors but in the reponse I was getting when I console logged props it showed it was unauthorised, so I knew I needed to give it the session details as well. perhaps console.log props and see if there is anything there to help troubleshoot from?
17 replies
TTCTheo's Typesafe Cult
Created by WeiKaiLe on 4/2/2023 in #questions
SSGHelper & GetStaticProps - Not loading data server side?
Thank you! Session was needed because it was a protected route but changing ssrAccountData to trpcState was what did the trick. Not sure why I changed that but knew I was doing something stupid. Thank you so much!
17 replies