Skip to content

Commit 5ab503a

Browse files
fix(cli): Add conditional rendering for private data based on API type
1 parent 6a43a4f commit 5ab503a

File tree

10 files changed

+70
-56
lines changed

10 files changed

+70
-56
lines changed

.changeset/moody-chefs-follow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-better-t-stack": patch
3+
---
4+
5+
Add conditional rendering for private data based on API type in dashboard page

apps/cli/src/helpers/project-generation/template-manager.ts

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -475,33 +475,16 @@ export async function setupAuthTemplate(
475475
} else {
476476
}
477477
} else if (hasSvelteWeb) {
478-
if (context.api === "orpc") {
479-
const authWebSvelteSrc = path.join(
480-
PKG_ROOT,
481-
"templates/auth/web/svelte",
482-
);
483-
if (await fs.pathExists(authWebSvelteSrc)) {
484-
await processAndCopyFiles(
485-
"**/*",
486-
authWebSvelteSrc,
487-
webAppDir,
488-
context,
489-
);
490-
} else {
491-
}
478+
const authWebSvelteSrc = path.join(PKG_ROOT, "templates/auth/web/svelte");
479+
if (await fs.pathExists(authWebSvelteSrc)) {
480+
await processAndCopyFiles("**/*", authWebSvelteSrc, webAppDir, context);
481+
} else {
492482
}
493483
} else if (hasSolidWeb) {
494-
if (context.api === "orpc") {
495-
const authWebSolidSrc = path.join(PKG_ROOT, "templates/auth/web/solid");
496-
if (await fs.pathExists(authWebSolidSrc)) {
497-
await processAndCopyFiles(
498-
"**/*",
499-
authWebSolidSrc,
500-
webAppDir,
501-
context,
502-
);
503-
} else {
504-
}
484+
const authWebSolidSrc = path.join(PKG_ROOT, "templates/auth/web/solid");
485+
if (await fs.pathExists(authWebSolidSrc)) {
486+
await processAndCopyFiles("**/*", authWebSolidSrc, webAppDir, context);
487+
} else {
505488
}
506489
}
507490
}

apps/cli/templates/auth/web/nuxt/app/pages/dashboard.vue

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<script setup lang="ts">
2+
{{#if (eq api "orpc")}}
3+
import { useQuery } from '@tanstack/vue-query'
4+
{{/if}}
5+
const {$authClient} = useNuxtApp()
6+
7+
definePageMeta({
8+
middleware: ['auth']
9+
})
10+
11+
const { $orpc } = useNuxtApp()
12+
13+
const session = $authClient.useSession()
14+
15+
{{#if (eq api "orpc")}}
16+
const privateData = useQuery($orpc.privateData.queryOptions())
17+
{{/if}}
18+
19+
</script>
20+
21+
<template>
22+
<div class="container mx-auto p-4">
23+
<h1 class="text-2xl font-bold mb-4">Dashboard</h1>
24+
<div v-if="session?.data?.user">
25+
<p class="mb-2">Welcome \{{ session.data.user.name }}</p>
26+
</div>
27+
{{#if (eq api "orpc")}}
28+
<div v-if="privateData.status.value === 'pending'">Loading private data...</div>
29+
<div v-else-if="privateData.status.value === 'error'">Error loading private data: \{{ privateData.error.value?.message }}</div>
30+
<p v-else-if="privateData.data.value">Private Data: \{{ privateData.data.value.message }}</p>
31+
{{/if}}
32+
</div>
33+
</template>

apps/cli/templates/auth/web/react/react-router/src/routes/dashboard.tsx.hbs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import { orpc } from "@/utils/orpc";
55
{{#if (eq api "trpc")}}
66
import { trpc } from "@/utils/trpc";
77
{{/if}}
8+
{{#if ( or (eq api "orpc") (eq api "trpc"))}}
89
import { useQuery } from "@tanstack/react-query";
10+
{{/if}}
911
import { useEffect } from "react";
1012
import { useNavigate } from "react-router";
1113

@@ -34,7 +36,9 @@ export default function Dashboard() {
3436
<div>
3537
<h1>Dashboard</h1>
3638
<p>Welcome {session?.user.name}</p>
39+
{{#if ( or (eq api "orpc") (eq api "trpc"))}}
3740
<p>privateData: {privateData.data?.message}</p>
41+
{{/if}}
3842
</div>
3943
);
4044
}

apps/cli/templates/auth/web/react/tanstack-router/src/routes/dashboard.tsx.hbs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import { orpc } from "@/utils/orpc";
55
{{#if (eq api "trpc")}}
66
import { trpc } from "@/utils/trpc";
77
{{/if}}
8+
{{#if ( or (eq api "orpc") (eq api "trpc"))}}
89
import { useQuery } from "@tanstack/react-query";
10+
{{/if}}
911
import { createFileRoute } from "@tanstack/react-router";
1012
import { useEffect } from "react";
1113

@@ -41,7 +43,9 @@ function RouteComponent() {
4143
<div>
4244
<h1>Dashboard</h1>
4345
<p>Welcome {session?.user.name}</p>
46+
{{#if ( or (eq api "orpc") (eq api "trpc"))}}
4447
<p>privateData: {privateData.data?.message}</p>
48+
{{/if}}
4549
</div>
4650
);
4751
}

apps/cli/templates/auth/web/react/tanstack-start/src/routes/dashboard.tsx.hbs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { authClient } from "@/lib/auth-client";
22
{{#if (eq api "trpc")}}
33
import { useTRPC } from "@/utils/trpc";
4+
import { useQuery } from "@tanstack/react-query";
45
{{/if}}
56
{{#if (eq api "orpc")}}
67
import { orpc } from "@/utils/orpc";
7-
{{/if}}
88
import { useQuery } from "@tanstack/react-query";
9+
{{/if}}
910
import { createFileRoute } from "@tanstack/react-router";
1011
import { useEffect } from "react";
1112

@@ -45,7 +46,9 @@ function RouteComponent() {
4546
<div>
4647
<h1>Dashboard</h1>
4748
<p>Welcome {session?.user.name}</p>
49+
{{#if ( or (eq api "orpc") (eq api "trpc"))}}
4850
<p>privateData: {privateData.data?.message}</p>
51+
{{/if}}
4952
</div>
5053
);
5154
}

apps/cli/templates/auth/web/solid/src/routes/dashboard.tsx renamed to apps/cli/templates/auth/web/solid/src/routes/dashboard.tsx.hbs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { authClient } from "@/lib/auth-client";
2+
{{#if (eq api "orpc")}}
23
import { orpc } from "@/utils/orpc";
34
import { useQuery } from "@tanstack/solid-query";
5+
{{/if}}
46
import { createFileRoute } from "@tanstack/solid-router";
57
import { createEffect, Show } from "solid-js";
68

@@ -12,7 +14,9 @@ function RouteComponent() {
1214
const session = authClient.useSession();
1315
const navigate = Route.useNavigate();
1416

17+
{{#if (eq api "orpc")}}
1518
const privateData = useQuery(() => orpc.privateData.queryOptions());
19+
{{/if}}
1620

1721
createEffect(() => {
1822
if (!session().data && !session().isPending) {
@@ -31,7 +35,9 @@ function RouteComponent() {
3135
<Show when={!session().isPending && session().data}>
3236
<h1>Dashboard</h1>
3337
<p>Welcome {session().data?.user.name}</p>
38+
{{#if (eq api "orpc")}}
3439
<p>privateData: {privateData.data?.message}</p>
40+
{{/if}}
3541
</Show>
3642
</div>
3743
);

apps/cli/templates/auth/web/svelte/src/components/UserMenu.svelte

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
<script lang="ts">
22
import { authClient } from '$lib/auth-client';
33
import { goto } from '$app/navigation';
4-
import { queryClient } from '$lib/orpc';
54
65
const sessionQuery = authClient.useSession();
76
87
async function handleSignOut() {
98
await authClient.signOut({
109
fetchOptions: {
1110
onSuccess: () => {
12-
queryClient.invalidateQueries();
1311
goto('/');
1412
},
1513
onError: (error) => {

apps/cli/templates/auth/web/svelte/src/routes/dashboard/+page.svelte renamed to apps/cli/templates/auth/web/svelte/src/routes/dashboard/+page.svelte.hbs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
import { onMount } from 'svelte';
33
import { goto } from '$app/navigation';
44
import { authClient } from '$lib/auth-client';
5+
{{#if (eq api "orpc")}}
56
import { orpc } from '$lib/orpc';
67
import { createQuery } from '@tanstack/svelte-query';
8+
{{/if}}
79
import { get } from 'svelte/store';
810
911
const sessionQuery = authClient.useSession();
1012
13+
{{#if (eq api "orpc")}}
1114
const privateDataQuery = createQuery(orpc.privateData.queryOptions());
15+
{{/if}}
1216
1317
onMount(() => {
1418
const { data: session, isPending } = get(sessionQuery);
@@ -21,11 +25,12 @@
2125
{#if $sessionQuery.isPending}
2226
<div>Loading...</div>
2327
{:else if !$sessionQuery.data}
24-
<!-- Redirecting... -->
2528
{:else}
2629
<div>
2730
<h1>Dashboard</h1>
2831
<p>Welcome {$sessionQuery.data.user.name}</p>
32+
{{#if (eq api "orpc")}}
2933
<p>privateData: {$privateDataQuery.data?.message}</p>
34+
{{/if}}
3035
</div>
3136
{/if}

0 commit comments

Comments
 (0)