@proofkit/cli 1.0.0-beta.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/CHANGELOG.md +120 -0
- package/LICENSE.md +21 -0
- package/README.md +19 -0
- package/dist/acorn-AKFTBDM6.js +15 -0
- package/dist/angular-BOQ6FHSU.js +2 -0
- package/dist/babel-ZTOORN7K.js +15 -0
- package/dist/chunk-4LISTI44.js +1 -0
- package/dist/estree-KOJPX4S6.js +36 -0
- package/dist/flow-RCI44GYZ.js +19 -0
- package/dist/glimmer-GV5EF5E4.js +30 -0
- package/dist/graphql-YXQNPQWM.js +29 -0
- package/dist/html-ZAJTRROK.js +22 -0
- package/dist/index.js +300 -0
- package/dist/markdown-Q75DTQI7.js +63 -0
- package/dist/meriyah-32K7GBV5.js +4 -0
- package/dist/postcss-WWYO4PGL.js +54 -0
- package/dist/typescript-M6N7JDNQ.js +20 -0
- package/dist/yaml-LY7PNAYV.js +161 -0
- package/index.d.ts +19 -0
- package/package.json +122 -0
- package/template/extras/_cursor/conditional-rules/nextjs-framework.mdc +51 -0
- package/template/extras/_cursor/conditional-rules/npm.mdc +60 -0
- package/template/extras/_cursor/conditional-rules/pnpm.mdc +65 -0
- package/template/extras/_cursor/conditional-rules/yarn.mdc +60 -0
- package/template/extras/_cursor/rules/cursor-rules.mdc +88 -0
- package/template/extras/_cursor/rules/filemaker-api.mdc +176 -0
- package/template/extras/_cursor/rules/troubleshooting-patterns.mdc +240 -0
- package/template/extras/_cursor/rules/ui-components.mdc +57 -0
- package/template/extras/config/_eslint.js +27 -0
- package/template/extras/config/_prettier.config.js +6 -0
- package/template/extras/config/drizzle-config-mysql.ts +12 -0
- package/template/extras/config/drizzle-config-postgres.ts +12 -0
- package/template/extras/config/drizzle-config-sqlite.ts +12 -0
- package/template/extras/config/fmschema.config.mjs +9 -0
- package/template/extras/config/get-query-client.ts +6 -0
- package/template/extras/config/postcss.config.cjs +7 -0
- package/template/extras/config/query-provider-vite.tsx +19 -0
- package/template/extras/config/query-provider.tsx +21 -0
- package/template/extras/emailProviders/none/email.tsx +24 -0
- package/template/extras/emailProviders/plunk/email.tsx +26 -0
- package/template/extras/emailProviders/plunk/service.ts +4 -0
- package/template/extras/emailProviders/resend/email.tsx +23 -0
- package/template/extras/emailProviders/resend/service.ts +4 -0
- package/template/extras/fmaddon-auth/app/(main)/auth/profile/actions.ts +93 -0
- package/template/extras/fmaddon-auth/app/(main)/auth/profile/page.tsx +27 -0
- package/template/extras/fmaddon-auth/app/(main)/auth/profile/profile-form.tsx +56 -0
- package/template/extras/fmaddon-auth/app/(main)/auth/profile/reset-password-form.tsx +110 -0
- package/template/extras/fmaddon-auth/app/(main)/auth/profile/schema.ts +19 -0
- package/template/extras/fmaddon-auth/app/auth/forgot-password/actions.ts +37 -0
- package/template/extras/fmaddon-auth/app/auth/forgot-password/forgot-form.tsx +41 -0
- package/template/extras/fmaddon-auth/app/auth/forgot-password/page.tsx +21 -0
- package/template/extras/fmaddon-auth/app/auth/forgot-password/schema.ts +5 -0
- package/template/extras/fmaddon-auth/app/auth/login/actions.ts +34 -0
- package/template/extras/fmaddon-auth/app/auth/login/login-form.tsx +64 -0
- package/template/extras/fmaddon-auth/app/auth/login/page.tsx +26 -0
- package/template/extras/fmaddon-auth/app/auth/login/schema.ts +6 -0
- package/template/extras/fmaddon-auth/app/auth/reset-password/actions.ts +50 -0
- package/template/extras/fmaddon-auth/app/auth/reset-password/page.tsx +32 -0
- package/template/extras/fmaddon-auth/app/auth/reset-password/reset-password-form.tsx +59 -0
- package/template/extras/fmaddon-auth/app/auth/reset-password/schema.ts +14 -0
- package/template/extras/fmaddon-auth/app/auth/reset-password/verify-email/actions.ts +45 -0
- package/template/extras/fmaddon-auth/app/auth/reset-password/verify-email/page.tsx +32 -0
- package/template/extras/fmaddon-auth/app/auth/reset-password/verify-email/schema.ts +5 -0
- package/template/extras/fmaddon-auth/app/auth/reset-password/verify-email/verify-email-form.tsx +48 -0
- package/template/extras/fmaddon-auth/app/auth/signup/actions.ts +49 -0
- package/template/extras/fmaddon-auth/app/auth/signup/page.tsx +26 -0
- package/template/extras/fmaddon-auth/app/auth/signup/schema.ts +12 -0
- package/template/extras/fmaddon-auth/app/auth/signup/signup-form.tsx +67 -0
- package/template/extras/fmaddon-auth/app/auth/verify-email/actions.ts +110 -0
- package/template/extras/fmaddon-auth/app/auth/verify-email/email-verification-form.tsx +45 -0
- package/template/extras/fmaddon-auth/app/auth/verify-email/page.tsx +38 -0
- package/template/extras/fmaddon-auth/app/auth/verify-email/resend-button.tsx +35 -0
- package/template/extras/fmaddon-auth/app/auth/verify-email/schema.ts +5 -0
- package/template/extras/fmaddon-auth/components/auth/actions.ts +16 -0
- package/template/extras/fmaddon-auth/components/auth/protect.tsx +17 -0
- package/template/extras/fmaddon-auth/components/auth/redirect.tsx +26 -0
- package/template/extras/fmaddon-auth/components/auth/use-user.ts +59 -0
- package/template/extras/fmaddon-auth/components/auth/user-menu.tsx +51 -0
- package/template/extras/fmaddon-auth/emails/auth-code.tsx +156 -0
- package/template/extras/fmaddon-auth/middleware.ts +45 -0
- package/template/extras/fmaddon-auth/server/auth/utils/email-verification.ts +136 -0
- package/template/extras/fmaddon-auth/server/auth/utils/encryption.ts +51 -0
- package/template/extras/fmaddon-auth/server/auth/utils/index.ts +16 -0
- package/template/extras/fmaddon-auth/server/auth/utils/password-reset.ts +152 -0
- package/template/extras/fmaddon-auth/server/auth/utils/password.ts +67 -0
- package/template/extras/fmaddon-auth/server/auth/utils/redirect.ts +8 -0
- package/template/extras/fmaddon-auth/server/auth/utils/session.ts +192 -0
- package/template/extras/fmaddon-auth/server/auth/utils/user.ts +147 -0
- package/template/extras/prisma/schema/base-planetscale.prisma +24 -0
- package/template/extras/prisma/schema/base.prisma +20 -0
- package/template/extras/prisma/schema/with-auth-planetscale.prisma +77 -0
- package/template/extras/prisma/schema/with-auth.prisma +74 -0
- package/template/extras/src/app/_components/post-tw.tsx +50 -0
- package/template/extras/src/app/_components/post.tsx +54 -0
- package/template/extras/src/app/api/auth/[...nextauth]/route.ts +4 -0
- package/template/extras/src/app/api/trpc/[trpc]/route.ts +34 -0
- package/template/extras/src/app/clerk-auth/layout.tsx +10 -0
- package/template/extras/src/app/clerk-auth/signin/[[...sign-in]]/page.tsx +5 -0
- package/template/extras/src/app/clerk-auth/signup/[[...sign-up]]/page.tsx +5 -0
- package/template/extras/src/app/layout/base.tsx +34 -0
- package/template/extras/src/app/layout/main-shell.tsx +37 -0
- package/template/extras/src/app/layout/with-trpc-tw.tsx +24 -0
- package/template/extras/src/app/layout/with-trpc.tsx +24 -0
- package/template/extras/src/app/layout/with-tw.tsx +20 -0
- package/template/extras/src/app/next-auth/layout.tsx +22 -0
- package/template/extras/src/app/next-auth/signin/page.tsx +82 -0
- package/template/extras/src/app/next-auth/signup/action.ts +24 -0
- package/template/extras/src/app/next-auth/signup/page.tsx +40 -0
- package/template/extras/src/app/next-auth/signup/validation.ts +12 -0
- package/template/extras/src/app/page/base.tsx +6 -0
- package/template/extras/src/app/page/with-auth-trpc-tw.tsx +67 -0
- package/template/extras/src/app/page/with-auth-trpc.tsx +68 -0
- package/template/extras/src/app/page/with-trpc-tw.tsx +53 -0
- package/template/extras/src/app/page/with-trpc.tsx +54 -0
- package/template/extras/src/app/page/with-tw.tsx +37 -0
- package/template/extras/src/components/clerk-auth/clerk-provider.tsx +18 -0
- package/template/extras/src/components/clerk-auth/user-menu-mobile.tsx +36 -0
- package/template/extras/src/components/clerk-auth/user-menu.tsx +24 -0
- package/template/extras/src/components/next-auth/next-auth-provider.tsx +14 -0
- package/template/extras/src/components/next-auth/user-menu-mobile.tsx +31 -0
- package/template/extras/src/components/next-auth/user-menu.tsx +38 -0
- package/template/extras/src/env/with-auth.ts +31 -0
- package/template/extras/src/env/with-clerk.ts +20 -0
- package/template/extras/src/index.module.css +177 -0
- package/template/extras/src/middleware/clerk.ts +20 -0
- package/template/extras/src/middleware/next-auth.ts +5 -0
- package/template/extras/src/pages/_app/base.tsx +14 -0
- package/template/extras/src/pages/_app/with-auth-trpc-tw.tsx +23 -0
- package/template/extras/src/pages/_app/with-auth-trpc.tsx +23 -0
- package/template/extras/src/pages/_app/with-auth-tw.tsx +21 -0
- package/template/extras/src/pages/_app/with-auth.tsx +21 -0
- package/template/extras/src/pages/_app/with-trpc-tw.tsx +16 -0
- package/template/extras/src/pages/_app/with-trpc.tsx +16 -0
- package/template/extras/src/pages/_app/with-tw.tsx +14 -0
- package/template/extras/src/pages/api/auth/[...nextauth].ts +5 -0
- package/template/extras/src/pages/api/trpc/[trpc].ts +19 -0
- package/template/extras/src/pages/index/base.tsx +47 -0
- package/template/extras/src/pages/index/with-auth-trpc-tw.tsx +80 -0
- package/template/extras/src/pages/index/with-auth-trpc.tsx +81 -0
- package/template/extras/src/pages/index/with-trpc-tw.tsx +52 -0
- package/template/extras/src/pages/index/with-trpc.tsx +53 -0
- package/template/extras/src/pages/index/with-tw.tsx +45 -0
- package/template/extras/src/server/api/root.ts +23 -0
- package/template/extras/src/server/api/routers/post/base.ts +40 -0
- package/template/extras/src/server/api/routers/post/with-auth-drizzle.ts +39 -0
- package/template/extras/src/server/api/routers/post/with-auth-prisma.ts +41 -0
- package/template/extras/src/server/api/routers/post/with-auth.ts +37 -0
- package/template/extras/src/server/api/routers/post/with-drizzle.ts +30 -0
- package/template/extras/src/server/api/routers/post/with-prisma.ts +31 -0
- package/template/extras/src/server/api/trpc-app/base.ts +103 -0
- package/template/extras/src/server/api/trpc-app/with-auth-db.ts +133 -0
- package/template/extras/src/server/api/trpc-app/with-auth.ts +130 -0
- package/template/extras/src/server/api/trpc-app/with-db.ts +106 -0
- package/template/extras/src/server/api/trpc-pages/base.ts +122 -0
- package/template/extras/src/server/api/trpc-pages/with-auth-db.ts +160 -0
- package/template/extras/src/server/api/trpc-pages/with-auth.ts +158 -0
- package/template/extras/src/server/api/trpc-pages/with-db.ts +125 -0
- package/template/extras/src/server/data/users.ts +23 -0
- package/template/extras/src/server/db/db-prisma-planetscale.ts +22 -0
- package/template/extras/src/server/db/db-prisma.ts +17 -0
- package/template/extras/src/server/db/index-drizzle/with-mysql.ts +18 -0
- package/template/extras/src/server/db/index-drizzle/with-planetscale.ts +7 -0
- package/template/extras/src/server/db/index-drizzle/with-postgres.ts +18 -0
- package/template/extras/src/server/db/index-drizzle/with-sqlite.ts +19 -0
- package/template/extras/src/server/db/schema-drizzle/base-mysql.ts +34 -0
- package/template/extras/src/server/db/schema-drizzle/base-planetscale.ts +34 -0
- package/template/extras/src/server/db/schema-drizzle/base-postgres.ts +36 -0
- package/template/extras/src/server/db/schema-drizzle/base-sqlite.ts +30 -0
- package/template/extras/src/server/db/schema-drizzle/with-auth-mysql.ts +123 -0
- package/template/extras/src/server/db/schema-drizzle/with-auth-planetscale.ts +117 -0
- package/template/extras/src/server/db/schema-drizzle/with-auth-postgres.ts +130 -0
- package/template/extras/src/server/db/schema-drizzle/with-auth-sqlite.ts +116 -0
- package/template/extras/src/server/next-auth/base.ts +111 -0
- package/template/extras/src/server/next-auth/password.ts +13 -0
- package/template/extras/src/server/next-auth/with-drizzle.ts +83 -0
- package/template/extras/src/server/next-auth/with-prisma.ts +72 -0
- package/template/extras/src/trpc/query-client.ts +25 -0
- package/template/extras/src/trpc/react.tsx +76 -0
- package/template/extras/src/trpc/server.ts +30 -0
- package/template/extras/src/utils/api.ts +68 -0
- package/template/extras/start-database/mysql.sh +54 -0
- package/template/extras/start-database/postgres.sh +55 -0
- package/template/fm-addon/ProofKitAuth/de.xml +518 -0
- package/template/fm-addon/ProofKitAuth/en.xml +518 -0
- package/template/fm-addon/ProofKitAuth/es.xml +518 -0
- package/template/fm-addon/ProofKitAuth/fr.xml +518 -0
- package/template/fm-addon/ProofKitAuth/icon.png +0 -0
- package/template/fm-addon/ProofKitAuth/icon@2x.png +0 -0
- package/template/fm-addon/ProofKitAuth/info.json +11 -0
- package/template/fm-addon/ProofKitAuth/info_de.json +18 -0
- package/template/fm-addon/ProofKitAuth/info_en.json +8 -0
- package/template/fm-addon/ProofKitAuth/info_es.json +18 -0
- package/template/fm-addon/ProofKitAuth/info_fr.json +18 -0
- package/template/fm-addon/ProofKitAuth/info_it.json +18 -0
- package/template/fm-addon/ProofKitAuth/info_ja.json +18 -0
- package/template/fm-addon/ProofKitAuth/info_ko.json +18 -0
- package/template/fm-addon/ProofKitAuth/info_nl.json +18 -0
- package/template/fm-addon/ProofKitAuth/info_pt.json +18 -0
- package/template/fm-addon/ProofKitAuth/info_sv.json +18 -0
- package/template/fm-addon/ProofKitAuth/info_zh.json +18 -0
- package/template/fm-addon/ProofKitAuth/it.xml +518 -0
- package/template/fm-addon/ProofKitAuth/ja.xml +518 -0
- package/template/fm-addon/ProofKitAuth/ko.xml +518 -0
- package/template/fm-addon/ProofKitAuth/nl.xml +518 -0
- package/template/fm-addon/ProofKitAuth/preview.png +0 -0
- package/template/fm-addon/ProofKitAuth/pt.xml +518 -0
- package/template/fm-addon/ProofKitAuth/sv.xml +518 -0
- package/template/fm-addon/ProofKitAuth/template.xml +0 -0
- package/template/fm-addon/ProofKitAuth/zh.xml +518 -0
- package/template/fm-addon/ProofKitWV/de.xml +896 -0
- package/template/fm-addon/ProofKitWV/en.xml +896 -0
- package/template/fm-addon/ProofKitWV/es.xml +896 -0
- package/template/fm-addon/ProofKitWV/fr.xml +896 -0
- package/template/fm-addon/ProofKitWV/icon.png +0 -0
- package/template/fm-addon/ProofKitWV/icon@2x.png +0 -0
- package/template/fm-addon/ProofKitWV/info.json +11 -0
- package/template/fm-addon/ProofKitWV/info_de.json +18 -0
- package/template/fm-addon/ProofKitWV/info_en.json +11 -0
- package/template/fm-addon/ProofKitWV/info_es.json +18 -0
- package/template/fm-addon/ProofKitWV/info_fr.json +18 -0
- package/template/fm-addon/ProofKitWV/info_it.json +18 -0
- package/template/fm-addon/ProofKitWV/info_ja.json +18 -0
- package/template/fm-addon/ProofKitWV/info_ko.json +18 -0
- package/template/fm-addon/ProofKitWV/info_nl.json +18 -0
- package/template/fm-addon/ProofKitWV/info_pt.json +18 -0
- package/template/fm-addon/ProofKitWV/info_sv.json +18 -0
- package/template/fm-addon/ProofKitWV/info_zh.json +18 -0
- package/template/fm-addon/ProofKitWV/it.xml +896 -0
- package/template/fm-addon/ProofKitWV/ja.xml +896 -0
- package/template/fm-addon/ProofKitWV/ko.xml +896 -0
- package/template/fm-addon/ProofKitWV/nl.xml +896 -0
- package/template/fm-addon/ProofKitWV/preview.png +0 -0
- package/template/fm-addon/ProofKitWV/pt.xml +896 -0
- package/template/fm-addon/ProofKitWV/records_de.xml +0 -0
- package/template/fm-addon/ProofKitWV/records_en.xml +0 -0
- package/template/fm-addon/ProofKitWV/records_es.xml +0 -0
- package/template/fm-addon/ProofKitWV/records_fr.xml +0 -0
- package/template/fm-addon/ProofKitWV/records_it.xml +0 -0
- package/template/fm-addon/ProofKitWV/records_ja.xml +0 -0
- package/template/fm-addon/ProofKitWV/records_ko.xml +0 -0
- package/template/fm-addon/ProofKitWV/records_nl.xml +0 -0
- package/template/fm-addon/ProofKitWV/records_pt.xml +0 -0
- package/template/fm-addon/ProofKitWV/records_sv.xml +0 -0
- package/template/fm-addon/ProofKitWV/records_zh.xml +0 -0
- package/template/fm-addon/ProofKitWV/sv.xml +896 -0
- package/template/fm-addon/ProofKitWV/template.xml +0 -0
- package/template/fm-addon/ProofKitWV/zh.xml +896 -0
- package/template/nextjs/README.md +27 -0
- package/template/nextjs/_gitignore +37 -0
- package/template/nextjs/next.config.ts +12 -0
- package/template/nextjs/package.json +50 -0
- package/template/nextjs/postcss.config.cjs +14 -0
- package/template/nextjs/proofkit.json +1 -0
- package/template/nextjs/public/favicon.ico +0 -0
- package/template/nextjs/public/proofkit.png +0 -0
- package/template/nextjs/src/app/(main)/layout.tsx +6 -0
- package/template/nextjs/src/app/(main)/page.tsx +90 -0
- package/template/nextjs/src/app/layout.tsx +39 -0
- package/template/nextjs/src/app/navigation.tsx +12 -0
- package/template/nextjs/src/components/AppLogo.tsx +6 -0
- package/template/nextjs/src/components/AppShell/internal/AppShell.tsx +21 -0
- package/template/nextjs/src/components/AppShell/internal/Header.module.css +40 -0
- package/template/nextjs/src/components/AppShell/internal/Header.tsx +34 -0
- package/template/nextjs/src/components/AppShell/internal/HeaderMobileMenu.tsx +27 -0
- package/template/nextjs/src/components/AppShell/internal/HeaderNavLink.tsx +31 -0
- package/template/nextjs/src/components/AppShell/internal/config.ts +1 -0
- package/template/nextjs/src/components/AppShell/slot-header-center.tsx +13 -0
- package/template/nextjs/src/components/AppShell/slot-header-left.tsx +23 -0
- package/template/nextjs/src/components/AppShell/slot-header-mobile-content.tsx +43 -0
- package/template/nextjs/src/components/AppShell/slot-header-right.tsx +26 -0
- package/template/nextjs/src/config/env.ts +13 -0
- package/template/nextjs/src/config/theme/globals.css +1 -0
- package/template/nextjs/src/config/theme/mantine-theme.ts +22 -0
- package/template/nextjs/src/server/safe-action.ts +3 -0
- package/template/nextjs/src/utils/notification-helpers.ts +32 -0
- package/template/nextjs/tsconfig.json +40 -0
- package/template/pages/nextjs/blank/page.tsx +5 -0
- package/template/pages/nextjs/table/page.tsx +17 -0
- package/template/pages/nextjs/table/table.tsx +18 -0
- package/template/pages/nextjs/table-edit/actions.ts +23 -0
- package/template/pages/nextjs/table-edit/page.tsx +28 -0
- package/template/pages/nextjs/table-edit/schema.ts +4 -0
- package/template/pages/nextjs/table-edit/table.tsx +43 -0
- package/template/pages/nextjs/table-infinite/actions.ts +62 -0
- package/template/pages/nextjs/table-infinite/page.tsx +11 -0
- package/template/pages/nextjs/table-infinite/query.ts +44 -0
- package/template/pages/nextjs/table-infinite/table.tsx +107 -0
- package/template/pages/nextjs/table-infinite-edit/actions.ts +84 -0
- package/template/pages/nextjs/table-infinite-edit/page.tsx +23 -0
- package/template/pages/nextjs/table-infinite-edit/query.ts +81 -0
- package/template/pages/nextjs/table-infinite-edit/schema.ts +4 -0
- package/template/pages/nextjs/table-infinite-edit/table.tsx +130 -0
- package/template/pages/vite-wv/blank/index.tsx +0 -0
- package/template/pages/vite-wv/table/index.tsx +34 -0
- package/template/pages/vite-wv/table-edit/index.tsx +72 -0
- package/template/vite-wv/.vscode/settings.json +11 -0
- package/template/vite-wv/_gitignore +18 -0
- package/template/vite-wv/index.html +13 -0
- package/template/vite-wv/package.json +52 -0
- package/template/vite-wv/pnpm-lock.yaml +2294 -0
- package/template/vite-wv/postcss.config.cjs +14 -0
- package/template/vite-wv/proofkit.json +1 -0
- package/template/vite-wv/scripts/launch-fm.sh +3 -0
- package/template/vite-wv/scripts/upload.js +21 -0
- package/template/vite-wv/src/components/AppLogo.tsx +5 -0
- package/template/vite-wv/src/components/full-screen-loader.tsx +9 -0
- package/template/vite-wv/src/config/env.ts +16 -0
- package/template/vite-wv/src/config/theme/globals.css +1 -0
- package/template/vite-wv/src/config/theme/mantine-theme.ts +22 -0
- package/template/vite-wv/src/main.tsx +42 -0
- package/template/vite-wv/src/routeTree.gen.ts +111 -0
- package/template/vite-wv/src/routes/__root.tsx +21 -0
- package/template/vite-wv/src/routes/index.tsx +63 -0
- package/template/vite-wv/src/routes/secondary.tsx +28 -0
- package/template/vite-wv/src/utils/notification-helpers.ts +32 -0
- package/template/vite-wv/tsconfig.json +14 -0
- package/template/vite-wv/vite.config.ts +18 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { signIn, signOut, useSession } from "next-auth/react";
|
|
2
|
+
import Head from "next/head";
|
|
3
|
+
import Link from "next/link";
|
|
4
|
+
|
|
5
|
+
import { api } from "~/utils/api";
|
|
6
|
+
|
|
7
|
+
export default function Home() {
|
|
8
|
+
const hello = api.post.hello.useQuery({ text: "from tRPC" });
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<>
|
|
12
|
+
<Head>
|
|
13
|
+
<title>Create T3 App</title>
|
|
14
|
+
<meta name="description" content="Generated by proofkit" />
|
|
15
|
+
<link rel="icon" href="/favicon.ico" />
|
|
16
|
+
</Head>
|
|
17
|
+
<main className="flex min-h-screen flex-col items-center justify-center bg-gradient-to-b from-[#2e026d] to-[#15162c]">
|
|
18
|
+
<div className="container flex flex-col items-center justify-center gap-12 px-4 py-16">
|
|
19
|
+
<h1 className="text-5xl font-extrabold tracking-tight text-white sm:text-[5rem]">
|
|
20
|
+
Create <span className="text-[hsl(280,100%,70%)]">T3</span> App
|
|
21
|
+
</h1>
|
|
22
|
+
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 md:gap-8">
|
|
23
|
+
<Link
|
|
24
|
+
className="flex max-w-xs flex-col gap-4 rounded-xl bg-white/10 p-4 text-white hover:bg-white/20"
|
|
25
|
+
href="https://create.t3.gg/en/usage/first-steps"
|
|
26
|
+
target="_blank"
|
|
27
|
+
>
|
|
28
|
+
<h3 className="text-2xl font-bold">First Steps →</h3>
|
|
29
|
+
<div className="text-lg">
|
|
30
|
+
Just the basics - Everything you need to know to set up your
|
|
31
|
+
database and authentication.
|
|
32
|
+
</div>
|
|
33
|
+
</Link>
|
|
34
|
+
<Link
|
|
35
|
+
className="flex max-w-xs flex-col gap-4 rounded-xl bg-white/10 p-4 text-white hover:bg-white/20"
|
|
36
|
+
href="https://create.t3.gg/en/introduction"
|
|
37
|
+
target="_blank"
|
|
38
|
+
>
|
|
39
|
+
<h3 className="text-2xl font-bold">Documentation →</h3>
|
|
40
|
+
<div className="text-lg">
|
|
41
|
+
Learn more about Create T3 App, the libraries it uses, and how
|
|
42
|
+
to deploy it.
|
|
43
|
+
</div>
|
|
44
|
+
</Link>
|
|
45
|
+
</div>
|
|
46
|
+
<div className="flex flex-col items-center gap-2">
|
|
47
|
+
<p className="text-2xl text-white">
|
|
48
|
+
{hello.data ? hello.data.greeting : "Loading tRPC query..."}
|
|
49
|
+
</p>
|
|
50
|
+
<AuthShowcase />
|
|
51
|
+
</div>
|
|
52
|
+
</div>
|
|
53
|
+
</main>
|
|
54
|
+
</>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function AuthShowcase() {
|
|
59
|
+
const { data: sessionData } = useSession();
|
|
60
|
+
|
|
61
|
+
const { data: secretMessage } = api.post.getSecretMessage.useQuery(
|
|
62
|
+
undefined, // no input
|
|
63
|
+
{ enabled: sessionData?.user !== undefined }
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<div className="flex flex-col items-center justify-center gap-4">
|
|
68
|
+
<p className="text-center text-2xl text-white">
|
|
69
|
+
{sessionData && <span>Logged in as {sessionData.user?.name}</span>}
|
|
70
|
+
{secretMessage && <span> - {secretMessage}</span>}
|
|
71
|
+
</p>
|
|
72
|
+
<button
|
|
73
|
+
className="rounded-full bg-white/10 px-10 py-3 font-semibold text-white no-underline transition hover:bg-white/20"
|
|
74
|
+
onClick={sessionData ? () => void signOut() : () => void signIn()}
|
|
75
|
+
>
|
|
76
|
+
{sessionData ? "Sign out" : "Sign in"}
|
|
77
|
+
</button>
|
|
78
|
+
</div>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { signIn, signOut, useSession } from "next-auth/react";
|
|
2
|
+
import Head from "next/head";
|
|
3
|
+
import Link from "next/link";
|
|
4
|
+
|
|
5
|
+
import { api } from "~/utils/api";
|
|
6
|
+
import styles from "./index.module.css";
|
|
7
|
+
|
|
8
|
+
export default function Home() {
|
|
9
|
+
const hello = api.post.hello.useQuery({ text: "from tRPC" });
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<>
|
|
13
|
+
<Head>
|
|
14
|
+
<title>Create T3 App</title>
|
|
15
|
+
<meta name="description" content="Generated by proofkit" />
|
|
16
|
+
<link rel="icon" href="/favicon.ico" />
|
|
17
|
+
</Head>
|
|
18
|
+
<main className={styles.main}>
|
|
19
|
+
<div className={styles.container}>
|
|
20
|
+
<h1 className={styles.title}>
|
|
21
|
+
Create <span className={styles.pinkSpan}>T3</span> App
|
|
22
|
+
</h1>
|
|
23
|
+
<div className={styles.cardRow}>
|
|
24
|
+
<Link
|
|
25
|
+
className={styles.card}
|
|
26
|
+
href="https://create.t3.gg/en/usage/first-steps"
|
|
27
|
+
target="_blank"
|
|
28
|
+
>
|
|
29
|
+
<h3 className={styles.cardTitle}>First Steps →</h3>
|
|
30
|
+
<div className={styles.cardText}>
|
|
31
|
+
Just the basics - Everything you need to know to set up your
|
|
32
|
+
database and authentication.
|
|
33
|
+
</div>
|
|
34
|
+
</Link>
|
|
35
|
+
<Link
|
|
36
|
+
className={styles.card}
|
|
37
|
+
href="https://create.t3.gg/en/introduction"
|
|
38
|
+
target="_blank"
|
|
39
|
+
>
|
|
40
|
+
<h3 className={styles.cardTitle}>Documentation →</h3>
|
|
41
|
+
<div className={styles.cardText}>
|
|
42
|
+
Learn more about Create T3 App, the libraries it uses, and how
|
|
43
|
+
to deploy it.
|
|
44
|
+
</div>
|
|
45
|
+
</Link>
|
|
46
|
+
</div>
|
|
47
|
+
<div className={styles.showcaseContainer}>
|
|
48
|
+
<p className={styles.showcaseText}>
|
|
49
|
+
{hello.data ? hello.data.greeting : "Loading tRPC query..."}
|
|
50
|
+
</p>
|
|
51
|
+
<AuthShowcase />
|
|
52
|
+
</div>
|
|
53
|
+
</div>
|
|
54
|
+
</main>
|
|
55
|
+
</>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function AuthShowcase() {
|
|
60
|
+
const { data: sessionData } = useSession();
|
|
61
|
+
|
|
62
|
+
const { data: secretMessage } = api.post.getSecretMessage.useQuery(
|
|
63
|
+
undefined, // no input
|
|
64
|
+
{ enabled: sessionData?.user !== undefined }
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<div className={styles.authContainer}>
|
|
69
|
+
<p className={styles.showcaseText}>
|
|
70
|
+
{sessionData && <span>Logged in as {sessionData.user?.name}</span>}
|
|
71
|
+
{secretMessage && <span> - {secretMessage}</span>}
|
|
72
|
+
</p>
|
|
73
|
+
<button
|
|
74
|
+
className={styles.loginButton}
|
|
75
|
+
onClick={sessionData ? () => void signOut() : () => void signIn()}
|
|
76
|
+
>
|
|
77
|
+
{sessionData ? "Sign out" : "Sign in"}
|
|
78
|
+
</button>
|
|
79
|
+
</div>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import Head from "next/head";
|
|
2
|
+
import Link from "next/link";
|
|
3
|
+
|
|
4
|
+
import { api } from "~/utils/api";
|
|
5
|
+
|
|
6
|
+
export default function Home() {
|
|
7
|
+
const hello = api.post.hello.useQuery({ text: "from tRPC" });
|
|
8
|
+
|
|
9
|
+
return (
|
|
10
|
+
<>
|
|
11
|
+
<Head>
|
|
12
|
+
<title>Create T3 App</title>
|
|
13
|
+
<meta name="description" content="Generated by proofkit" />
|
|
14
|
+
<link rel="icon" href="/favicon.ico" />
|
|
15
|
+
</Head>
|
|
16
|
+
<main className="flex min-h-screen flex-col items-center justify-center bg-gradient-to-b from-[#2e026d] to-[#15162c]">
|
|
17
|
+
<div className="container flex flex-col items-center justify-center gap-12 px-4 py-16">
|
|
18
|
+
<h1 className="text-5xl font-extrabold tracking-tight text-white sm:text-[5rem]">
|
|
19
|
+
Create <span className="text-[hsl(280,100%,70%)]">T3</span> App
|
|
20
|
+
</h1>
|
|
21
|
+
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 md:gap-8">
|
|
22
|
+
<Link
|
|
23
|
+
className="flex max-w-xs flex-col gap-4 rounded-xl bg-white/10 p-4 text-white hover:bg-white/20"
|
|
24
|
+
href="https://create.t3.gg/en/usage/first-steps"
|
|
25
|
+
target="_blank"
|
|
26
|
+
>
|
|
27
|
+
<h3 className="text-2xl font-bold">First Steps →</h3>
|
|
28
|
+
<div className="text-lg">
|
|
29
|
+
Just the basics - Everything you need to know to set up your
|
|
30
|
+
database and authentication.
|
|
31
|
+
</div>
|
|
32
|
+
</Link>
|
|
33
|
+
<Link
|
|
34
|
+
className="flex max-w-xs flex-col gap-4 rounded-xl bg-white/10 p-4 text-white hover:bg-white/20"
|
|
35
|
+
href="https://create.t3.gg/en/introduction"
|
|
36
|
+
target="_blank"
|
|
37
|
+
>
|
|
38
|
+
<h3 className="text-2xl font-bold">Documentation →</h3>
|
|
39
|
+
<div className="text-lg">
|
|
40
|
+
Learn more about Create T3 App, the libraries it uses, and how
|
|
41
|
+
to deploy it.
|
|
42
|
+
</div>
|
|
43
|
+
</Link>
|
|
44
|
+
</div>
|
|
45
|
+
<p className="text-2xl text-white">
|
|
46
|
+
{hello.data ? hello.data.greeting : "Loading tRPC query..."}
|
|
47
|
+
</p>
|
|
48
|
+
</div>
|
|
49
|
+
</main>
|
|
50
|
+
</>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import Head from "next/head";
|
|
2
|
+
import Link from "next/link";
|
|
3
|
+
|
|
4
|
+
import { api } from "~/utils/api";
|
|
5
|
+
import styles from "./index.module.css";
|
|
6
|
+
|
|
7
|
+
export default function Home() {
|
|
8
|
+
const hello = api.post.hello.useQuery({ text: "from tRPC" });
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<>
|
|
12
|
+
<Head>
|
|
13
|
+
<title>Create T3 App</title>
|
|
14
|
+
<meta name="description" content="Generated by proofkit" />
|
|
15
|
+
<link rel="icon" href="/favicon.ico" />
|
|
16
|
+
</Head>
|
|
17
|
+
<main className={styles.main}>
|
|
18
|
+
<div className={styles.container}>
|
|
19
|
+
<h1 className={styles.title}>
|
|
20
|
+
Create <span className={styles.pinkSpan}>T3</span> App
|
|
21
|
+
</h1>
|
|
22
|
+
<div className={styles.cardRow}>
|
|
23
|
+
<Link
|
|
24
|
+
className={styles.card}
|
|
25
|
+
href="https://create.t3.gg/en/usage/first-steps"
|
|
26
|
+
target="_blank"
|
|
27
|
+
>
|
|
28
|
+
<h3 className={styles.cardTitle}>First Steps →</h3>
|
|
29
|
+
<div className={styles.cardText}>
|
|
30
|
+
Just the basics - Everything you need to know to set up your
|
|
31
|
+
database and authentication.
|
|
32
|
+
</div>
|
|
33
|
+
</Link>
|
|
34
|
+
<Link
|
|
35
|
+
className={styles.card}
|
|
36
|
+
href="https://create.t3.gg/en/introduction"
|
|
37
|
+
target="_blank"
|
|
38
|
+
>
|
|
39
|
+
<h3 className={styles.cardTitle}>Documentation →</h3>
|
|
40
|
+
<div className={styles.cardText}>
|
|
41
|
+
Learn more about Create T3 App, the libraries it uses, and how
|
|
42
|
+
to deploy it.
|
|
43
|
+
</div>
|
|
44
|
+
</Link>
|
|
45
|
+
</div>
|
|
46
|
+
<p className={styles.showcaseText}>
|
|
47
|
+
{hello.data ? hello.data.greeting : "Loading tRPC query..."}
|
|
48
|
+
</p>
|
|
49
|
+
</div>
|
|
50
|
+
</main>
|
|
51
|
+
</>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import Head from "next/head";
|
|
2
|
+
import Link from "next/link";
|
|
3
|
+
|
|
4
|
+
export default function Home() {
|
|
5
|
+
return (
|
|
6
|
+
<>
|
|
7
|
+
<Head>
|
|
8
|
+
<title>Create T3 App</title>
|
|
9
|
+
<meta name="description" content="Generated by proofkit" />
|
|
10
|
+
<link rel="icon" href="/favicon.ico" />
|
|
11
|
+
</Head>
|
|
12
|
+
<main className="flex min-h-screen flex-col items-center justify-center bg-gradient-to-b from-[#2e026d] to-[#15162c]">
|
|
13
|
+
<div className="container flex flex-col items-center justify-center gap-12 px-4 py-16">
|
|
14
|
+
<h1 className="text-5xl font-extrabold tracking-tight text-white sm:text-[5rem]">
|
|
15
|
+
Create <span className="text-[hsl(280,100%,70%)]">T3</span> App
|
|
16
|
+
</h1>
|
|
17
|
+
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 md:gap-8">
|
|
18
|
+
<Link
|
|
19
|
+
className="flex max-w-xs flex-col gap-4 rounded-xl bg-white/10 p-4 text-white hover:bg-white/20"
|
|
20
|
+
href="https://create.t3.gg/en/usage/first-steps"
|
|
21
|
+
target="_blank"
|
|
22
|
+
>
|
|
23
|
+
<h3 className="text-2xl font-bold">First Steps →</h3>
|
|
24
|
+
<div className="text-lg">
|
|
25
|
+
Just the basics - Everything you need to know to set up your
|
|
26
|
+
database and authentication.
|
|
27
|
+
</div>
|
|
28
|
+
</Link>
|
|
29
|
+
<Link
|
|
30
|
+
className="flex max-w-xs flex-col gap-4 rounded-xl bg-white/10 p-4 text-white hover:bg-white/20"
|
|
31
|
+
href="https://create.t3.gg/en/introduction"
|
|
32
|
+
target="_blank"
|
|
33
|
+
>
|
|
34
|
+
<h3 className="text-2xl font-bold">Documentation →</h3>
|
|
35
|
+
<div className="text-lg">
|
|
36
|
+
Learn more about Create T3 App, the libraries it uses, and how
|
|
37
|
+
to deploy it.
|
|
38
|
+
</div>
|
|
39
|
+
</Link>
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
</main>
|
|
43
|
+
</>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { postRouter } from "~/server/api/routers/post";
|
|
2
|
+
import { createCallerFactory, createTRPCRouter } from "~/server/api/trpc";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This is the primary router for your server.
|
|
6
|
+
*
|
|
7
|
+
* All routers added in /api/routers should be manually added here.
|
|
8
|
+
*/
|
|
9
|
+
export const appRouter = createTRPCRouter({
|
|
10
|
+
post: postRouter,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
// export type definition of API
|
|
14
|
+
export type AppRouter = typeof appRouter;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Create a server-side caller for the tRPC API.
|
|
18
|
+
* @example
|
|
19
|
+
* const trpc = createCaller(createContext);
|
|
20
|
+
* const res = await trpc.post.all();
|
|
21
|
+
* ^? Post[]
|
|
22
|
+
*/
|
|
23
|
+
export const createCaller = createCallerFactory(appRouter);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
|
|
3
|
+
import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";
|
|
4
|
+
|
|
5
|
+
// Mocked DB
|
|
6
|
+
interface Post {
|
|
7
|
+
id: number;
|
|
8
|
+
name: string;
|
|
9
|
+
}
|
|
10
|
+
const posts: Post[] = [
|
|
11
|
+
{
|
|
12
|
+
id: 1,
|
|
13
|
+
name: "Hello World",
|
|
14
|
+
},
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
export const postRouter = createTRPCRouter({
|
|
18
|
+
hello: publicProcedure
|
|
19
|
+
.input(z.object({ text: z.string() }))
|
|
20
|
+
.query(({ input }) => {
|
|
21
|
+
return {
|
|
22
|
+
greeting: `Hello ${input.text}`,
|
|
23
|
+
};
|
|
24
|
+
}),
|
|
25
|
+
|
|
26
|
+
create: publicProcedure
|
|
27
|
+
.input(z.object({ name: z.string().min(1) }))
|
|
28
|
+
.mutation(async ({ input }) => {
|
|
29
|
+
const post: Post = {
|
|
30
|
+
id: posts.length + 1,
|
|
31
|
+
name: input.name,
|
|
32
|
+
};
|
|
33
|
+
posts.push(post);
|
|
34
|
+
return post;
|
|
35
|
+
}),
|
|
36
|
+
|
|
37
|
+
getLatest: publicProcedure.query(() => {
|
|
38
|
+
return posts.at(-1) ?? null;
|
|
39
|
+
}),
|
|
40
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createTRPCRouter,
|
|
5
|
+
protectedProcedure,
|
|
6
|
+
publicProcedure,
|
|
7
|
+
} from "~/server/api/trpc";
|
|
8
|
+
import { posts } from "~/server/db/schema";
|
|
9
|
+
|
|
10
|
+
export const postRouter = createTRPCRouter({
|
|
11
|
+
hello: publicProcedure
|
|
12
|
+
.input(z.object({ text: z.string() }))
|
|
13
|
+
.query(({ input }) => {
|
|
14
|
+
return {
|
|
15
|
+
greeting: `Hello ${input.text}`,
|
|
16
|
+
};
|
|
17
|
+
}),
|
|
18
|
+
|
|
19
|
+
create: protectedProcedure
|
|
20
|
+
.input(z.object({ name: z.string().min(1) }))
|
|
21
|
+
.mutation(async ({ ctx, input }) => {
|
|
22
|
+
await ctx.db.insert(posts).values({
|
|
23
|
+
name: input.name,
|
|
24
|
+
createdById: ctx.session.user.id,
|
|
25
|
+
});
|
|
26
|
+
}),
|
|
27
|
+
|
|
28
|
+
getLatest: publicProcedure.query(async ({ ctx }) => {
|
|
29
|
+
const post = await ctx.db.query.posts.findFirst({
|
|
30
|
+
orderBy: (posts, { desc }) => [desc(posts.createdAt)],
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return post ?? null;
|
|
34
|
+
}),
|
|
35
|
+
|
|
36
|
+
getSecretMessage: protectedProcedure.query(() => {
|
|
37
|
+
return "you can now see this secret message!";
|
|
38
|
+
}),
|
|
39
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createTRPCRouter,
|
|
5
|
+
protectedProcedure,
|
|
6
|
+
publicProcedure,
|
|
7
|
+
} from "~/server/api/trpc";
|
|
8
|
+
|
|
9
|
+
export const postRouter = createTRPCRouter({
|
|
10
|
+
hello: publicProcedure
|
|
11
|
+
.input(z.object({ text: z.string() }))
|
|
12
|
+
.query(({ input }) => {
|
|
13
|
+
return {
|
|
14
|
+
greeting: `Hello ${input.text}`,
|
|
15
|
+
};
|
|
16
|
+
}),
|
|
17
|
+
|
|
18
|
+
create: protectedProcedure
|
|
19
|
+
.input(z.object({ name: z.string().min(1) }))
|
|
20
|
+
.mutation(async ({ ctx, input }) => {
|
|
21
|
+
return ctx.db.post.create({
|
|
22
|
+
data: {
|
|
23
|
+
name: input.name,
|
|
24
|
+
createdBy: { connect: { id: ctx.session.user.id } },
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}),
|
|
28
|
+
|
|
29
|
+
getLatest: protectedProcedure.query(async ({ ctx }) => {
|
|
30
|
+
const post = await ctx.db.post.findFirst({
|
|
31
|
+
orderBy: { createdAt: "desc" },
|
|
32
|
+
where: { createdBy: { id: ctx.session.user.id } },
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
return post ?? null;
|
|
36
|
+
}),
|
|
37
|
+
|
|
38
|
+
getSecretMessage: protectedProcedure.query(() => {
|
|
39
|
+
return "you can now see this secret message!";
|
|
40
|
+
}),
|
|
41
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createTRPCRouter,
|
|
5
|
+
protectedProcedure,
|
|
6
|
+
publicProcedure,
|
|
7
|
+
} from "~/server/api/trpc";
|
|
8
|
+
|
|
9
|
+
let post = {
|
|
10
|
+
id: 1,
|
|
11
|
+
name: "Hello World",
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const postRouter = createTRPCRouter({
|
|
15
|
+
hello: publicProcedure
|
|
16
|
+
.input(z.object({ text: z.string() }))
|
|
17
|
+
.query(({ input }) => {
|
|
18
|
+
return {
|
|
19
|
+
greeting: `Hello ${input.text}`,
|
|
20
|
+
};
|
|
21
|
+
}),
|
|
22
|
+
|
|
23
|
+
create: protectedProcedure
|
|
24
|
+
.input(z.object({ name: z.string().min(1) }))
|
|
25
|
+
.mutation(async ({ input }) => {
|
|
26
|
+
post = { id: post.id + 1, name: input.name };
|
|
27
|
+
return post;
|
|
28
|
+
}),
|
|
29
|
+
|
|
30
|
+
getLatest: protectedProcedure.query(() => {
|
|
31
|
+
return post;
|
|
32
|
+
}),
|
|
33
|
+
|
|
34
|
+
getSecretMessage: protectedProcedure.query(() => {
|
|
35
|
+
return "you can now see this secret message!";
|
|
36
|
+
}),
|
|
37
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
|
|
3
|
+
import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";
|
|
4
|
+
import { posts } from "~/server/db/schema";
|
|
5
|
+
|
|
6
|
+
export const postRouter = createTRPCRouter({
|
|
7
|
+
hello: publicProcedure
|
|
8
|
+
.input(z.object({ text: z.string() }))
|
|
9
|
+
.query(({ input }) => {
|
|
10
|
+
return {
|
|
11
|
+
greeting: `Hello ${input.text}`,
|
|
12
|
+
};
|
|
13
|
+
}),
|
|
14
|
+
|
|
15
|
+
create: publicProcedure
|
|
16
|
+
.input(z.object({ name: z.string().min(1) }))
|
|
17
|
+
.mutation(async ({ ctx, input }) => {
|
|
18
|
+
await ctx.db.insert(posts).values({
|
|
19
|
+
name: input.name,
|
|
20
|
+
});
|
|
21
|
+
}),
|
|
22
|
+
|
|
23
|
+
getLatest: publicProcedure.query(async ({ ctx }) => {
|
|
24
|
+
const post = await ctx.db.query.posts.findFirst({
|
|
25
|
+
orderBy: (posts, { desc }) => [desc(posts.createdAt)],
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
return post ?? null;
|
|
29
|
+
}),
|
|
30
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
|
|
3
|
+
import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";
|
|
4
|
+
|
|
5
|
+
export const postRouter = createTRPCRouter({
|
|
6
|
+
hello: publicProcedure
|
|
7
|
+
.input(z.object({ text: z.string() }))
|
|
8
|
+
.query(({ input }) => {
|
|
9
|
+
return {
|
|
10
|
+
greeting: `Hello ${input.text}`,
|
|
11
|
+
};
|
|
12
|
+
}),
|
|
13
|
+
|
|
14
|
+
create: publicProcedure
|
|
15
|
+
.input(z.object({ name: z.string().min(1) }))
|
|
16
|
+
.mutation(async ({ ctx, input }) => {
|
|
17
|
+
return ctx.db.post.create({
|
|
18
|
+
data: {
|
|
19
|
+
name: input.name,
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
}),
|
|
23
|
+
|
|
24
|
+
getLatest: publicProcedure.query(async ({ ctx }) => {
|
|
25
|
+
const post = await ctx.db.post.findFirst({
|
|
26
|
+
orderBy: { createdAt: "desc" },
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return post ?? null;
|
|
30
|
+
}),
|
|
31
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* YOU PROBABLY DON'T NEED TO EDIT THIS FILE, UNLESS:
|
|
3
|
+
* 1. You want to modify request context (see Part 1).
|
|
4
|
+
* 2. You want to create a new middleware or type of procedure (see Part 3).
|
|
5
|
+
*
|
|
6
|
+
* TL;DR - This is where all the tRPC server stuff is created and plugged in. The pieces you will
|
|
7
|
+
* need to use are documented accordingly near the end.
|
|
8
|
+
*/
|
|
9
|
+
import { initTRPC } from "@trpc/server";
|
|
10
|
+
import superjson from "superjson";
|
|
11
|
+
import { ZodError } from "zod/v4";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 1. CONTEXT
|
|
15
|
+
*
|
|
16
|
+
* This section defines the "contexts" that are available in the backend API.
|
|
17
|
+
*
|
|
18
|
+
* These allow you to access things when processing a request, like the database, the session, etc.
|
|
19
|
+
*
|
|
20
|
+
* This helper generates the "internals" for a tRPC context. The API handler and RSC clients each
|
|
21
|
+
* wrap this and provides the required context.
|
|
22
|
+
*
|
|
23
|
+
* @see https://trpc.io/docs/server/context
|
|
24
|
+
*/
|
|
25
|
+
export const createTRPCContext = async (opts: { headers: Headers }) => {
|
|
26
|
+
return {
|
|
27
|
+
...opts,
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 2. INITIALIZATION
|
|
33
|
+
*
|
|
34
|
+
* This is where the tRPC API is initialized, connecting the context and transformer. We also parse
|
|
35
|
+
* ZodErrors so that you get typesafety on the frontend if your procedure fails due to validation
|
|
36
|
+
* errors on the backend.
|
|
37
|
+
*/
|
|
38
|
+
const t = initTRPC.context<typeof createTRPCContext>().create({
|
|
39
|
+
transformer: superjson,
|
|
40
|
+
errorFormatter({ shape, error }) {
|
|
41
|
+
return {
|
|
42
|
+
...shape,
|
|
43
|
+
data: {
|
|
44
|
+
...shape.data,
|
|
45
|
+
zodError:
|
|
46
|
+
error.cause instanceof ZodError ? error.cause.flatten() : null,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Create a server-side caller.
|
|
54
|
+
*
|
|
55
|
+
* @see https://trpc.io/docs/server/server-side-calls
|
|
56
|
+
*/
|
|
57
|
+
export const createCallerFactory = t.createCallerFactory;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 3. ROUTER & PROCEDURE (THE IMPORTANT BIT)
|
|
61
|
+
*
|
|
62
|
+
* These are the pieces you use to build your tRPC API. You should import these a lot in the
|
|
63
|
+
* "/src/server/api/routers" directory.
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* This is how you create new routers and sub-routers in your tRPC API.
|
|
68
|
+
*
|
|
69
|
+
* @see https://trpc.io/docs/router
|
|
70
|
+
*/
|
|
71
|
+
export const createTRPCRouter = t.router;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Middleware for timing procedure execution and adding an articifial delay in development.
|
|
75
|
+
*
|
|
76
|
+
* You can remove this if you don't like it, but it can help catch unwanted waterfalls by simulating
|
|
77
|
+
* network latency that would occur in production but not in local development.
|
|
78
|
+
*/
|
|
79
|
+
const timingMiddleware = t.middleware(async ({ next, path }) => {
|
|
80
|
+
const start = Date.now();
|
|
81
|
+
|
|
82
|
+
if (t._config.isDev) {
|
|
83
|
+
// artificial delay in dev
|
|
84
|
+
const waitMs = Math.floor(Math.random() * 400) + 100;
|
|
85
|
+
await new Promise((resolve) => setTimeout(resolve, waitMs));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const result = await next();
|
|
89
|
+
|
|
90
|
+
const end = Date.now();
|
|
91
|
+
console.log(`[TRPC] ${path} took ${end - start}ms to execute`);
|
|
92
|
+
|
|
93
|
+
return result;
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Public (unauthenticated) procedure
|
|
98
|
+
*
|
|
99
|
+
* This is the base piece you use to build new queries and mutations on your tRPC API. It does not
|
|
100
|
+
* guarantee that a user querying is authorized, but you can still access user session data if they
|
|
101
|
+
* are logged in.
|
|
102
|
+
*/
|
|
103
|
+
export const publicProcedure = t.procedure.use(timingMiddleware);
|