create-better-t-stack 1.1.0 → 1.3.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/README.md +52 -38
- package/dist/index.js +66 -60
- package/package.json +1 -1
- package/template/base/apps/native/_gitignore +24 -0
- package/template/base/apps/native/app/(drawer)/(tabs)/_layout.tsx +29 -0
- package/template/base/apps/native/app/(drawer)/(tabs)/index.tsx +9 -0
- package/template/base/apps/native/app/(drawer)/(tabs)/two.tsx +16 -0
- package/template/base/apps/native/app/(drawer)/_layout.tsx +39 -0
- package/template/base/apps/native/app/(drawer)/index.tsx +36 -0
- package/template/base/apps/native/app/+html.tsx +46 -0
- package/template/base/apps/native/app/+not-found.tsx +18 -0
- package/template/base/apps/native/app/_layout.tsx +76 -0
- package/template/base/apps/native/app/modal.tsx +15 -0
- package/template/base/apps/native/app-env.d.ts +2 -0
- package/template/base/apps/native/app.json +38 -0
- package/template/base/apps/native/assets/adaptive-icon.png +0 -0
- package/template/base/apps/native/assets/favicon.png +0 -0
- package/template/base/apps/native/assets/icon.png +0 -0
- package/template/base/apps/native/assets/splash.png +0 -0
- package/template/base/apps/native/babel.config.js +12 -0
- package/template/base/apps/native/components/container.tsx +9 -0
- package/template/base/apps/native/components/header-button.tsx +31 -0
- package/template/base/apps/native/components/tabbar-icon.tsx +15 -0
- package/template/base/apps/native/global.css +25 -0
- package/template/base/apps/native/lib/android-navigation-bar.tsx +11 -0
- package/template/base/apps/native/lib/constants.ts +18 -0
- package/template/base/apps/native/lib/use-color-scheme.ts +12 -0
- package/template/base/apps/native/metro.config.js +57 -0
- package/template/base/apps/native/package.json +47 -0
- package/template/base/apps/native/tailwind.config.js +32 -0
- package/template/base/apps/native/tsconfig.json +18 -0
- package/template/base/apps/native/utils/trpc.ts +19 -0
- package/template/base/apps/server/package.json +0 -2
- package/template/base/apps/server/tsconfig.json +1 -1
- package/template/base/apps/{client → web}/package.json +1 -1
- package/template/base/apps/web/src/main.tsx +33 -0
- package/template/base/apps/{client → web}/src/routes/__root.tsx +3 -3
- package/template/base/apps/{client → web}/src/routes/index.tsx +7 -6
- package/template/base/apps/web/src/utils/trpc.ts +33 -0
- package/template/base/package.json +2 -1
- package/template/{with-drizzle-sqlite/apps/server/src/with-auth-lib/context.ts → with-auth/apps/server/src/lib/with-elysia-context.ts} +4 -4
- package/template/{with-drizzle-postgres/apps/server/src/with-auth-lib/context.ts → with-auth/apps/server/src/lib/with-hono-context.ts} +3 -3
- package/template/with-auth/apps/server/src/with-elysia-index.ts +38 -0
- package/template/with-auth/apps/server/src/{index.ts → with-hono-index.ts} +3 -2
- package/template/with-auth/apps/{client → web}/src/routes/dashboard.tsx +2 -1
- package/template/with-auth/apps/web/src/utils/trpc.ts +39 -0
- package/template/with-elysia/apps/server/src/index.ts +27 -0
- package/template/with-elysia/apps/server/src/lib/context.ts +13 -0
- package/template/{base → with-hono}/apps/server/src/index.ts +2 -2
- package/template/{base → with-hono}/apps/server/src/lib/context.ts +2 -2
- package/template/base/apps/client/src/main.tsx +0 -72
- package/template/base/apps/client/src/utils/trpc.ts +0 -4
- package/template/with-auth/apps/client/src/main.tsx +0 -78
- package/template/with-drizzle-postgres/apps/server/src/routers/todo.ts +0 -44
- package/template/with-drizzle-postgres/apps/server/src/with-auth-lib/trpc.ts +0 -24
- package/template/with-drizzle-sqlite/apps/server/src/with-auth-lib/trpc.ts +0 -24
- package/template/with-prisma-postgres/apps/server/src/with-auth-lib/context.ts +0 -18
- package/template/with-prisma-postgres/apps/server/src/with-auth-lib/trpc.ts +0 -24
- package/template/with-prisma-sqlite/apps/server/src/with-auth-lib/context.ts +0 -18
- package/template/with-prisma-sqlite/apps/server/src/with-auth-lib/trpc.ts +0 -24
- package/template/base/apps/{client → web}/_gitignore +0 -0
- package/template/base/apps/{client → web}/components.json +0 -0
- package/template/base/apps/{client → web}/index.html +0 -0
- package/template/base/apps/{client → web}/src/components/header.tsx +0 -0
- package/template/base/apps/{client → web}/src/components/loader.tsx +0 -0
- package/template/base/apps/{client → web}/src/components/mode-toggle.tsx +0 -0
- package/template/base/apps/{client → web}/src/components/theme-provider.tsx +0 -0
- package/template/base/apps/{client → web}/src/components/ui/button.tsx +0 -0
- package/template/base/apps/{client → web}/src/components/ui/card.tsx +0 -0
- package/template/base/apps/{client → web}/src/components/ui/checkbox.tsx +0 -0
- package/template/base/apps/{client → web}/src/components/ui/dropdown-menu.tsx +0 -0
- package/template/base/apps/{client → web}/src/components/ui/input.tsx +0 -0
- package/template/base/apps/{client → web}/src/components/ui/label.tsx +0 -0
- package/template/base/apps/{client → web}/src/components/ui/skeleton.tsx +0 -0
- package/template/base/apps/{client → web}/src/components/ui/sonner.tsx +0 -0
- package/template/base/apps/{client → web}/src/index.css +0 -0
- package/template/base/apps/{client → web}/src/lib/utils.ts +0 -0
- package/template/base/apps/{client → web}/tsconfig.json +0 -0
- package/template/base/apps/{client → web}/vite.config.ts +0 -0
- package/template/examples/todo/apps/{client → web}/src/routes/todos.tsx +0 -0
- package/template/{with-drizzle-postgres/apps/server/src/with-auth-lib → with-auth/apps/server/src/with-drizzle-postgres-lib}/auth.ts +1 -1
- /package/template/{with-drizzle-sqlite/apps/server/src/with-auth-lib → with-auth/apps/server/src/with-drizzle-sqlite-lib}/auth.ts +0 -0
- /package/template/{with-prisma-postgres/apps/server/src/with-auth-lib → with-auth/apps/server/src/with-prisma-postgres-lib}/auth.ts +0 -0
- /package/template/{with-prisma-sqlite/apps/server/src/with-auth-lib → with-auth/apps/server/src/with-prisma-sqlite-lib}/auth.ts +0 -0
- /package/template/with-auth/apps/{client → web}/src/components/auth-forms.tsx +0 -0
- /package/template/with-auth/apps/{client → web}/src/components/header.tsx +0 -0
- /package/template/with-auth/apps/{client → web}/src/components/sign-in-form.tsx +0 -0
- /package/template/with-auth/apps/{client → web}/src/components/sign-up-form.tsx +0 -0
- /package/template/with-auth/apps/{client → web}/src/components/user-menu.tsx +0 -0
- /package/template/with-auth/apps/{client → web}/src/lib/auth-client.ts +0 -0
- /package/template/with-auth/apps/{client → web}/src/routes/login.tsx +0 -0
- /package/template/with-pwa/apps/{client → web}/public/logo.png +0 -0
- /package/template/with-pwa/apps/{client → web}/pwa-assets.config.ts +0 -0
- /package/template/with-pwa/apps/{client → web}/vite.config.ts +0 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { QueryClientProvider } from "@tanstack/react-query";
|
|
2
|
+
import { RouterProvider, createRouter } from "@tanstack/react-router";
|
|
3
|
+
import ReactDOM from "react-dom/client";
|
|
4
|
+
import Loader from "./components/loader";
|
|
5
|
+
import { routeTree } from "./routeTree.gen";
|
|
6
|
+
import { queryClient, trpcClient } from "./utils/trpc";
|
|
7
|
+
|
|
8
|
+
const router = createRouter({
|
|
9
|
+
routeTree,
|
|
10
|
+
defaultPreload: "intent",
|
|
11
|
+
defaultPendingComponent: () => <Loader />,
|
|
12
|
+
context: { trpcClient },
|
|
13
|
+
Wrap: function WrapComponent({ children }) {
|
|
14
|
+
return (
|
|
15
|
+
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
16
|
+
);
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// Register things for typesafety
|
|
21
|
+
declare module "@tanstack/react-router" {
|
|
22
|
+
interface Register {
|
|
23
|
+
router: typeof router;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const rootElement = document.getElementById("app");
|
|
28
|
+
if (!rootElement) throw new Error("Root element not found");
|
|
29
|
+
|
|
30
|
+
if (!rootElement.innerHTML) {
|
|
31
|
+
const root = ReactDOM.createRoot(rootElement);
|
|
32
|
+
root.render(<RouterProvider router={router} />);
|
|
33
|
+
}
|
|
@@ -2,19 +2,19 @@ import Header from "@/components/header";
|
|
|
2
2
|
import Loader from "@/components/loader";
|
|
3
3
|
import { ThemeProvider } from "@/components/theme-provider";
|
|
4
4
|
import { Toaster } from "@/components/ui/sonner";
|
|
5
|
-
import {
|
|
5
|
+
import type { trpcClient } from "@/utils/trpc";
|
|
6
6
|
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
|
|
7
7
|
import {
|
|
8
|
+
HeadContent,
|
|
8
9
|
Outlet,
|
|
9
10
|
createRootRouteWithContext,
|
|
10
11
|
useRouterState,
|
|
11
|
-
HeadContent,
|
|
12
12
|
} from "@tanstack/react-router";
|
|
13
13
|
import { TanStackRouterDevtools } from "@tanstack/react-router-devtools";
|
|
14
14
|
import "../index.css";
|
|
15
15
|
|
|
16
16
|
export interface RouterAppContext {
|
|
17
|
-
|
|
17
|
+
trpcClient: typeof trpcClient;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export const Route = createRootRouteWithContext<RouterAppContext>()({
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { Button } from "@/components/ui/button";
|
|
1
2
|
import { trpc } from "@/utils/trpc";
|
|
2
|
-
import {
|
|
3
|
+
import { useQuery } from "@tanstack/react-query";
|
|
4
|
+
import { Link, createFileRoute } from "@tanstack/react-router";
|
|
3
5
|
import { ArrowRight } from "lucide-react";
|
|
4
|
-
import { Button } from "@/components/ui/button";
|
|
5
6
|
|
|
6
7
|
export const Route = createFileRoute("/")({
|
|
7
8
|
component: HomeComponent,
|
|
@@ -24,7 +25,7 @@ const TITLE_TEXT = `
|
|
|
24
25
|
`;
|
|
25
26
|
|
|
26
27
|
function HomeComponent() {
|
|
27
|
-
const healthCheck = trpc.healthCheck.
|
|
28
|
+
const healthCheck = useQuery(trpc.healthCheck.queryOptions());
|
|
28
29
|
|
|
29
30
|
return (
|
|
30
31
|
<div className="container mx-auto max-w-3xl px-4 py-2">
|
|
@@ -33,9 +34,9 @@ function HomeComponent() {
|
|
|
33
34
|
<section className="rounded-lg border p-4">
|
|
34
35
|
<h2 className="mb-2 font-medium">API Status</h2>
|
|
35
36
|
<div className="flex items-center gap-2">
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
<div
|
|
38
|
+
className={`h-2 w-2 rounded-full ${healthCheck.data ? "bg-green-500" : "bg-red-500"}`}
|
|
39
|
+
/>
|
|
39
40
|
<span className="text-sm text-muted-foreground">
|
|
40
41
|
{healthCheck.isLoading
|
|
41
42
|
? "Checking..."
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { AppRouter } from "../../../server/src/routers";
|
|
2
|
+
import { QueryCache, QueryClient } from "@tanstack/react-query";
|
|
3
|
+
import { createTRPCClient, httpBatchLink } from "@trpc/client";
|
|
4
|
+
import { createTRPCOptionsProxy } from "@trpc/tanstack-react-query";
|
|
5
|
+
import { toast } from "sonner";
|
|
6
|
+
|
|
7
|
+
export const queryClient = new QueryClient({
|
|
8
|
+
queryCache: new QueryCache({
|
|
9
|
+
onError: (error) => {
|
|
10
|
+
toast.error(error.message, {
|
|
11
|
+
action: {
|
|
12
|
+
label: "retry",
|
|
13
|
+
onClick: () => {
|
|
14
|
+
queryClient.invalidateQueries();
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
},
|
|
19
|
+
}),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export const trpcClient = createTRPCClient<AppRouter>({
|
|
23
|
+
links: [
|
|
24
|
+
httpBatchLink({
|
|
25
|
+
url: `${import.meta.env.VITE_SERVER_URL}/trpc`,
|
|
26
|
+
}),
|
|
27
|
+
],
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export const trpc = createTRPCOptionsProxy<AppRouter>({
|
|
31
|
+
client: trpcClient,
|
|
32
|
+
queryClient,
|
|
33
|
+
});
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
"dev": "turbo dev",
|
|
7
7
|
"build": "turbo build",
|
|
8
8
|
"check-types": "turbo check-types",
|
|
9
|
-
"dev:
|
|
9
|
+
"dev:native": "turbo -F native dev",
|
|
10
|
+
"dev:web": "turbo -F web dev",
|
|
10
11
|
"dev:server": "turbo -F server dev",
|
|
11
12
|
"db:push": "turbo -F server db:push",
|
|
12
13
|
"db:studio": "turbo -F server db:studio"
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type { Context as
|
|
1
|
+
import type { Context as ElysiaContext } from "elysia";
|
|
2
2
|
import { auth } from "./auth";
|
|
3
3
|
|
|
4
4
|
export type CreateContextOptions = {
|
|
5
|
-
|
|
5
|
+
context: ElysiaContext;
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
export async function createContext({
|
|
8
|
+
export async function createContext({ context }: CreateContextOptions) {
|
|
9
9
|
const session = await auth.api.getSession({
|
|
10
|
-
headers:
|
|
10
|
+
headers: context.request.headers,
|
|
11
11
|
});
|
|
12
12
|
|
|
13
13
|
return {
|
|
@@ -2,12 +2,12 @@ import type { Context as HonoContext } from "hono";
|
|
|
2
2
|
import { auth } from "./auth";
|
|
3
3
|
|
|
4
4
|
export type CreateContextOptions = {
|
|
5
|
-
|
|
5
|
+
context: HonoContext;
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
export async function createContext({
|
|
8
|
+
export async function createContext({ context }: CreateContextOptions) {
|
|
9
9
|
const session = await auth.api.getSession({
|
|
10
|
-
headers:
|
|
10
|
+
headers: context.req.raw.headers,
|
|
11
11
|
});
|
|
12
12
|
|
|
13
13
|
return {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import { Elysia } from "elysia";
|
|
3
|
+
import { cors } from "@elysiajs/cors";
|
|
4
|
+
import { auth } from "./lib/auth";
|
|
5
|
+
import { createContext } from "./lib/context";
|
|
6
|
+
import { appRouter } from "./routers/index";
|
|
7
|
+
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
|
|
8
|
+
|
|
9
|
+
const app = new Elysia()
|
|
10
|
+
.use(
|
|
11
|
+
cors({
|
|
12
|
+
origin: process.env.CORS_ORIGIN || "",
|
|
13
|
+
methods: ["GET", "POST", "OPTIONS"],
|
|
14
|
+
allowedHeaders: ["Content-Type", "Authorization"],
|
|
15
|
+
credentials: true,
|
|
16
|
+
}),
|
|
17
|
+
)
|
|
18
|
+
.all("/api/auth/*", async (context) => {
|
|
19
|
+
const { request } = context;
|
|
20
|
+
if (["POST", "GET"].includes(request.method)) {
|
|
21
|
+
return auth.handler(request);
|
|
22
|
+
} else {
|
|
23
|
+
context.error(405);
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
.all("/trpc/*", async (context) => {
|
|
27
|
+
const res = await fetchRequestHandler({
|
|
28
|
+
endpoint: "/trpc",
|
|
29
|
+
router: appRouter,
|
|
30
|
+
req: context.request,
|
|
31
|
+
createContext: () => createContext({ context }),
|
|
32
|
+
});
|
|
33
|
+
return res;
|
|
34
|
+
})
|
|
35
|
+
.get("/", () => "OK")
|
|
36
|
+
.listen(3000, () => {
|
|
37
|
+
console.log(`Server is running on http://localhost:3000`);
|
|
38
|
+
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
import { trpcServer } from "@hono/trpc-server";
|
|
2
3
|
import "dotenv/config";
|
|
3
4
|
import { Hono } from "hono";
|
|
@@ -27,8 +28,8 @@ app.use(
|
|
|
27
28
|
"/trpc/*",
|
|
28
29
|
trpcServer({
|
|
29
30
|
router: appRouter,
|
|
30
|
-
createContext: (_opts,
|
|
31
|
-
return createContext({
|
|
31
|
+
createContext: (_opts, context) => {
|
|
32
|
+
return createContext({ context });
|
|
32
33
|
},
|
|
33
34
|
}),
|
|
34
35
|
);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { authClient } from "@/lib/auth-client";
|
|
2
2
|
import { trpc } from "@/utils/trpc";
|
|
3
|
+
import { useQuery } from "@tanstack/react-query";
|
|
3
4
|
import { createFileRoute } from "@tanstack/react-router";
|
|
4
5
|
import { useEffect } from "react";
|
|
5
6
|
|
|
@@ -12,7 +13,7 @@ function RouteComponent() {
|
|
|
12
13
|
|
|
13
14
|
const navigate = Route.useNavigate();
|
|
14
15
|
|
|
15
|
-
const privateData = trpc.privateData.
|
|
16
|
+
const privateData = useQuery(trpc.privateData.queryOptions());
|
|
16
17
|
|
|
17
18
|
useEffect(() => {
|
|
18
19
|
if (!session && !isPending) {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { AppRouter } from "../../../server/src/routers";
|
|
2
|
+
import { QueryCache, QueryClient } from "@tanstack/react-query";
|
|
3
|
+
import { createTRPCClient, httpBatchLink } from "@trpc/client";
|
|
4
|
+
import { createTRPCOptionsProxy } from "@trpc/tanstack-react-query";
|
|
5
|
+
import { toast } from "sonner";
|
|
6
|
+
|
|
7
|
+
export const queryClient = new QueryClient({
|
|
8
|
+
queryCache: new QueryCache({
|
|
9
|
+
onError: (error) => {
|
|
10
|
+
toast.error(error.message, {
|
|
11
|
+
action: {
|
|
12
|
+
label: "retry",
|
|
13
|
+
onClick: () => {
|
|
14
|
+
queryClient.invalidateQueries();
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
},
|
|
19
|
+
}),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export const trpcClient = createTRPCClient<AppRouter>({
|
|
23
|
+
links: [
|
|
24
|
+
httpBatchLink({
|
|
25
|
+
url: `${import.meta.env.VITE_SERVER_URL}/trpc`,
|
|
26
|
+
fetch(url, options) {
|
|
27
|
+
return fetch(url, {
|
|
28
|
+
...options,
|
|
29
|
+
credentials: "include",
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
}),
|
|
33
|
+
],
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export const trpc = createTRPCOptionsProxy<AppRouter>({
|
|
37
|
+
client: trpcClient,
|
|
38
|
+
queryClient,
|
|
39
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import { Elysia } from "elysia";
|
|
3
|
+
import { cors } from "@elysiajs/cors";
|
|
4
|
+
import { createContext } from "./lib/context";
|
|
5
|
+
import { appRouter } from "./routers/index";
|
|
6
|
+
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
|
|
7
|
+
|
|
8
|
+
const app = new Elysia()
|
|
9
|
+
.use(
|
|
10
|
+
cors({
|
|
11
|
+
origin: process.env.CORS_ORIGIN || "",
|
|
12
|
+
methods: ["GET", "POST", "OPTIONS"],
|
|
13
|
+
}),
|
|
14
|
+
)
|
|
15
|
+
.all("/trpc/*", async (context) => {
|
|
16
|
+
const res = await fetchRequestHandler({
|
|
17
|
+
endpoint: "/trpc",
|
|
18
|
+
router: appRouter,
|
|
19
|
+
req: context.request,
|
|
20
|
+
createContext: () => createContext({ context }),
|
|
21
|
+
});
|
|
22
|
+
return res;
|
|
23
|
+
})
|
|
24
|
+
.get("/", () => "OK")
|
|
25
|
+
.listen(3000, () => {
|
|
26
|
+
console.log(`Server is running on http://localhost:3000`);
|
|
27
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Context as ElysiaContext } from "elysia";
|
|
2
|
+
|
|
3
|
+
export type CreateContextOptions = {
|
|
4
|
+
context: ElysiaContext;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export async function createContext({ context }: CreateContextOptions) {
|
|
8
|
+
return {
|
|
9
|
+
session: null,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type Context = Awaited<ReturnType<typeof createContext>>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Context as HonoContext } from "hono";
|
|
2
2
|
|
|
3
3
|
export type CreateContextOptions = {
|
|
4
|
-
|
|
4
|
+
context: HonoContext;
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
-
export async function createContext({
|
|
7
|
+
export async function createContext({ context }: CreateContextOptions) {
|
|
8
8
|
return {
|
|
9
9
|
session: null,
|
|
10
10
|
};
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
QueryCache,
|
|
3
|
-
QueryClient,
|
|
4
|
-
QueryClientProvider,
|
|
5
|
-
} from "@tanstack/react-query";
|
|
6
|
-
import { RouterProvider, createRouter } from "@tanstack/react-router";
|
|
7
|
-
import { httpBatchLink } from "@trpc/client";
|
|
8
|
-
import { createTRPCQueryUtils } from "@trpc/react-query";
|
|
9
|
-
import ReactDOM from "react-dom/client";
|
|
10
|
-
import { toast } from "sonner";
|
|
11
|
-
import Loader from "./components/loader";
|
|
12
|
-
import { routeTree } from "./routeTree.gen";
|
|
13
|
-
import { trpc } from "./utils/trpc";
|
|
14
|
-
|
|
15
|
-
const queryClient = new QueryClient({
|
|
16
|
-
queryCache: new QueryCache({
|
|
17
|
-
onError: (error) => {
|
|
18
|
-
toast.error(error.message, {
|
|
19
|
-
action: {
|
|
20
|
-
label: "retry",
|
|
21
|
-
onClick: () => {
|
|
22
|
-
queryClient.invalidateQueries();
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
},
|
|
27
|
-
}),
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const trpcClient = trpc.createClient({
|
|
31
|
-
links: [
|
|
32
|
-
httpBatchLink({
|
|
33
|
-
url: `${import.meta.env.VITE_SERVER_URL}/trpc`,
|
|
34
|
-
}),
|
|
35
|
-
],
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
export const trpcQueryUtils = createTRPCQueryUtils({
|
|
39
|
-
queryClient,
|
|
40
|
-
client: trpcClient,
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
const router = createRouter({
|
|
44
|
-
routeTree,
|
|
45
|
-
defaultPreload: "intent",
|
|
46
|
-
context: { trpcQueryUtils },
|
|
47
|
-
defaultPendingComponent: () => <Loader />,
|
|
48
|
-
Wrap: function WrapComponent({ children }) {
|
|
49
|
-
return (
|
|
50
|
-
<trpc.Provider client={trpcClient} queryClient={queryClient}>
|
|
51
|
-
<QueryClientProvider client={queryClient}>
|
|
52
|
-
{children}
|
|
53
|
-
</QueryClientProvider>
|
|
54
|
-
</trpc.Provider>
|
|
55
|
-
);
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
// Register things for typesafety
|
|
60
|
-
declare module "@tanstack/react-router" {
|
|
61
|
-
interface Register {
|
|
62
|
-
router: typeof router;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const rootElement = document.getElementById("app");
|
|
67
|
-
if (!rootElement) throw new Error("Root element not found");
|
|
68
|
-
|
|
69
|
-
if (!rootElement.innerHTML) {
|
|
70
|
-
const root = ReactDOM.createRoot(rootElement);
|
|
71
|
-
root.render(<RouterProvider router={router} />);
|
|
72
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
QueryCache,
|
|
3
|
-
QueryClient,
|
|
4
|
-
QueryClientProvider,
|
|
5
|
-
} from "@tanstack/react-query";
|
|
6
|
-
import { RouterProvider, createRouter } from "@tanstack/react-router";
|
|
7
|
-
import { httpBatchLink } from "@trpc/client";
|
|
8
|
-
import { createTRPCQueryUtils } from "@trpc/react-query";
|
|
9
|
-
import ReactDOM from "react-dom/client";
|
|
10
|
-
import { toast } from "sonner";
|
|
11
|
-
import Loader from "./components/loader";
|
|
12
|
-
import { routeTree } from "./routeTree.gen";
|
|
13
|
-
import { trpc } from "./utils/trpc";
|
|
14
|
-
|
|
15
|
-
const queryClient = new QueryClient({
|
|
16
|
-
queryCache: new QueryCache({
|
|
17
|
-
onError: (error) => {
|
|
18
|
-
toast.error(error.message, {
|
|
19
|
-
action: {
|
|
20
|
-
label: "retry",
|
|
21
|
-
onClick: () => {
|
|
22
|
-
queryClient.invalidateQueries();
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
},
|
|
27
|
-
}),
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const trpcClient = trpc.createClient({
|
|
31
|
-
links: [
|
|
32
|
-
httpBatchLink({
|
|
33
|
-
url: `${import.meta.env.VITE_SERVER_URL}/trpc`,
|
|
34
|
-
fetch(url, options) {
|
|
35
|
-
return fetch(url, {
|
|
36
|
-
...options,
|
|
37
|
-
credentials: "include",
|
|
38
|
-
});
|
|
39
|
-
},
|
|
40
|
-
}),
|
|
41
|
-
],
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
export const trpcQueryUtils = createTRPCQueryUtils({
|
|
45
|
-
queryClient,
|
|
46
|
-
client: trpcClient,
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
const router = createRouter({
|
|
50
|
-
routeTree,
|
|
51
|
-
defaultPreload: "intent",
|
|
52
|
-
context: { trpcQueryUtils },
|
|
53
|
-
defaultPendingComponent: () => <Loader />,
|
|
54
|
-
Wrap: function WrapComponent({ children }) {
|
|
55
|
-
return (
|
|
56
|
-
<trpc.Provider client={trpcClient} queryClient={queryClient}>
|
|
57
|
-
<QueryClientProvider client={queryClient}>
|
|
58
|
-
{children}
|
|
59
|
-
</QueryClientProvider>
|
|
60
|
-
</trpc.Provider>
|
|
61
|
-
);
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
// Register things for typesafety
|
|
66
|
-
declare module "@tanstack/react-router" {
|
|
67
|
-
interface Register {
|
|
68
|
-
router: typeof router;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const rootElement = document.getElementById("app");
|
|
73
|
-
if (!rootElement) throw new Error("Root element not found");
|
|
74
|
-
|
|
75
|
-
if (!rootElement.innerHTML) {
|
|
76
|
-
const root = ReactDOM.createRoot(rootElement);
|
|
77
|
-
root.render(<RouterProvider router={router} />);
|
|
78
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { router, publicProcedure } from "../lib/trpc";
|
|
3
|
-
import { todo } from "../db/schema";
|
|
4
|
-
import { eq } from "drizzle-orm";
|
|
5
|
-
import { db } from "../db";
|
|
6
|
-
|
|
7
|
-
export const todoRouter = router({
|
|
8
|
-
getAll: publicProcedure.query(async () => {
|
|
9
|
-
return await db.select().from(todo).all();
|
|
10
|
-
}),
|
|
11
|
-
|
|
12
|
-
create: publicProcedure
|
|
13
|
-
.input(z.object({ text: z.string().min(1) }))
|
|
14
|
-
.mutation(async ({ input }) => {
|
|
15
|
-
return await db
|
|
16
|
-
.insert(todo)
|
|
17
|
-
.values({
|
|
18
|
-
text: input.text,
|
|
19
|
-
})
|
|
20
|
-
.returning()
|
|
21
|
-
.get();
|
|
22
|
-
}),
|
|
23
|
-
|
|
24
|
-
toggle: publicProcedure
|
|
25
|
-
.input(z.object({ id: z.number(), completed: z.boolean() }))
|
|
26
|
-
.mutation(async ({ input }) => {
|
|
27
|
-
return await db
|
|
28
|
-
.update(todo)
|
|
29
|
-
.set({ completed: input.completed })
|
|
30
|
-
.where(eq(todo.id, input.id))
|
|
31
|
-
.returning()
|
|
32
|
-
.get();
|
|
33
|
-
}),
|
|
34
|
-
|
|
35
|
-
delete: publicProcedure
|
|
36
|
-
.input(z.object({ id: z.number() }))
|
|
37
|
-
.mutation(async ({ input }) => {
|
|
38
|
-
return await db
|
|
39
|
-
.delete(todo)
|
|
40
|
-
.where(eq(todo.id, input.id))
|
|
41
|
-
.returning()
|
|
42
|
-
.get();
|
|
43
|
-
}),
|
|
44
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
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>>;
|
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
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>>;
|