create-better-t-stack 0.1.0 → 1.0.2
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/README.md +59 -49
- package/dist/index.js +135 -305
- package/package.json +19 -11
- package/template/base/_gitignore +2 -0
- package/template/base/package.json +18 -0
- package/template/base/packages/client/_gitignore +23 -0
- package/template/base/packages/client/components.json +21 -0
- package/template/base/packages/client/index.html +12 -0
- package/template/base/packages/client/package.json +49 -0
- package/template/base/packages/client/src/components/header.tsx +31 -0
- package/template/base/packages/client/src/components/loader.tsx +9 -0
- package/template/base/packages/client/src/components/mode-toggle.tsx +37 -0
- package/template/base/packages/client/src/components/theme-provider.tsx +73 -0
- package/template/base/packages/client/src/components/ui/button.tsx +57 -0
- package/template/base/packages/client/src/components/ui/card.tsx +92 -0
- package/template/base/packages/client/src/components/ui/checkbox.tsx +30 -0
- package/template/base/packages/client/src/components/ui/dropdown-menu.tsx +199 -0
- package/template/base/packages/client/src/components/ui/input.tsx +22 -0
- package/template/base/packages/client/src/components/ui/label.tsx +24 -0
- package/template/base/packages/client/src/components/ui/skeleton.tsx +15 -0
- package/template/base/packages/client/src/components/ui/sonner.tsx +29 -0
- package/template/base/packages/client/src/index.css +119 -0
- package/template/base/packages/client/src/lib/utils.ts +6 -0
- package/template/base/packages/client/src/main.tsx +72 -0
- package/template/base/packages/client/src/routes/__root.tsx +58 -0
- package/template/base/packages/client/src/routes/index.tsx +89 -0
- package/template/base/packages/client/src/utils/trpc.ts +4 -0
- package/template/base/packages/client/tsconfig.json +18 -0
- package/template/base/packages/client/vite.config.ts +14 -0
- package/template/base/packages/server/_gitignore +36 -0
- package/template/base/packages/server/package.json +27 -0
- package/template/base/packages/server/src/index.ts +41 -0
- package/template/base/packages/server/src/lib/context.ts +13 -0
- package/template/base/packages/server/src/lib/trpc.ts +8 -0
- package/template/base/packages/server/src/routers/index.ts +11 -0
- package/template/base/packages/server/tsconfig.json +18 -0
- package/template/base/turbo.json +27 -0
- package/template/examples/todo/packages/client/src/routes/todos.tsx +128 -0
- package/template/examples/todo/packages/server/src/routers/with-drizzle-todo.ts +44 -0
- package/template/examples/todo/packages/server/src/routers/with-prisma-todo.ts +55 -0
- package/template/with-auth/packages/client/src/components/auth-forms.tsx +13 -0
- package/template/with-auth/packages/client/src/components/header.tsx +34 -0
- package/template/with-auth/packages/client/src/components/sign-in-form.tsx +139 -0
- package/template/with-auth/packages/client/src/components/sign-up-form.tsx +164 -0
- package/template/with-auth/packages/client/src/components/user-menu.tsx +62 -0
- package/template/with-auth/packages/client/src/lib/auth-client.ts +5 -0
- package/template/with-auth/packages/client/src/main.tsx +78 -0
- package/template/with-auth/packages/client/src/routes/dashboard.tsx +36 -0
- package/template/with-auth/packages/client/src/routes/login.tsx +11 -0
- package/template/with-auth/packages/server/src/index.ts +46 -0
- package/template/with-auth/packages/server/src/lib/trpc.ts +24 -0
- package/template/with-auth/packages/server/src/routers/index.ts +19 -0
- package/template/with-biome/biome.json +42 -0
- package/template/with-drizzle-postgres/packages/server/drizzle.config.ts +10 -0
- package/template/with-drizzle-postgres/packages/server/src/db/index.ts +5 -0
- package/template/with-drizzle-postgres/packages/server/src/db/schema/auth.ts +47 -0
- package/template/with-drizzle-postgres/packages/server/src/db/schema/todo.ts +7 -0
- package/template/with-drizzle-postgres/packages/server/src/routers/todo.ts +44 -0
- package/template/with-drizzle-postgres/packages/server/src/with-auth-lib/auth.ts +15 -0
- package/template/with-drizzle-postgres/packages/server/src/with-auth-lib/context.ts +18 -0
- package/template/with-drizzle-postgres/packages/server/src/with-auth-lib/trpc.ts +24 -0
- package/template/with-drizzle-sqlite/packages/server/drizzle.config.ts +11 -0
- package/template/with-drizzle-sqlite/packages/server/src/db/index.ts +9 -0
- package/template/with-drizzle-sqlite/packages/server/src/db/schema/auth.ts +61 -0
- package/template/with-drizzle-sqlite/packages/server/src/db/schema/todo.ts +7 -0
- package/template/with-drizzle-sqlite/packages/server/src/with-auth-lib/auth.ts +15 -0
- package/template/with-drizzle-sqlite/packages/server/src/with-auth-lib/context.ts +18 -0
- package/template/with-drizzle-sqlite/packages/server/src/with-auth-lib/trpc.ts +24 -0
- package/template/with-husky/.husky/pre-commit +1 -0
- package/template/with-prisma-postgres/packages/server/prisma/index.ts +5 -0
- package/template/with-prisma-postgres/packages/server/prisma/schema/auth.prisma +59 -0
- package/template/with-prisma-postgres/packages/server/prisma/schema/schema.prisma +9 -0
- package/template/with-prisma-postgres/packages/server/prisma/schema/todo.prisma +7 -0
- package/template/with-prisma-postgres/packages/server/src/with-auth-lib/auth.ts +17 -0
- package/template/with-prisma-postgres/packages/server/src/with-auth-lib/context.ts +18 -0
- package/template/with-prisma-postgres/packages/server/src/with-auth-lib/trpc.ts +24 -0
- package/template/with-prisma-sqlite/packages/server/prisma/index.ts +5 -0
- package/template/with-prisma-sqlite/packages/server/prisma/schema/auth.prisma +59 -0
- package/template/with-prisma-sqlite/packages/server/prisma/schema/schema.prisma +8 -0
- package/template/with-prisma-sqlite/packages/server/prisma/schema/todo.prisma +7 -0
- package/template/with-prisma-sqlite/packages/server/src/with-auth-lib/auth.ts +17 -0
- package/template/with-prisma-sqlite/packages/server/src/with-auth-lib/context.ts +18 -0
- package/template/with-prisma-sqlite/packages/server/src/with-auth-lib/trpc.ts +24 -0
- package/template/with-pwa/packages/client/public/logo.png +0 -0
- package/template/with-pwa/packages/client/pwa-assets.config.ts +12 -0
- package/template/with-pwa/packages/client/vite.config.ts +35 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { betterAuth } from "better-auth";
|
|
2
|
+
import { prismaAdapter } from "better-auth/adapters/prisma";
|
|
3
|
+
import prisma from "../../prisma";
|
|
4
|
+
|
|
5
|
+
export const auth = betterAuth({
|
|
6
|
+
database: prismaAdapter(prisma, {
|
|
7
|
+
provider: "pg",
|
|
8
|
+
}),
|
|
9
|
+
trustedOrigins: [process.env.CORS_ORIGIN || ""],
|
|
10
|
+
emailAndPassword: { enabled: true },
|
|
11
|
+
advanced: {
|
|
12
|
+
defaultCookieAttributes: {
|
|
13
|
+
sameSite: "none",
|
|
14
|
+
secure: true,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Context as HonoContext } from "hono";
|
|
2
|
+
import { auth } from "./auth";
|
|
3
|
+
|
|
4
|
+
export type CreateContextOptions = {
|
|
5
|
+
hono: HonoContext;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export async function createContext({ hono }: CreateContextOptions) {
|
|
9
|
+
const session = await auth.api.getSession({
|
|
10
|
+
headers: hono.req.raw.headers,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
session,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type Context = Awaited<ReturnType<typeof createContext>>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { initTRPC, TRPCError } from "@trpc/server";
|
|
2
|
+
import type { Context } from "./context";
|
|
3
|
+
|
|
4
|
+
export const t = initTRPC.context<Context>().create();
|
|
5
|
+
|
|
6
|
+
export const router = t.router;
|
|
7
|
+
|
|
8
|
+
export const publicProcedure = t.procedure;
|
|
9
|
+
|
|
10
|
+
export const protectedProcedure = t.procedure.use(({ ctx, next }) => {
|
|
11
|
+
if (!ctx.session) {
|
|
12
|
+
throw new TRPCError({
|
|
13
|
+
code: "UNAUTHORIZED",
|
|
14
|
+
message: "Authentication required",
|
|
15
|
+
cause: "No session",
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return next({
|
|
19
|
+
ctx: {
|
|
20
|
+
...ctx,
|
|
21
|
+
session: ctx.session,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
model User {
|
|
2
|
+
id String @id @map("_id")
|
|
3
|
+
name String
|
|
4
|
+
email String
|
|
5
|
+
emailVerified Boolean
|
|
6
|
+
image String?
|
|
7
|
+
createdAt DateTime
|
|
8
|
+
updatedAt DateTime
|
|
9
|
+
sessions Session[]
|
|
10
|
+
accounts Account[]
|
|
11
|
+
|
|
12
|
+
@@unique([email])
|
|
13
|
+
@@map("user")
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
model Session {
|
|
17
|
+
id String @id @map("_id")
|
|
18
|
+
expiresAt DateTime
|
|
19
|
+
token String
|
|
20
|
+
createdAt DateTime
|
|
21
|
+
updatedAt DateTime
|
|
22
|
+
ipAddress String?
|
|
23
|
+
userAgent String?
|
|
24
|
+
userId String
|
|
25
|
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
26
|
+
|
|
27
|
+
@@unique([token])
|
|
28
|
+
@@map("session")
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
model Account {
|
|
32
|
+
id String @id @map("_id")
|
|
33
|
+
accountId String
|
|
34
|
+
providerId String
|
|
35
|
+
userId String
|
|
36
|
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
37
|
+
accessToken String?
|
|
38
|
+
refreshToken String?
|
|
39
|
+
idToken String?
|
|
40
|
+
accessTokenExpiresAt DateTime?
|
|
41
|
+
refreshTokenExpiresAt DateTime?
|
|
42
|
+
scope String?
|
|
43
|
+
password String?
|
|
44
|
+
createdAt DateTime
|
|
45
|
+
updatedAt DateTime
|
|
46
|
+
|
|
47
|
+
@@map("account")
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
model Verification {
|
|
51
|
+
id String @id @map("_id")
|
|
52
|
+
identifier String
|
|
53
|
+
value String
|
|
54
|
+
expiresAt DateTime
|
|
55
|
+
createdAt DateTime?
|
|
56
|
+
updatedAt DateTime?
|
|
57
|
+
|
|
58
|
+
@@map("verification")
|
|
59
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { betterAuth } from "better-auth";
|
|
2
|
+
import { prismaAdapter } from "better-auth/adapters/prisma";
|
|
3
|
+
import prisma from "../../prisma";
|
|
4
|
+
|
|
5
|
+
export const auth = betterAuth({
|
|
6
|
+
database: prismaAdapter(prisma, {
|
|
7
|
+
provider: "sqlite",
|
|
8
|
+
}),
|
|
9
|
+
trustedOrigins: [process.env.CORS_ORIGIN || ""],
|
|
10
|
+
emailAndPassword: { enabled: true },
|
|
11
|
+
advanced: {
|
|
12
|
+
defaultCookieAttributes: {
|
|
13
|
+
sameSite: "none",
|
|
14
|
+
secure: true,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Context as HonoContext } from "hono";
|
|
2
|
+
import { auth } from "./auth";
|
|
3
|
+
|
|
4
|
+
export type CreateContextOptions = {
|
|
5
|
+
hono: HonoContext;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export async function createContext({ hono }: CreateContextOptions) {
|
|
9
|
+
const session = await auth.api.getSession({
|
|
10
|
+
headers: hono.req.raw.headers,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
session,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type Context = Awaited<ReturnType<typeof createContext>>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { initTRPC, TRPCError } from "@trpc/server";
|
|
2
|
+
import type { Context } from "./context";
|
|
3
|
+
|
|
4
|
+
export const t = initTRPC.context<Context>().create();
|
|
5
|
+
|
|
6
|
+
export const router = t.router;
|
|
7
|
+
|
|
8
|
+
export const publicProcedure = t.procedure;
|
|
9
|
+
|
|
10
|
+
export const protectedProcedure = t.procedure.use(({ ctx, next }) => {
|
|
11
|
+
if (!ctx.session) {
|
|
12
|
+
throw new TRPCError({
|
|
13
|
+
code: "UNAUTHORIZED",
|
|
14
|
+
message: "Authentication required",
|
|
15
|
+
cause: "No session",
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return next({
|
|
19
|
+
ctx: {
|
|
20
|
+
...ctx,
|
|
21
|
+
session: ctx.session,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
});
|
|
Binary file
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import tailwindcss from "@tailwindcss/vite";
|
|
2
|
+
import { TanStackRouterVite } from "@tanstack/router-plugin/vite";
|
|
3
|
+
import react from "@vitejs/plugin-react";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { defineConfig } from "vite";
|
|
6
|
+
import { VitePWA } from "vite-plugin-pwa";
|
|
7
|
+
|
|
8
|
+
export default defineConfig({
|
|
9
|
+
plugins: [
|
|
10
|
+
tailwindcss(),
|
|
11
|
+
TanStackRouterVite({}),
|
|
12
|
+
react(),
|
|
13
|
+
VitePWA({
|
|
14
|
+
registerType: "autoUpdate",
|
|
15
|
+
manifest: {
|
|
16
|
+
name: "My App",
|
|
17
|
+
short_name: "My App ",
|
|
18
|
+
description: "My App",
|
|
19
|
+
theme_color: "#0c0c0c",
|
|
20
|
+
},
|
|
21
|
+
pwaAssets: {
|
|
22
|
+
disabled: false,
|
|
23
|
+
config: true,
|
|
24
|
+
},
|
|
25
|
+
devOptions: {
|
|
26
|
+
enabled: true,
|
|
27
|
+
},
|
|
28
|
+
}),
|
|
29
|
+
],
|
|
30
|
+
resolve: {
|
|
31
|
+
alias: {
|
|
32
|
+
"@": path.resolve(__dirname, "./src"),
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
});
|