Skip to content

Commit

Permalink
fix prefetch 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.

* Modify `cli/template/extras/src/app/page/with-auth-trpc-tw.tsx` to add a condition to prefetch `getLatest` only if the user is authenticated.
* Modify `cli/template/extras/src/app/page/with-auth-trpc.tsx` to add a condition to prefetch `getLatest` only if the user is authenticated.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/t3-oss/create-t3-app/issues/1961?shareId=XXXX-XXXX-XXXX-XXXX).
  • Loading branch information
Guria committed Aug 19, 2024
1 parent 4885a97 commit 93a3dc9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
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 93a3dc9

Please sign in to comment.