@farm.js/create-app 0.1.0-beta.20 → 0.1.0-beta.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +8 -6
  2. package/bin/create-farm-app.js +1 -1
  3. package/dist/index.js +34 -8
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +34 -8
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/utils.js +8 -6
  8. package/dist/utils.js.map +1 -1
  9. package/dist/utils.mjs +8 -6
  10. package/dist/utils.mjs.map +1 -1
  11. package/package.json +2 -2
  12. package/templates/auth/.env.example +6 -0
  13. package/templates/auth/README.md +95 -0
  14. package/templates/auth/farm.config.ts +11 -0
  15. package/templates/auth/gitignore +10 -0
  16. package/templates/auth/package.json +32 -0
  17. package/templates/auth/pnpm-workspace.yaml +13 -0
  18. package/templates/auth/src/app/dashboard/middleware.ts +13 -0
  19. package/templates/auth/src/app/dashboard/page.tsx +140 -0
  20. package/templates/auth/src/app/error.tsx +25 -0
  21. package/templates/auth/src/app/globals.css +1064 -0
  22. package/templates/auth/src/app/layout.tsx +11 -0
  23. package/templates/auth/src/app/loading.tsx +15 -0
  24. package/templates/auth/src/app/not-found.tsx +26 -0
  25. package/templates/auth/src/app/page.tsx +46 -0
  26. package/templates/auth/src/app/sign-in/page.tsx +16 -0
  27. package/templates/auth/src/app/sign-up/page.tsx +16 -0
  28. package/templates/auth/src/components/auth-form.tsx +120 -0
  29. package/templates/auth/src/components/auth-shell.tsx +21 -0
  30. package/templates/auth/src/components/resource-links.tsx +78 -0
  31. package/templates/auth/src/components/sign-out-button.tsx +45 -0
  32. package/templates/auth/src/components/site-header.tsx +46 -0
  33. package/templates/auth/tsconfig.json +20 -0
  34. package/templates/basic/package.json +4 -2
  35. package/templates/basic/pnpm-workspace.yaml +8 -0
  36. package/templates/basic/src/app/globals.css +241 -0
  37. package/templates/basic/src/app/layout.tsx +2 -4
  38. package/templates/basic/src/app/page.tsx +20 -61
  39. package/templates/basic/src/components/resource-links.tsx +78 -0
  40. package/templates/better-auth/.env.example +3 -0
  41. package/templates/better-auth/README.md +87 -0
  42. package/templates/better-auth/farm.config.ts +29 -0
  43. package/templates/better-auth/gitignore +10 -0
  44. package/templates/better-auth/package.json +34 -0
  45. package/templates/better-auth/pnpm-workspace.yaml +13 -0
  46. package/templates/better-auth/src/app/dashboard/middleware.ts +15 -0
  47. package/templates/better-auth/src/app/dashboard/page.tsx +188 -0
  48. package/templates/better-auth/src/app/error.tsx +25 -0
  49. package/templates/better-auth/src/app/globals.css +1064 -0
  50. package/templates/better-auth/src/app/layout.tsx +11 -0
  51. package/templates/better-auth/src/app/loading.tsx +15 -0
  52. package/templates/better-auth/src/app/not-found.tsx +26 -0
  53. package/templates/better-auth/src/app/page.tsx +50 -0
  54. package/templates/better-auth/src/app/sign-in/page.tsx +16 -0
  55. package/templates/better-auth/src/app/sign-up/page.tsx +16 -0
  56. package/templates/better-auth/src/components/auth-form.tsx +120 -0
  57. package/templates/better-auth/src/components/auth-shell.tsx +21 -0
  58. package/templates/better-auth/src/components/resource-links.tsx +78 -0
  59. package/templates/better-auth/src/components/sign-out-button.tsx +45 -0
  60. package/templates/better-auth/src/components/site-header.tsx +46 -0
  61. package/templates/better-auth/src/lib/auth-client.ts +5 -0
  62. package/templates/better-auth/src/lib/auth.ts +50 -0
  63. package/templates/better-auth/src/lib/session.ts +8 -0
  64. package/templates/better-auth/tsconfig.json +20 -0
  65. package/templates/basic/src/app/about/page.tsx +0 -32
@@ -0,0 +1,140 @@
1
+ "use client";
2
+
3
+ import { useAuth } from "@farm.js/auth/client";
4
+ import { useEffect } from "react";
5
+ import { SignOutButton } from "../../components/sign-out-button";
6
+ import { SiteHeader } from "../../components/site-header";
7
+
8
+ export default function DashboardPage() {
9
+ const { isPending, session, user } = useAuth();
10
+
11
+ useEffect(() => {
12
+ if (!isPending && !user) {
13
+ window.location.replace("/sign-in");
14
+ }
15
+ }, [isPending, user]);
16
+
17
+ if (isPending) {
18
+ return (
19
+ <main className="loading-shell" aria-label="Loading account" aria-live="polite">
20
+ <div className="loading-block">
21
+ <span className="loading-label">Verifying protected session</span>
22
+ <div className="loading-line wide" />
23
+ <div className="loading-line" />
24
+ <div className="loading-grid">
25
+ <div />
26
+ <div />
27
+ </div>
28
+ </div>
29
+ </main>
30
+ );
31
+ }
32
+
33
+ if (!user || !session) {
34
+ return (
35
+ <main className="loading-shell" aria-label="Returning to sign in" aria-live="polite">
36
+ <div className="loading-block">
37
+ <span className="loading-label">Session unavailable</span>
38
+ <p className="loading-message">Returning you to the sign-in page…</p>
39
+ </div>
40
+ </main>
41
+ );
42
+ }
43
+
44
+ const createdAt = new Date(user.createdAt).toLocaleDateString("en", {
45
+ day: "numeric",
46
+ month: "short",
47
+ year: "numeric",
48
+ });
49
+ const expiresAt = new Date(session.expiresAt).toLocaleString("en", {
50
+ day: "numeric",
51
+ hour: "2-digit",
52
+ minute: "2-digit",
53
+ month: "short",
54
+ });
55
+
56
+ return (
57
+ <div className="site-frame">
58
+ <SiteHeader user={user} />
59
+
60
+ <main className="dashboard-shell">
61
+ <div className="dashboard-heading">
62
+ <div>
63
+ <span className="section-index">PROTECTED / MIDDLEWARE VERIFIED</span>
64
+ <h1>Welcome back, {user.name}.</h1>
65
+ <p>Farm route middleware verified your session before this dashboard loaded.</p>
66
+ </div>
67
+ <SignOutButton />
68
+ </div>
69
+
70
+ <section className="dashboard-grid" aria-label="Account overview">
71
+ <article className="account-panel">
72
+ <div className="panel-heading">
73
+ <span>Account</span>
74
+ <span className="status-badge">
75
+ <span className="status-dot" aria-hidden="true" />
76
+ Active
77
+ </span>
78
+ </div>
79
+ <dl className="detail-list">
80
+ <div>
81
+ <dt>Name</dt>
82
+ <dd>{user.name}</dd>
83
+ </div>
84
+ <div>
85
+ <dt>Email</dt>
86
+ <dd>{user.email}</dd>
87
+ </div>
88
+ <div>
89
+ <dt>Created</dt>
90
+ <dd>{createdAt}</dd>
91
+ </div>
92
+ </dl>
93
+ </article>
94
+
95
+ <article className="session-panel">
96
+ <div className="panel-heading">
97
+ <span>Current session</span>
98
+ <code>httpOnly cookie</code>
99
+ </div>
100
+ <dl className="detail-list">
101
+ <div>
102
+ <dt>Session ID</dt>
103
+ <dd className="mono truncate">{session.id}</dd>
104
+ </div>
105
+ <div>
106
+ <dt>Expires</dt>
107
+ <dd>{expiresAt}</dd>
108
+ </div>
109
+ <div>
110
+ <dt>Storage</dt>
111
+ <dd>SQLite locally / Postgres in production</dd>
112
+ </div>
113
+ </dl>
114
+ </article>
115
+ </section>
116
+
117
+ <section className="next-steps" aria-labelledby="next-steps-title">
118
+ <div className="section-heading compact">
119
+ <span className="section-index">NEXT / MAKE IT YOURS</span>
120
+ <h2 id="next-steps-title">The account boundary is ready for product work.</h2>
121
+ </div>
122
+ <div className="next-step-list">
123
+ <div>
124
+ <span>01</span>
125
+ <p>Set the production FARMJS Auth URL, secret, and database URL in your host.</p>
126
+ </div>
127
+ <div>
128
+ <span>02</span>
129
+ <p>Run the FARMJS Auth migration command before serving production traffic.</p>
130
+ </div>
131
+ <div>
132
+ <span>03</span>
133
+ <p>Build your first protected feature beside this dashboard route.</p>
134
+ </div>
135
+ </div>
136
+ </section>
137
+ </main>
138
+ </div>
139
+ );
140
+ }
@@ -0,0 +1,25 @@
1
+ "use client";
2
+
3
+ import type { ErrorProps } from "@farm.js/core";
4
+
5
+ export default function ErrorBoundary({ error, reset }: ErrorProps) {
6
+ const message = error instanceof Error ? error.message : "An unexpected error occurred.";
7
+
8
+ return (
9
+ <main className="error-shell">
10
+ <section className="error-panel">
11
+ <span className="section-index">ERROR / RECOVERABLE</span>
12
+ <h1>That route did not finish loading.</h1>
13
+ <p>{message}</p>
14
+ <div className="hero-actions">
15
+ <button className="button button-primary" onClick={reset} type="button">
16
+ Try again
17
+ </button>
18
+ <a className="button button-secondary" href="/">
19
+ Return home
20
+ </a>
21
+ </div>
22
+ </section>
23
+ </main>
24
+ );
25
+ }