Skip to content

Commit

Permalink
fix issue with prefetch protected procedure in auth templates
Browse files Browse the repository at this point in the history
Fixes #1961

Add condition to prefetch `getLatest` only if the user is authenticated.
  • Loading branch information
Guria committed Aug 19, 2024
1 parent 4885a97 commit f22405b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
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

0 comments on commit f22405b

Please sign in to comment.