Skip to content

Commit 72f787e

Browse files
committed
fix(create): exclude better-auth demo integration files when demo is disabled
The better-auth header-user components reference the /demo/better-auth route, which doesn't exist when users opt out of demo files. Convert these to EJS templates with conditional rendering so they return null instead of linking to a non-existent route. Also extend isDemoFilePath filtering to cover add-on integration files (previously only routes, lib, hooks, data, and components were filtered in a037c4d).
1 parent a037c4d commit 72f787e

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

packages/create/src/create-app.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ function isDemoFilePath(path?: string) {
2929
normalized.includes('/lib/demo.') ||
3030
normalized.includes('/hooks/demo-') ||
3131
normalized.includes('/hooks/demo.') ||
32-
normalized.includes('/data/demo.') ||
3332
normalized.includes('/data/demo-') ||
33+
normalized.includes('/data/demo.') ||
3434
normalized.includes('/components/demo-') ||
3535
normalized.includes('/components/demo.')
3636
)
@@ -49,10 +49,15 @@ function stripExamplesFromOptions(options: Options): Options {
4949
!isDemoFilePath(route.path) &&
5050
!(route.url && route.url.startsWith('/demo')),
5151
)
52+
53+
const filteredIntegrations = (addOn.integrations || []).filter(
54+
(integration) => !isDemoFilePath(integration.path)
55+
)
5256

5357
return {
5458
...addOn,
5559
routes: filteredRoutes,
60+
integrations: filteredIntegrations,
5661
getFiles: async () => {
5762
const files = await addOn.getFiles()
5863
return files.filter((file) => !isDemoFilePath(file))

packages/create/src/frameworks/react/add-ons/better-auth/assets/src/integrations/better-auth/header-user.tsx renamed to packages/create/src/frameworks/react/add-ons/better-auth/assets/src/integrations/better-auth/header-user.tsx.ejs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { authClient } from "#/lib/auth-client";
2+
<%_ if (routes.some(r => r.url === '/demo/better-auth')) { _%>
23
import { Link } from "@tanstack/react-router";
4+
<%_ } _%>
35

46
export default function BetterAuthHeader() {
57
const { data: session, isPending } = authClient.useSession();
@@ -34,6 +36,7 @@ export default function BetterAuthHeader() {
3436
);
3537
}
3638

39+
<%_ if (routes.some(r => r.url === '/demo/better-auth')) { _%>
3740
return (
3841
<Link
3942
to="/demo/better-auth"
@@ -42,4 +45,7 @@ export default function BetterAuthHeader() {
4245
Sign in
4346
</Link>
4447
);
48+
<%_ } else { _%>
49+
return null;
50+
<%_ } _%>
4551
}

packages/create/src/frameworks/solid/add-ons/better-auth/assets/src/integrations/better-auth/header-user.tsx renamed to packages/create/src/frameworks/solid/add-ons/better-auth/assets/src/integrations/better-auth/header-user.tsx.ejs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Show } from "solid-js";
2+
<%_ if (routes.some(r => r.url === '/demo/better-auth')) { _%>
23
import { Link } from "@tanstack/solid-router";
4+
<%_ } _%>
35
import { authClient } from "../../lib/auth-client";
46

57
export default function BetterAuthHeader() {
@@ -14,6 +16,7 @@ export default function BetterAuthHeader() {
1416
>
1517
<Show
1618
when={session().data?.user}
19+
<%_ if (routes.some(r => r.url === '/demo/better-auth')) { _%>
1720
fallback={
1821
<Link
1922
to="/demo/better-auth"
@@ -22,6 +25,7 @@ export default function BetterAuthHeader() {
2225
Sign in
2326
</Link>
2427
}
28+
<%_ } _%>
2529
>
2630
{(user) => (
2731
<div class="flex items-center gap-2">

0 commit comments

Comments
 (0)