Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: conditional prefetch for protectedProcedure in auth templates #1969

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lucky-parents-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-t3-app": patch
---

fix issue with prefetch protected procedure in auth templates
4 changes: 3 additions & 1 deletion cli/template/extras/src/app/page/with-auth-trpc-tw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export default async function Home() {
const hello = await api.post.hello({ text: "from tRPC" });
const session = await getServerAuthSession();

void api.post.getLatest.prefetch();
if (session?.user) {
void api.post.getLatest.prefetch();
}

return (
<HydrateClient>
Expand Down
4 changes: 3 additions & 1 deletion cli/template/extras/src/app/page/with-auth-trpc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export default async function Home() {
const hello = await api.post.hello({ text: "from tRPC" });
const session = await getServerAuthSession();

void api.post.getLatest.prefetch();
if (session?.user) {
void api.post.getLatest.prefetch();
}

return (
<HydrateClient>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const postRouter = createTRPCRouter({
});
}),

getLatest: publicProcedure.query(async ({ ctx }) => {
getLatest: protectedProcedure.query(async ({ ctx }) => {
const post = await ctx.db.query.posts.findFirst({
orderBy: (posts, { desc }) => [desc(posts.createdAt)],
});
Expand Down
Loading