create-efforge 0.0.0-stage → 0.2.0
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.
- package/LICENSE +21 -0
- package/README.md +88 -2
- package/dist/addon.js +115 -0
- package/dist/bin.js +13 -0
- package/dist/cli.js +28 -0
- package/dist/commands/add.js +640 -0
- package/dist/commands/create.js +319 -0
- package/dist/commands/list.js +80 -0
- package/dist/diff.js +72 -0
- package/dist/exec.js +33 -0
- package/dist/generate.js +181 -0
- package/dist/manifest.js +14 -0
- package/dist/projectName.js +41 -0
- package/dist/prompts/flow.js +122 -0
- package/dist/prompts/navigable.js +193 -0
- package/dist/routeTree.js +7 -0
- package/dist/rules.js +27 -0
- package/dist/slots.js +116 -0
- package/dist/stack.js +68 -0
- package/dist/transforms/addAlchemyResource.js +71 -0
- package/dist/transforms/addArrayItem.js +31 -0
- package/dist/transforms/addAuthPlugin.js +77 -0
- package/dist/transforms/addDevVar.js +18 -0
- package/dist/transforms/addExport.js +46 -0
- package/dist/transforms/addImport.js +11 -0
- package/dist/transforms/addLayer.js +31 -0
- package/dist/transforms/addServerFnMiddleware.js +62 -0
- package/dist/transforms/addWorkflowSecret.js +43 -0
- package/dist/transforms/addWranglerBinding.js +61 -0
- package/dist/transforms/appendAgentsSection.js +26 -0
- package/dist/transforms/errors.js +7 -0
- package/dist/transforms/index.js +40 -0
- package/dist/transforms/setWranglerValue.js +40 -0
- package/dist/transforms/util.js +219 -0
- package/dist/tree.js +1 -0
- package/dist/versions.js +73 -0
- package/dist/write.js +28 -0
- package/package.json +63 -4
- package/templates/ai/effect-ai-byok/addon.json +619 -0
- package/templates/ai/effect-ai-byok/files/core/llm-crypto.test.ts +52 -0
- package/templates/ai/effect-ai-byok/files/core/llm-crypto.ts +76 -0
- package/templates/ai/effect-ai-byok/files/core/llm-store.ts +21 -0
- package/templates/ai/effect-ai-byok/files/core/llm.ts +32 -0
- package/templates/ai/effect-ai-byok/files/drizzle/d1/20261018161056_llm_credential/migration.sql +9 -0
- package/templates/ai/effect-ai-byok/files/drizzle/d1/20261018161056_llm_credential/snapshot.json +944 -0
- package/templates/ai/effect-ai-byok/files/drizzle/pg/20261018161056_llm_credential/migration.sql +10 -0
- package/templates/ai/effect-ai-byok/files/drizzle/pg/20261018161056_llm_credential/snapshot.json +1232 -0
- package/templates/ai/effect-ai-byok/files/routes/ai.tsx +193 -0
- package/templates/ai/effect-ai-byok/files/schema/d1.ts +16 -0
- package/templates/ai/effect-ai-byok/files/schema/pg.ts +14 -0
- package/templates/ai/effect-ai-byok/files/server/ai-settings.ts +129 -0
- package/templates/ai/effect-ai-byok/files/server/ai.ts +25 -0
- package/templates/ai/effect-ai-byok/files/server/llm-env.ts +48 -0
- package/templates/ai/effect-ai-byok/files/server/llm-orgs.ts +146 -0
- package/templates/ai/effect-ai-byok/files/server/llm-provider.ts +56 -0
- package/templates/ai/effect-ai-byok/files/server/llm-store-drizzle.ts +48 -0
- package/templates/ai/effect-ai-byok/files/server/llm-store-sql-d1.ts +41 -0
- package/templates/ai/effect-ai-byok/files/server/llm-store-sql-pg.ts +41 -0
- package/templates/ai/effect-ai-byok/files/sql/d1.sql +8 -0
- package/templates/ai/effect-ai-byok/files/sql/pg.sql +8 -0
- package/templates/auth/better-auth/addon.json +424 -0
- package/templates/auth/better-auth/files/core/Auth.ts +18 -0
- package/templates/auth/better-auth/files/drizzle/d1/20261018161054_auth/migration.sql +51 -0
- package/templates/auth/better-auth/files/drizzle/d1/20261018161054_auth/snapshot.json +522 -0
- package/templates/auth/better-auth/files/drizzle/pg/20261018161053_auth/migration.sql +51 -0
- package/templates/auth/better-auth/files/drizzle/pg/20261018161053_auth/snapshot.json +680 -0
- package/templates/auth/better-auth/files/lib/auth-client.ts +4 -0
- package/templates/auth/better-auth/files/routes/app.tsx +54 -0
- package/templates/auth/better-auth/files/schema/d1/auth-schema.ts +86 -0
- package/templates/auth/better-auth/files/schema/pg/auth-schema.ts +73 -0
- package/templates/auth/better-auth/files/server/auth-live.ts +47 -0
- package/templates/auth/better-auth/files/server/session.ts +14 -0
- package/templates/auth/better-auth/files/shared/components/auth-card.tsx +32 -0
- package/templates/auth/better-auth/files/shared/components/user-menu.tsx +44 -0
- package/templates/auth/better-auth/files/shared/drizzle/d1/drizzle.config.ts +7 -0
- package/templates/auth/better-auth/files/shared/drizzle/pg/drizzle.config.ts +10 -0
- package/templates/auth/better-auth/files/shared/lib/form.ts +5 -0
- package/templates/auth/better-auth/files/shared/lib/redirect.ts +6 -0
- package/templates/auth/better-auth/files/shared/routes/app/index.tsx +54 -0
- package/templates/auth/better-auth/files/shared/routes/sign-in.tsx +85 -0
- package/templates/auth/better-auth/files/shared/routes/sign-up.tsx +91 -0
- package/templates/auth/better-auth/files/shared/server/auth-route.ts +15 -0
- package/templates/auth/better-auth/files/shared/server/auth.ts +22 -0
- package/templates/auth/better-auth/files/shared/server/db/d1-drizzle.ts +25 -0
- package/templates/auth/better-auth/files/shared/server/db/d1-effect-sql.ts +17 -0
- package/templates/auth/better-auth/files/shared/server/db/pg-drizzle.ts +32 -0
- package/templates/auth/better-auth/files/shared/server/db/pg-effect-sql.ts +29 -0
- package/templates/auth/better-auth/files/shared/server/require-session.ts +20 -0
- package/templates/auth/better-auth/files/sql/d1/0002_auth.sql +13 -0
- package/templates/auth/better-auth/files/sql/pg/0002_auth.sql +13 -0
- package/templates/auth/better-auth-orgs/addon.json +463 -0
- package/templates/auth/better-auth-orgs/files/components/org-switcher.tsx +65 -0
- package/templates/auth/better-auth-orgs/files/core/Auth.ts +20 -0
- package/templates/auth/better-auth-orgs/files/drizzle/d1/20261018161055_auth/migration.sql +88 -0
- package/templates/auth/better-auth-orgs/files/drizzle/d1/20261018161055_auth/snapshot.json +862 -0
- package/templates/auth/better-auth-orgs/files/drizzle/pg/20261018161055_auth/migration.sql +88 -0
- package/templates/auth/better-auth-orgs/files/drizzle/pg/20261018161055_auth/snapshot.json +1127 -0
- package/templates/auth/better-auth-orgs/files/lib/auth-client.ts +5 -0
- package/templates/auth/better-auth-orgs/files/routes/accept-invite.$id.tsx +68 -0
- package/templates/auth/better-auth-orgs/files/routes/app/settings/index.tsx +27 -0
- package/templates/auth/better-auth-orgs/files/routes/app/settings/members.tsx +202 -0
- package/templates/auth/better-auth-orgs/files/routes/app/settings.tsx +30 -0
- package/templates/auth/better-auth-orgs/files/routes/app.tsx +58 -0
- package/templates/auth/better-auth-orgs/files/routes/onboarding.tsx +66 -0
- package/templates/auth/better-auth-orgs/files/schema/d1/auth-schema.ts +139 -0
- package/templates/auth/better-auth-orgs/files/schema/pg/auth-schema.ts +124 -0
- package/templates/auth/better-auth-orgs/files/server/auth-live.ts +52 -0
- package/templates/auth/better-auth-orgs/files/server/session.ts +44 -0
- package/templates/auth/better-auth-orgs/files/sql/d1/0002_auth.sql +27 -0
- package/templates/auth/better-auth-orgs/files/sql/pg/0002_auth.sql +27 -0
- package/templates/base/addon.json +216 -0
- package/templates/base/files/AGENTS.md +82 -0
- package/templates/base/files/CLAUDE.md +1 -0
- package/templates/base/files/README.md +32 -0
- package/templates/base/files/core/package.json +13 -0
- package/templates/base/files/core/src/index.ts +2 -0
- package/templates/base/files/core/test/core.test.ts +4 -0
- package/templates/base/files/core/tsconfig.json +6 -0
- package/templates/base/files/gitignore +11 -0
- package/templates/base/files/pnpm-workspace.yaml +11 -0
- package/templates/base/files/root/lint/effect-tests.js +45 -0
- package/templates/base/files/root/package.json +16 -0
- package/templates/base/files/root/tsconfig.base.json +19 -0
- package/templates/base/files/root/turbo.json +9 -0
- package/templates/base/files/root/vite.config.ts +86 -0
- package/templates/base/files/web/components.json +21 -0
- package/templates/base/files/web/package.json +17 -0
- package/templates/base/files/web/src/components/theme-provider.tsx +57 -0
- package/templates/base/files/web/src/components/theme-toggle.tsx +34 -0
- package/templates/base/files/web/src/components/ui/avatar.tsx +93 -0
- package/templates/base/files/web/src/components/ui/button.tsx +61 -0
- package/templates/base/files/web/src/components/ui/card.tsx +74 -0
- package/templates/base/files/web/src/components/ui/dialog.tsx +141 -0
- package/templates/base/files/web/src/components/ui/dropdown-menu.tsx +225 -0
- package/templates/base/files/web/src/components/ui/input.tsx +20 -0
- package/templates/base/files/web/src/components/ui/label.tsx +18 -0
- package/templates/base/files/web/src/components/ui/sonner.tsx +45 -0
- package/templates/base/files/web/src/components/widgets.tsx +4 -0
- package/templates/base/files/web/src/lib/utils.ts +6 -0
- package/templates/base/files/web/src/router.tsx +12 -0
- package/templates/base/files/web/src/routes/__root.tsx +42 -0
- package/templates/base/files/web/src/routes/app/index.tsx +27 -0
- package/templates/base/files/web/src/routes/app/settings.tsx +29 -0
- package/templates/base/files/web/src/routes/app.tsx +47 -0
- package/templates/base/files/web/src/routes/index.tsx +51 -0
- package/templates/base/files/web/src/server/greeting.ts +12 -0
- package/templates/base/files/web/src/server/layers.ts +10 -0
- package/templates/base/files/web/src/server/runtime.ts +5 -0
- package/templates/base/files/web/src/styles.css +81 -0
- package/templates/base/files/web/tsconfig.json +11 -0
- package/templates/base/files/web/vite.config.ts +9 -0
- package/templates/database/d1/addon.json +118 -0
- package/templates/database/d1/files/package.json +12 -0
- package/templates/database/d1/files/tsconfig.json +5 -0
- package/templates/database/postgres/addon.json +142 -0
- package/templates/database/postgres/files/docker-compose.yml +21 -0
- package/templates/database/postgres/files/package.json +12 -0
- package/templates/database/postgres/files/runtime.ts +12 -0
- package/templates/database/postgres/files/tsconfig.json +5 -0
- package/templates/extras/browser/addon.json +173 -0
- package/templates/extras/browser/files/BrowserContainer.ts +14 -0
- package/templates/extras/browser/files/app/Dockerfile +15 -0
- package/templates/extras/browser/files/app/dockerignore +1 -0
- package/templates/extras/browser/files/app/package-lock +605 -0
- package/templates/extras/browser/files/app/package.json +9 -0
- package/templates/extras/browser/files/app/src/server.ts +78 -0
- package/templates/extras/browser/files/app/src/url-policy.ts +115 -0
- package/templates/extras/browser/files/app/tsconfig.json +6 -0
- package/templates/extras/browser/files/browser.ts +34 -0
- package/templates/extras/browser/files/core-browser.ts +21 -0
- package/templates/extras/browser/files/run-browser.ts +25 -0
- package/templates/extras/email/addon.json +182 -0
- package/templates/extras/email/files/core-mailer.ts +28 -0
- package/templates/extras/email/files/invitation-email.ts +38 -0
- package/templates/extras/email/files/mailer.ts +58 -0
- package/templates/extras/realtime/addon.json +135 -0
- package/templates/extras/realtime/files/Room.ts +46 -0
- package/templates/extras/realtime/files/core-realtime.ts +19 -0
- package/templates/extras/realtime/files/realtime-demo.tsx +40 -0
- package/templates/extras/realtime/files/realtime-limits.test.ts +32 -0
- package/templates/extras/realtime/files/realtime-limits.ts +35 -0
- package/templates/extras/realtime/files/realtime-route.ts +39 -0
- package/templates/extras/realtime/files/realtime.ts +39 -0
- package/templates/extras/realtime/files/use-room.ts +67 -0
- package/templates/extras/storage/addon.json +132 -0
- package/templates/extras/storage/files/core-storage.ts +64 -0
- package/templates/extras/storage/files/storage-route.ts +50 -0
- package/templates/extras/storage/files/storage-security.test.ts +71 -0
- package/templates/extras/storage/files/storage-security.ts +92 -0
- package/templates/extras/storage/files/storage.ts +84 -0
- package/templates/extras/workflows/addon.json +95 -0
- package/templates/extras/workflows/files/Example.ts +42 -0
- package/templates/extras/workflows/files/core-jobs.ts +45 -0
- package/templates/extras/workflows/files/example-job.ts +36 -0
- package/templates/extras/workflows/files/jobs.ts +34 -0
- package/templates/infra/alchemy/addon.json +37 -0
- package/templates/infra/alchemy/files/README.md +27 -0
- package/templates/infra/alchemy/files/alchemy.run.ts +36 -0
- package/templates/infra/alchemy/files/github/deploy.yml +63 -0
- package/templates/infra/alchemy/files/tsconfig.json +5 -0
- package/templates/infra/alchemy/files/vite.config.ts +30 -0
- package/templates/orm/drizzle/addon.json +188 -0
- package/templates/orm/drizzle/files/d1/Database.ts +7 -0
- package/templates/orm/drizzle/files/d1/drizzle/20261018154417_init/migration.sql +10 -0
- package/templates/orm/drizzle/files/d1/drizzle/20261018154417_init/snapshot.json +60 -0
- package/templates/orm/drizzle/files/d1/drizzle.config.ts +7 -0
- package/templates/orm/drizzle/files/d1/layer.ts +13 -0
- package/templates/orm/drizzle/files/d1/migrate.ts +37 -0
- package/templates/orm/drizzle/files/d1/schema.ts +15 -0
- package/templates/orm/drizzle/files/pg/Database.ts +7 -0
- package/templates/orm/drizzle/files/pg/drizzle/20261018154416_init/migration.sql +10 -0
- package/templates/orm/drizzle/files/pg/drizzle/20261018154416_init/snapshot.json +75 -0
- package/templates/orm/drizzle/files/pg/drizzle.config.ts +10 -0
- package/templates/orm/drizzle/files/pg/layer.ts +16 -0
- package/templates/orm/drizzle/files/pg/migrate.ts +24 -0
- package/templates/orm/drizzle/files/pg/schema.ts +11 -0
- package/templates/orm/drizzle/files/shared/index.ts +2 -0
- package/templates/orm/drizzle/files/shared/notes.ts +15 -0
- package/templates/orm/drizzle/files/shared/page.tsx +50 -0
- package/templates/orm/effect-sql/addon.json +124 -0
- package/templates/orm/effect-sql/files/d1/layer.ts +13 -0
- package/templates/orm/effect-sql/files/d1/migrate.ts +20 -0
- package/templates/orm/effect-sql/files/d1/schema.ts +7 -0
- package/templates/orm/effect-sql/files/d1-sql/0001_init.sql +10 -0
- package/templates/orm/effect-sql/files/pg/layer.ts +16 -0
- package/templates/orm/effect-sql/files/pg/migrate.ts +66 -0
- package/templates/orm/effect-sql/files/pg/schema.ts +7 -0
- package/templates/orm/effect-sql/files/pg-sql/0001_init.sql +10 -0
- package/templates/orm/effect-sql/files/shared/Database.ts +7 -0
- package/templates/orm/effect-sql/files/shared/index.ts +2 -0
- package/templates/orm/effect-sql/files/shared/notes.ts +18 -0
- package/templates/orm/effect-sql/files/shared/page.tsx +50 -0
- package/templates/runtime/cloudflare/addon.json +52 -0
- package/templates/runtime/cloudflare/files/cloudflare.ts +10 -0
- package/templates/runtime/cloudflare/files/routes.ts +5 -0
- package/templates/runtime/cloudflare/files/server.ts +22 -0
- package/templates/runtime/cloudflare/files/tsconfig.json +12 -0
- package/templates/runtime/cloudflare/files/vite.config.ts +20 -0
- package/templates/runtime/cloudflare/files/wrangler.jsonc +8 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { createFileRoute, Link, Outlet, redirect } from "@tanstack/react-router"
|
|
2
|
+
import { LayoutDashboard, Settings } from "lucide-react"
|
|
3
|
+
import { ThemeToggle } from "@/components/theme-toggle"
|
|
4
|
+
import { UserMenu } from "@/components/user-menu"
|
|
5
|
+
import { getSession } from "@/server/session"
|
|
6
|
+
|
|
7
|
+
export const Route = createFileRoute("/app")({
|
|
8
|
+
beforeLoad: async () => {
|
|
9
|
+
const session = await getSession()
|
|
10
|
+
if (session === null) throw redirect({ to: "/sign-in" })
|
|
11
|
+
return { session }
|
|
12
|
+
},
|
|
13
|
+
component: AppShell,
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
const nav = [
|
|
17
|
+
{ to: "/app", label: "Dashboard", icon: LayoutDashboard },
|
|
18
|
+
{ to: "/app/settings", label: "Settings", icon: Settings },
|
|
19
|
+
] as const
|
|
20
|
+
|
|
21
|
+
function AppShell() {
|
|
22
|
+
const { session } = Route.useRouteContext()
|
|
23
|
+
return (
|
|
24
|
+
<div className="grid min-h-screen grid-cols-[14rem_1fr]">
|
|
25
|
+
<aside className="flex flex-col gap-6 border-r bg-muted/40 p-4">
|
|
26
|
+
<Link to="/" className="font-semibold">
|
|
27
|
+
My app
|
|
28
|
+
</Link>
|
|
29
|
+
<nav className="flex flex-col gap-1">
|
|
30
|
+
{nav.map(({ to, label, icon: Icon }) => (
|
|
31
|
+
<Link
|
|
32
|
+
key={to}
|
|
33
|
+
to={to}
|
|
34
|
+
activeOptions={{ exact: true }}
|
|
35
|
+
className="flex items-center gap-2 rounded-md px-3 py-2 text-sm text-muted-foreground hover:bg-accent hover:text-accent-foreground [&.active]:bg-accent [&.active]:text-accent-foreground"
|
|
36
|
+
>
|
|
37
|
+
<Icon className="size-4" />
|
|
38
|
+
{label}
|
|
39
|
+
</Link>
|
|
40
|
+
))}
|
|
41
|
+
</nav>
|
|
42
|
+
</aside>
|
|
43
|
+
<div className="flex flex-col">
|
|
44
|
+
<header className="flex items-center justify-end gap-2 border-b px-6 py-3">
|
|
45
|
+
<ThemeToggle />
|
|
46
|
+
<UserMenu name={session.name} email={session.email} />
|
|
47
|
+
</header>
|
|
48
|
+
<main className="flex-1 p-6">
|
|
49
|
+
<Outlet />
|
|
50
|
+
</main>
|
|
51
|
+
</div>
|
|
52
|
+
</div>
|
|
53
|
+
)
|
|
54
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { sql } from "drizzle-orm"
|
|
2
|
+
import { sqliteTable, text, integer, index } from "drizzle-orm/sqlite-core"
|
|
3
|
+
|
|
4
|
+
export const user = sqliteTable("user", {
|
|
5
|
+
id: text("id").primaryKey(),
|
|
6
|
+
name: text("name").notNull(),
|
|
7
|
+
email: text("email").notNull().unique(),
|
|
8
|
+
emailVerified: integer("email_verified", { mode: "boolean" }).default(false).notNull(),
|
|
9
|
+
image: text("image"),
|
|
10
|
+
createdAt: integer("created_at", { mode: "timestamp_ms" })
|
|
11
|
+
.default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
|
|
12
|
+
.notNull(),
|
|
13
|
+
updatedAt: integer("updated_at", { mode: "timestamp_ms" })
|
|
14
|
+
.default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
|
|
15
|
+
.$onUpdate(() => /* @__PURE__ */ new Date())
|
|
16
|
+
.notNull(),
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
export const session = sqliteTable(
|
|
20
|
+
"session",
|
|
21
|
+
{
|
|
22
|
+
id: text("id").primaryKey(),
|
|
23
|
+
expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),
|
|
24
|
+
token: text("token").notNull().unique(),
|
|
25
|
+
createdAt: integer("created_at", { mode: "timestamp_ms" })
|
|
26
|
+
.default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
|
|
27
|
+
.notNull(),
|
|
28
|
+
updatedAt: integer("updated_at", { mode: "timestamp_ms" })
|
|
29
|
+
.$onUpdate(() => /* @__PURE__ */ new Date())
|
|
30
|
+
.notNull(),
|
|
31
|
+
ipAddress: text("ip_address"),
|
|
32
|
+
userAgent: text("user_agent"),
|
|
33
|
+
userId: text("user_id")
|
|
34
|
+
.notNull()
|
|
35
|
+
.references(() => user.id, { onDelete: "cascade" }),
|
|
36
|
+
},
|
|
37
|
+
(table) => [index("session_userId_idx").on(table.userId)],
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
export const account = sqliteTable(
|
|
41
|
+
"account",
|
|
42
|
+
{
|
|
43
|
+
id: text("id").primaryKey(),
|
|
44
|
+
accountId: text("account_id").notNull(),
|
|
45
|
+
providerId: text("provider_id").notNull(),
|
|
46
|
+
userId: text("user_id")
|
|
47
|
+
.notNull()
|
|
48
|
+
.references(() => user.id, { onDelete: "cascade" }),
|
|
49
|
+
accessToken: text("access_token"),
|
|
50
|
+
refreshToken: text("refresh_token"),
|
|
51
|
+
idToken: text("id_token"),
|
|
52
|
+
accessTokenExpiresAt: integer("access_token_expires_at", {
|
|
53
|
+
mode: "timestamp_ms",
|
|
54
|
+
}),
|
|
55
|
+
refreshTokenExpiresAt: integer("refresh_token_expires_at", {
|
|
56
|
+
mode: "timestamp_ms",
|
|
57
|
+
}),
|
|
58
|
+
scope: text("scope"),
|
|
59
|
+
password: text("password"),
|
|
60
|
+
createdAt: integer("created_at", { mode: "timestamp_ms" })
|
|
61
|
+
.default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
|
|
62
|
+
.notNull(),
|
|
63
|
+
updatedAt: integer("updated_at", { mode: "timestamp_ms" })
|
|
64
|
+
.$onUpdate(() => /* @__PURE__ */ new Date())
|
|
65
|
+
.notNull(),
|
|
66
|
+
},
|
|
67
|
+
(table) => [index("account_userId_idx").on(table.userId)],
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
export const verification = sqliteTable(
|
|
71
|
+
"verification",
|
|
72
|
+
{
|
|
73
|
+
id: text("id").primaryKey(),
|
|
74
|
+
identifier: text("identifier").notNull(),
|
|
75
|
+
value: text("value").notNull(),
|
|
76
|
+
expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),
|
|
77
|
+
createdAt: integer("created_at", { mode: "timestamp_ms" })
|
|
78
|
+
.default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
|
|
79
|
+
.notNull(),
|
|
80
|
+
updatedAt: integer("updated_at", { mode: "timestamp_ms" })
|
|
81
|
+
.default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
|
|
82
|
+
.$onUpdate(() => /* @__PURE__ */ new Date())
|
|
83
|
+
.notNull(),
|
|
84
|
+
},
|
|
85
|
+
(table) => [index("verification_identifier_idx").on(table.identifier)],
|
|
86
|
+
)
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { pgTable, text, timestamp, boolean, index } from "drizzle-orm/pg-core"
|
|
2
|
+
|
|
3
|
+
export const user = pgTable("user", {
|
|
4
|
+
id: text("id").primaryKey(),
|
|
5
|
+
name: text("name").notNull(),
|
|
6
|
+
email: text("email").notNull().unique(),
|
|
7
|
+
emailVerified: boolean("email_verified").default(false).notNull(),
|
|
8
|
+
image: text("image"),
|
|
9
|
+
createdAt: timestamp("created_at").defaultNow().notNull(),
|
|
10
|
+
updatedAt: timestamp("updated_at")
|
|
11
|
+
.defaultNow()
|
|
12
|
+
.$onUpdate(() => /* @__PURE__ */ new Date())
|
|
13
|
+
.notNull(),
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
export const session = pgTable(
|
|
17
|
+
"session",
|
|
18
|
+
{
|
|
19
|
+
id: text("id").primaryKey(),
|
|
20
|
+
expiresAt: timestamp("expires_at").notNull(),
|
|
21
|
+
token: text("token").notNull().unique(),
|
|
22
|
+
createdAt: timestamp("created_at").defaultNow().notNull(),
|
|
23
|
+
updatedAt: timestamp("updated_at")
|
|
24
|
+
.$onUpdate(() => /* @__PURE__ */ new Date())
|
|
25
|
+
.notNull(),
|
|
26
|
+
ipAddress: text("ip_address"),
|
|
27
|
+
userAgent: text("user_agent"),
|
|
28
|
+
userId: text("user_id")
|
|
29
|
+
.notNull()
|
|
30
|
+
.references(() => user.id, { onDelete: "cascade" }),
|
|
31
|
+
},
|
|
32
|
+
(table) => [index("session_userId_idx").on(table.userId)],
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
export const account = pgTable(
|
|
36
|
+
"account",
|
|
37
|
+
{
|
|
38
|
+
id: text("id").primaryKey(),
|
|
39
|
+
accountId: text("account_id").notNull(),
|
|
40
|
+
providerId: text("provider_id").notNull(),
|
|
41
|
+
userId: text("user_id")
|
|
42
|
+
.notNull()
|
|
43
|
+
.references(() => user.id, { onDelete: "cascade" }),
|
|
44
|
+
accessToken: text("access_token"),
|
|
45
|
+
refreshToken: text("refresh_token"),
|
|
46
|
+
idToken: text("id_token"),
|
|
47
|
+
accessTokenExpiresAt: timestamp("access_token_expires_at"),
|
|
48
|
+
refreshTokenExpiresAt: timestamp("refresh_token_expires_at"),
|
|
49
|
+
scope: text("scope"),
|
|
50
|
+
password: text("password"),
|
|
51
|
+
createdAt: timestamp("created_at").defaultNow().notNull(),
|
|
52
|
+
updatedAt: timestamp("updated_at")
|
|
53
|
+
.$onUpdate(() => /* @__PURE__ */ new Date())
|
|
54
|
+
.notNull(),
|
|
55
|
+
},
|
|
56
|
+
(table) => [index("account_userId_idx").on(table.userId)],
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
export const verification = pgTable(
|
|
60
|
+
"verification",
|
|
61
|
+
{
|
|
62
|
+
id: text("id").primaryKey(),
|
|
63
|
+
identifier: text("identifier").notNull(),
|
|
64
|
+
value: text("value").notNull(),
|
|
65
|
+
expiresAt: timestamp("expires_at").notNull(),
|
|
66
|
+
createdAt: timestamp("created_at").defaultNow().notNull(),
|
|
67
|
+
updatedAt: timestamp("updated_at")
|
|
68
|
+
.defaultNow()
|
|
69
|
+
.$onUpdate(() => /* @__PURE__ */ new Date())
|
|
70
|
+
.notNull(),
|
|
71
|
+
},
|
|
72
|
+
(table) => [index("verification_identifier_idx").on(table.identifier)],
|
|
73
|
+
)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Auth, Unauthorized } from "@repo/core/Auth"
|
|
2
|
+
import { getRequestHeaders } from "@tanstack/react-start/server"
|
|
3
|
+
import { Config, Context, Effect, Layer, Option, Redacted } from "effect"
|
|
4
|
+
import { WorkerConfig } from "effect-cf"
|
|
5
|
+
import { type AuthInstance, makeAuth } from "./auth"
|
|
6
|
+
import { AuthDatabase, AuthDatabaseLayer } from "./auth-database"
|
|
7
|
+
import { WorkerEnvLive } from "./cloudflare"
|
|
8
|
+
|
|
9
|
+
/** The Better Auth instance; `/api/auth/*` is served from it (see auth-route.ts). */
|
|
10
|
+
export class BetterAuth extends Context.Service<BetterAuth, AuthInstance>()("BetterAuth") {}
|
|
11
|
+
|
|
12
|
+
const BetterAuthLive = Layer.effect(
|
|
13
|
+
BetterAuth,
|
|
14
|
+
Effect.gen(function* () {
|
|
15
|
+
const { database } = yield* AuthDatabase
|
|
16
|
+
const provider = yield* WorkerConfig.provider
|
|
17
|
+
const { secret, baseURL } = yield* Effect.all({
|
|
18
|
+
secret: Config.Redacted("BETTER_AUTH_SECRET").parse(provider),
|
|
19
|
+
baseURL: Config.option(Config.String("BETTER_AUTH_URL")).parse(provider),
|
|
20
|
+
})
|
|
21
|
+
return makeAuth({
|
|
22
|
+
database,
|
|
23
|
+
secret: Redacted.value(secret),
|
|
24
|
+
baseURL: Option.getOrUndefined(Option.filter(baseURL, (url) => url !== "")),
|
|
25
|
+
})
|
|
26
|
+
}),
|
|
27
|
+
).pipe(Layer.provide(AuthDatabaseLayer), Layer.provide(WorkerEnvLive))
|
|
28
|
+
|
|
29
|
+
const unauthorized = () => new Unauthorized({ message: "Not signed in" })
|
|
30
|
+
|
|
31
|
+
/** Provides `Auth` (and `BetterAuth`). The session is read from the cookies of the request being handled. */
|
|
32
|
+
export const AuthLive = Layer.effect(
|
|
33
|
+
Auth,
|
|
34
|
+
Effect.gen(function* () {
|
|
35
|
+
const auth = yield* BetterAuth
|
|
36
|
+
return Auth.of({
|
|
37
|
+
currentSession: Effect.gen(function* () {
|
|
38
|
+
const found = yield* Effect.tryPromise({
|
|
39
|
+
try: () => auth.api.getSession({ headers: getRequestHeaders() }),
|
|
40
|
+
catch: unauthorized,
|
|
41
|
+
})
|
|
42
|
+
if (found === null) return yield* unauthorized()
|
|
43
|
+
return { userId: found.user.id, email: found.user.email, name: found.user.name }
|
|
44
|
+
}),
|
|
45
|
+
})
|
|
46
|
+
}),
|
|
47
|
+
).pipe(Layer.provideMerge(BetterAuthLive))
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Auth } from "@repo/core/Auth"
|
|
2
|
+
import { createServerFn } from "@tanstack/react-start"
|
|
3
|
+
import { Effect } from "effect"
|
|
4
|
+
import { runtime } from "./runtime"
|
|
5
|
+
|
|
6
|
+
/** The signed-in user, or null. Route guards call this. */
|
|
7
|
+
export const getSession = createServerFn({ method: "GET" }).handler(() =>
|
|
8
|
+
runtime.runPromise(
|
|
9
|
+
Effect.gen(function* () {
|
|
10
|
+
const auth = yield* Auth
|
|
11
|
+
return yield* auth.currentSession
|
|
12
|
+
}).pipe(Effect.catchTag("Unauthorized", () => Effect.succeed(null))),
|
|
13
|
+
),
|
|
14
|
+
)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ReactNode } from "react"
|
|
2
|
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
|
3
|
+
|
|
4
|
+
/** The centered card shared by the sign-in, sign-up and onboarding pages. */
|
|
5
|
+
export function AuthCard({
|
|
6
|
+
title,
|
|
7
|
+
description,
|
|
8
|
+
children,
|
|
9
|
+
footer,
|
|
10
|
+
}: {
|
|
11
|
+
title: string
|
|
12
|
+
description: string
|
|
13
|
+
children: ReactNode
|
|
14
|
+
footer?: ReactNode
|
|
15
|
+
}) {
|
|
16
|
+
return (
|
|
17
|
+
<div className="flex min-h-screen items-center justify-center p-6">
|
|
18
|
+
<Card className="w-full max-w-sm">
|
|
19
|
+
<CardHeader>
|
|
20
|
+
<CardTitle>{title}</CardTitle>
|
|
21
|
+
<CardDescription>{description}</CardDescription>
|
|
22
|
+
</CardHeader>
|
|
23
|
+
<CardContent className="space-y-4">
|
|
24
|
+
{children}
|
|
25
|
+
{footer === undefined ? null : (
|
|
26
|
+
<p className="text-center text-sm text-muted-foreground">{footer}</p>
|
|
27
|
+
)}
|
|
28
|
+
</CardContent>
|
|
29
|
+
</Card>
|
|
30
|
+
</div>
|
|
31
|
+
)
|
|
32
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Avatar, AvatarFallback } from "@/components/ui/avatar"
|
|
2
|
+
import {
|
|
3
|
+
DropdownMenu,
|
|
4
|
+
DropdownMenuContent,
|
|
5
|
+
DropdownMenuItem,
|
|
6
|
+
DropdownMenuLabel,
|
|
7
|
+
DropdownMenuSeparator,
|
|
8
|
+
DropdownMenuTrigger,
|
|
9
|
+
} from "@/components/ui/dropdown-menu"
|
|
10
|
+
import { authClient } from "@/lib/auth-client"
|
|
11
|
+
|
|
12
|
+
const initials = (name: string) =>
|
|
13
|
+
name
|
|
14
|
+
.split(/\s+/)
|
|
15
|
+
.filter(Boolean)
|
|
16
|
+
.slice(0, 2)
|
|
17
|
+
.map((part) => part.charAt(0).toUpperCase())
|
|
18
|
+
.join("") || "?"
|
|
19
|
+
|
|
20
|
+
async function signOut() {
|
|
21
|
+
await authClient.signOut()
|
|
22
|
+
window.location.assign("/sign-in")
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** The avatar in the app header; opens a menu with the account and a sign-out action. */
|
|
26
|
+
export function UserMenu({ name, email }: { name: string; email: string }) {
|
|
27
|
+
return (
|
|
28
|
+
<DropdownMenu>
|
|
29
|
+
<DropdownMenuTrigger aria-label="Account menu" className="rounded-full">
|
|
30
|
+
<Avatar>
|
|
31
|
+
<AvatarFallback>{initials(name)}</AvatarFallback>
|
|
32
|
+
</Avatar>
|
|
33
|
+
</DropdownMenuTrigger>
|
|
34
|
+
<DropdownMenuContent align="end">
|
|
35
|
+
<DropdownMenuLabel>
|
|
36
|
+
<div className="font-medium">{name}</div>
|
|
37
|
+
<div className="text-xs font-normal text-muted-foreground">{email}</div>
|
|
38
|
+
</DropdownMenuLabel>
|
|
39
|
+
<DropdownMenuSeparator />
|
|
40
|
+
<DropdownMenuItem onSelect={() => void signOut()}>Sign out</DropdownMenuItem>
|
|
41
|
+
</DropdownMenuContent>
|
|
42
|
+
</DropdownMenu>
|
|
43
|
+
)
|
|
44
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { defineConfig } from "drizzle-kit"
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
dialect: "postgresql",
|
|
5
|
+
schema: "./src/*schema.ts",
|
|
6
|
+
out: "./drizzle",
|
|
7
|
+
dbCredentials: {
|
|
8
|
+
url: process.env.DATABASE_URL ?? "postgres://postgres:postgres@localhost:5432/app",
|
|
9
|
+
},
|
|
10
|
+
})
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** A same-site path from a `?redirect=` search param, or `/app`. Anything else is ignored. */
|
|
2
|
+
export const safeRedirect = (value: unknown): string =>
|
|
3
|
+
typeof value === "string" && value.startsWith("/") && !value.startsWith("//") ? value : "/app"
|
|
4
|
+
|
|
5
|
+
export const redirectSearch = (search: Record<string, unknown>): { redirect?: string } =>
|
|
6
|
+
typeof search.redirect === "string" ? { redirect: search.redirect } : {}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { createFileRoute } from "@tanstack/react-router"
|
|
2
|
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
|
3
|
+
import { getGreeting } from "@/server/greeting"
|
|
4
|
+
import { listNotes } from "@/server/notes"
|
|
5
|
+
|
|
6
|
+
export const Route = createFileRoute("/app/")({
|
|
7
|
+
loader: async () => ({ greeting: await getGreeting(), notes: await listNotes() }),
|
|
8
|
+
component: Dashboard,
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
function Dashboard() {
|
|
12
|
+
const { session } = Route.useRouteContext()
|
|
13
|
+
const { greeting, notes } = Route.useLoaderData()
|
|
14
|
+
return (
|
|
15
|
+
<div className="space-y-6">
|
|
16
|
+
<h1 className="text-2xl font-semibold">Dashboard</h1>
|
|
17
|
+
<Card>
|
|
18
|
+
<CardHeader>
|
|
19
|
+
<CardTitle>
|
|
20
|
+
{greeting}, {session.name}
|
|
21
|
+
</CardTitle>
|
|
22
|
+
<CardDescription>
|
|
23
|
+
This text came from a server function running an Effect on the app runtime. You are
|
|
24
|
+
signed in as {session.email}.
|
|
25
|
+
</CardDescription>
|
|
26
|
+
</CardHeader>
|
|
27
|
+
</Card>
|
|
28
|
+
<Card>
|
|
29
|
+
<CardHeader>
|
|
30
|
+
<CardTitle>Notes</CardTitle>
|
|
31
|
+
<CardDescription>
|
|
32
|
+
Rows from the <code>note</code> table, read through the <code>Database</code> service.
|
|
33
|
+
</CardDescription>
|
|
34
|
+
</CardHeader>
|
|
35
|
+
<CardContent>
|
|
36
|
+
{notes.length === 0 ? (
|
|
37
|
+
<p className="text-sm text-muted-foreground">No notes yet.</p>
|
|
38
|
+
) : (
|
|
39
|
+
<ul className="space-y-2">
|
|
40
|
+
{notes.map((note) => (
|
|
41
|
+
<li key={note.id} className="flex items-baseline justify-between gap-4 text-sm">
|
|
42
|
+
<span>{note.title}</span>
|
|
43
|
+
<time className="text-muted-foreground">
|
|
44
|
+
{new Date(note.createdAt).toLocaleDateString()}
|
|
45
|
+
</time>
|
|
46
|
+
</li>
|
|
47
|
+
))}
|
|
48
|
+
</ul>
|
|
49
|
+
)}
|
|
50
|
+
</CardContent>
|
|
51
|
+
</Card>
|
|
52
|
+
</div>
|
|
53
|
+
)
|
|
54
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { createFileRoute, Link, redirect } from "@tanstack/react-router"
|
|
2
|
+
import { type SubmitEvent, useState } from "react"
|
|
3
|
+
import { AuthCard } from "@/components/auth-card"
|
|
4
|
+
import { Button } from "@/components/ui/button"
|
|
5
|
+
import { Input } from "@/components/ui/input"
|
|
6
|
+
import { Label } from "@/components/ui/label"
|
|
7
|
+
import { authClient } from "@/lib/auth-client"
|
|
8
|
+
import { formField } from "@/lib/form"
|
|
9
|
+
import { redirectSearch, safeRedirect } from "@/lib/redirect"
|
|
10
|
+
import { getSession } from "@/server/session"
|
|
11
|
+
|
|
12
|
+
export const Route = createFileRoute("/sign-in")({
|
|
13
|
+
validateSearch: redirectSearch,
|
|
14
|
+
beforeLoad: async ({ search }) => {
|
|
15
|
+
if ((await getSession()) !== null) throw redirect({ href: safeRedirect(search.redirect) })
|
|
16
|
+
},
|
|
17
|
+
component: SignIn,
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
function SignIn() {
|
|
21
|
+
const { redirect: next } = Route.useSearch()
|
|
22
|
+
const [error, setError] = useState<string | null>(null)
|
|
23
|
+
const [pending, setPending] = useState(false)
|
|
24
|
+
|
|
25
|
+
async function onSubmit(event: SubmitEvent<HTMLFormElement>) {
|
|
26
|
+
event.preventDefault()
|
|
27
|
+
const form = new FormData(event.currentTarget)
|
|
28
|
+
setPending(true)
|
|
29
|
+
setError(null)
|
|
30
|
+
const { error: failure } = await authClient.signIn.email({
|
|
31
|
+
email: formField(form, "email"),
|
|
32
|
+
password: formField(form, "password"),
|
|
33
|
+
})
|
|
34
|
+
if (failure) {
|
|
35
|
+
setError(failure.message ?? "Could not sign in")
|
|
36
|
+
setPending(false)
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
window.location.assign(safeRedirect(next))
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<AuthCard
|
|
44
|
+
title="Sign in"
|
|
45
|
+
description="Welcome back."
|
|
46
|
+
footer={
|
|
47
|
+
<>
|
|
48
|
+
No account yet?{" "}
|
|
49
|
+
<Link
|
|
50
|
+
to="/sign-up"
|
|
51
|
+
search={next === undefined ? {} : { redirect: next }}
|
|
52
|
+
className="underline"
|
|
53
|
+
>
|
|
54
|
+
Sign up
|
|
55
|
+
</Link>
|
|
56
|
+
</>
|
|
57
|
+
}
|
|
58
|
+
>
|
|
59
|
+
<form method="post" onSubmit={(event) => void onSubmit(event)} className="space-y-4">
|
|
60
|
+
<div className="space-y-2">
|
|
61
|
+
<Label htmlFor="email">Email</Label>
|
|
62
|
+
<Input id="email" name="email" type="email" autoComplete="email" required />
|
|
63
|
+
</div>
|
|
64
|
+
<div className="space-y-2">
|
|
65
|
+
<Label htmlFor="password">Password</Label>
|
|
66
|
+
<Input
|
|
67
|
+
id="password"
|
|
68
|
+
name="password"
|
|
69
|
+
type="password"
|
|
70
|
+
autoComplete="current-password"
|
|
71
|
+
required
|
|
72
|
+
/>
|
|
73
|
+
</div>
|
|
74
|
+
{error === null ? null : (
|
|
75
|
+
<p role="alert" className="text-sm text-destructive">
|
|
76
|
+
{error}
|
|
77
|
+
</p>
|
|
78
|
+
)}
|
|
79
|
+
<Button type="submit" className="w-full" disabled={pending}>
|
|
80
|
+
Sign in
|
|
81
|
+
</Button>
|
|
82
|
+
</form>
|
|
83
|
+
</AuthCard>
|
|
84
|
+
)
|
|
85
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { createFileRoute, Link, redirect } from "@tanstack/react-router"
|
|
2
|
+
import { type SubmitEvent, useState } from "react"
|
|
3
|
+
import { AuthCard } from "@/components/auth-card"
|
|
4
|
+
import { Button } from "@/components/ui/button"
|
|
5
|
+
import { Input } from "@/components/ui/input"
|
|
6
|
+
import { Label } from "@/components/ui/label"
|
|
7
|
+
import { authClient } from "@/lib/auth-client"
|
|
8
|
+
import { formField } from "@/lib/form"
|
|
9
|
+
import { redirectSearch, safeRedirect } from "@/lib/redirect"
|
|
10
|
+
import { getSession } from "@/server/session"
|
|
11
|
+
|
|
12
|
+
export const Route = createFileRoute("/sign-up")({
|
|
13
|
+
validateSearch: redirectSearch,
|
|
14
|
+
beforeLoad: async ({ search }) => {
|
|
15
|
+
if ((await getSession()) !== null) throw redirect({ href: safeRedirect(search.redirect) })
|
|
16
|
+
},
|
|
17
|
+
component: SignUp,
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
function SignUp() {
|
|
21
|
+
const { redirect: next } = Route.useSearch()
|
|
22
|
+
const [error, setError] = useState<string | null>(null)
|
|
23
|
+
const [pending, setPending] = useState(false)
|
|
24
|
+
|
|
25
|
+
async function onSubmit(event: SubmitEvent<HTMLFormElement>) {
|
|
26
|
+
event.preventDefault()
|
|
27
|
+
const form = new FormData(event.currentTarget)
|
|
28
|
+
setPending(true)
|
|
29
|
+
setError(null)
|
|
30
|
+
const { error: failure } = await authClient.signUp.email({
|
|
31
|
+
name: formField(form, "name"),
|
|
32
|
+
email: formField(form, "email"),
|
|
33
|
+
password: formField(form, "password"),
|
|
34
|
+
})
|
|
35
|
+
if (failure) {
|
|
36
|
+
setError(failure.message ?? "Could not create the account")
|
|
37
|
+
setPending(false)
|
|
38
|
+
return
|
|
39
|
+
}
|
|
40
|
+
window.location.assign(safeRedirect(next))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<AuthCard
|
|
45
|
+
title="Create an account"
|
|
46
|
+
description="Start with an email and a password."
|
|
47
|
+
footer={
|
|
48
|
+
<>
|
|
49
|
+
Already have an account?{" "}
|
|
50
|
+
<Link
|
|
51
|
+
to="/sign-in"
|
|
52
|
+
search={next === undefined ? {} : { redirect: next }}
|
|
53
|
+
className="underline"
|
|
54
|
+
>
|
|
55
|
+
Sign in
|
|
56
|
+
</Link>
|
|
57
|
+
</>
|
|
58
|
+
}
|
|
59
|
+
>
|
|
60
|
+
<form method="post" onSubmit={(event) => void onSubmit(event)} className="space-y-4">
|
|
61
|
+
<div className="space-y-2">
|
|
62
|
+
<Label htmlFor="name">Name</Label>
|
|
63
|
+
<Input id="name" name="name" autoComplete="name" required />
|
|
64
|
+
</div>
|
|
65
|
+
<div className="space-y-2">
|
|
66
|
+
<Label htmlFor="email">Email</Label>
|
|
67
|
+
<Input id="email" name="email" type="email" autoComplete="email" required />
|
|
68
|
+
</div>
|
|
69
|
+
<div className="space-y-2">
|
|
70
|
+
<Label htmlFor="password">Password</Label>
|
|
71
|
+
<Input
|
|
72
|
+
id="password"
|
|
73
|
+
name="password"
|
|
74
|
+
type="password"
|
|
75
|
+
autoComplete="new-password"
|
|
76
|
+
minLength={8}
|
|
77
|
+
required
|
|
78
|
+
/>
|
|
79
|
+
</div>
|
|
80
|
+
{error === null ? null : (
|
|
81
|
+
<p role="alert" className="text-sm text-destructive">
|
|
82
|
+
{error}
|
|
83
|
+
</p>
|
|
84
|
+
)}
|
|
85
|
+
<Button type="submit" className="w-full" disabled={pending}>
|
|
86
|
+
Create account
|
|
87
|
+
</Button>
|
|
88
|
+
</form>
|
|
89
|
+
</AuthCard>
|
|
90
|
+
)
|
|
91
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Effect } from "effect"
|
|
2
|
+
import { BetterAuth } from "./auth-live"
|
|
3
|
+
import type { WorkerRoute } from "./routes"
|
|
4
|
+
import { runtime } from "./runtime"
|
|
5
|
+
|
|
6
|
+
/** Serves Better Auth's HTTP API under `/api/auth/*` (sign-in, sign-up, sessions, organizations). */
|
|
7
|
+
export const authRoute: WorkerRoute = async (request) => {
|
|
8
|
+
if (!new URL(request.url).pathname.startsWith("/api/auth/")) return undefined
|
|
9
|
+
return runtime.runPromise(
|
|
10
|
+
Effect.gen(function* () {
|
|
11
|
+
const auth = yield* BetterAuth
|
|
12
|
+
return yield* Effect.promise(() => auth.handler(request))
|
|
13
|
+
}),
|
|
14
|
+
)
|
|
15
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type BetterAuthOptions, betterAuth } from "better-auth"
|
|
2
|
+
|
|
3
|
+
export interface AuthSettings {
|
|
4
|
+
readonly database: NonNullable<BetterAuthOptions["database"]>
|
|
5
|
+
readonly secret: string
|
|
6
|
+
readonly baseURL: string | undefined
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Better Auth for one request scope (see auth-live.ts). `efforge add` appends plugins to the
|
|
11
|
+
* `plugins` list, so keep the `plugins: [...]` array shape.
|
|
12
|
+
*/
|
|
13
|
+
export const makeAuth = ({ database, secret, baseURL }: AuthSettings) =>
|
|
14
|
+
betterAuth({
|
|
15
|
+
database,
|
|
16
|
+
secret,
|
|
17
|
+
...(baseURL === undefined ? {} : { baseURL }),
|
|
18
|
+
emailAndPassword: { enabled: true },
|
|
19
|
+
plugins: [/* efforge:auth-plugins */],
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
export type AuthInstance = ReturnType<typeof makeAuth>
|