@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,117 @@
|
|
|
1
|
+
import { relations, sql } from "drizzle-orm";
|
|
2
|
+
import {
|
|
3
|
+
bigint,
|
|
4
|
+
index,
|
|
5
|
+
int,
|
|
6
|
+
mysqlTableCreator,
|
|
7
|
+
primaryKey,
|
|
8
|
+
text,
|
|
9
|
+
timestamp,
|
|
10
|
+
varchar,
|
|
11
|
+
} from "drizzle-orm/mysql-core";
|
|
12
|
+
import { type AdapterAccount } from "next-auth/adapters";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* This is an example of how to use the multi-project schema feature of Drizzle ORM. Use the same
|
|
16
|
+
* database instance for multiple projects.
|
|
17
|
+
*
|
|
18
|
+
* @see https://orm.drizzle.team/docs/goodies#multi-project-schema
|
|
19
|
+
*/
|
|
20
|
+
export const createTable = mysqlTableCreator((name) => `project1_${name}`);
|
|
21
|
+
|
|
22
|
+
export const posts = createTable(
|
|
23
|
+
"post",
|
|
24
|
+
{
|
|
25
|
+
id: bigint("id", { mode: "number" }).primaryKey().autoincrement(),
|
|
26
|
+
name: varchar("name", { length: 256 }),
|
|
27
|
+
createdById: varchar("created_by", { length: 255 }).notNull(),
|
|
28
|
+
createdAt: timestamp("created_at")
|
|
29
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
30
|
+
.notNull(),
|
|
31
|
+
updatedAt: timestamp("updated_at").onUpdateNow(),
|
|
32
|
+
},
|
|
33
|
+
(example) => ({
|
|
34
|
+
createdByIdIdx: index("created_by_idx").on(example.createdById),
|
|
35
|
+
nameIndex: index("name_idx").on(example.name),
|
|
36
|
+
})
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
export const users = createTable("user", {
|
|
40
|
+
id: varchar("id", { length: 255 })
|
|
41
|
+
.notNull()
|
|
42
|
+
.primaryKey()
|
|
43
|
+
.$defaultFn(() => crypto.randomUUID()),
|
|
44
|
+
name: varchar("name", { length: 255 }),
|
|
45
|
+
email: varchar("email", { length: 255 }).notNull(),
|
|
46
|
+
emailVerified: timestamp("email_verified", {
|
|
47
|
+
mode: "date",
|
|
48
|
+
fsp: 3,
|
|
49
|
+
}).default(sql`CURRENT_TIMESTAMP(3)`),
|
|
50
|
+
image: varchar("image", { length: 255 }),
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
export const usersRelations = relations(users, ({ many }) => ({
|
|
54
|
+
accounts: many(accounts),
|
|
55
|
+
sessions: many(sessions),
|
|
56
|
+
}));
|
|
57
|
+
|
|
58
|
+
export const accounts = createTable(
|
|
59
|
+
"account",
|
|
60
|
+
{
|
|
61
|
+
userId: varchar("user_id", { length: 255 }).notNull(),
|
|
62
|
+
type: varchar("type", { length: 255 })
|
|
63
|
+
.$type<AdapterAccount["type"]>()
|
|
64
|
+
.notNull(),
|
|
65
|
+
provider: varchar("provider", { length: 255 }).notNull(),
|
|
66
|
+
providerAccountId: varchar("provider_account_id", {
|
|
67
|
+
length: 255,
|
|
68
|
+
}).notNull(),
|
|
69
|
+
refresh_token: text("refresh_token"),
|
|
70
|
+
access_token: text("access_token"),
|
|
71
|
+
expires_at: int("expires_at"),
|
|
72
|
+
token_type: varchar("token_type", { length: 255 }),
|
|
73
|
+
scope: varchar("scope", { length: 255 }),
|
|
74
|
+
id_token: text("id_token"),
|
|
75
|
+
session_state: varchar("session_state", { length: 255 }),
|
|
76
|
+
},
|
|
77
|
+
(account) => ({
|
|
78
|
+
compoundKey: primaryKey({
|
|
79
|
+
columns: [account.provider, account.providerAccountId],
|
|
80
|
+
}),
|
|
81
|
+
userIdIdx: index("accounts_user_id_idx").on(account.userId),
|
|
82
|
+
})
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
export const accountsRelations = relations(accounts, ({ one }) => ({
|
|
86
|
+
user: one(users, { fields: [accounts.userId], references: [users.id] }),
|
|
87
|
+
}));
|
|
88
|
+
|
|
89
|
+
export const sessions = createTable(
|
|
90
|
+
"session",
|
|
91
|
+
{
|
|
92
|
+
sessionToken: varchar("session_token", { length: 255 })
|
|
93
|
+
.notNull()
|
|
94
|
+
.primaryKey(),
|
|
95
|
+
userId: varchar("user_id", { length: 255 }).notNull(),
|
|
96
|
+
expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
97
|
+
},
|
|
98
|
+
(session) => ({
|
|
99
|
+
userIdIdx: index("session_user_id_idx").on(session.userId),
|
|
100
|
+
})
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
export const sessionsRelations = relations(sessions, ({ one }) => ({
|
|
104
|
+
user: one(users, { fields: [sessions.userId], references: [users.id] }),
|
|
105
|
+
}));
|
|
106
|
+
|
|
107
|
+
export const verificationTokens = createTable(
|
|
108
|
+
"verification_token",
|
|
109
|
+
{
|
|
110
|
+
identifier: varchar("identifier", { length: 255 }).notNull(),
|
|
111
|
+
token: varchar("token", { length: 255 }).notNull(),
|
|
112
|
+
expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
113
|
+
},
|
|
114
|
+
(vt) => ({
|
|
115
|
+
compoundKey: primaryKey({ columns: [vt.identifier, vt.token] }),
|
|
116
|
+
})
|
|
117
|
+
);
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { relations, sql } from "drizzle-orm";
|
|
2
|
+
import {
|
|
3
|
+
index,
|
|
4
|
+
integer,
|
|
5
|
+
pgTableCreator,
|
|
6
|
+
primaryKey,
|
|
7
|
+
serial,
|
|
8
|
+
text,
|
|
9
|
+
timestamp,
|
|
10
|
+
varchar,
|
|
11
|
+
} from "drizzle-orm/pg-core";
|
|
12
|
+
import { type AdapterAccount } from "next-auth/adapters";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* This is an example of how to use the multi-project schema feature of Drizzle ORM. Use the same
|
|
16
|
+
* database instance for multiple projects.
|
|
17
|
+
*
|
|
18
|
+
* @see https://orm.drizzle.team/docs/goodies#multi-project-schema
|
|
19
|
+
*/
|
|
20
|
+
export const createTable = pgTableCreator((name) => `project1_${name}`);
|
|
21
|
+
|
|
22
|
+
export const posts = createTable(
|
|
23
|
+
"post",
|
|
24
|
+
{
|
|
25
|
+
id: serial("id").primaryKey(),
|
|
26
|
+
name: varchar("name", { length: 256 }),
|
|
27
|
+
createdById: varchar("created_by", { length: 255 })
|
|
28
|
+
.notNull()
|
|
29
|
+
.references(() => users.id),
|
|
30
|
+
createdAt: timestamp("created_at", { withTimezone: true })
|
|
31
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
32
|
+
.notNull(),
|
|
33
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).$onUpdate(
|
|
34
|
+
() => new Date()
|
|
35
|
+
),
|
|
36
|
+
},
|
|
37
|
+
(example) => ({
|
|
38
|
+
createdByIdIdx: index("created_by_idx").on(example.createdById),
|
|
39
|
+
nameIndex: index("name_idx").on(example.name),
|
|
40
|
+
})
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
export const users = createTable("user", {
|
|
44
|
+
id: varchar("id", { length: 255 })
|
|
45
|
+
.notNull()
|
|
46
|
+
.primaryKey()
|
|
47
|
+
.$defaultFn(() => crypto.randomUUID()),
|
|
48
|
+
name: varchar("name", { length: 255 }),
|
|
49
|
+
email: varchar("email", { length: 255 }).notNull(),
|
|
50
|
+
emailVerified: timestamp("email_verified", {
|
|
51
|
+
mode: "date",
|
|
52
|
+
withTimezone: true,
|
|
53
|
+
}).default(sql`CURRENT_TIMESTAMP`),
|
|
54
|
+
image: varchar("image", { length: 255 }),
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export const usersRelations = relations(users, ({ many }) => ({
|
|
58
|
+
accounts: many(accounts),
|
|
59
|
+
}));
|
|
60
|
+
|
|
61
|
+
export const accounts = createTable(
|
|
62
|
+
"account",
|
|
63
|
+
{
|
|
64
|
+
userId: varchar("user_id", { length: 255 })
|
|
65
|
+
.notNull()
|
|
66
|
+
.references(() => users.id),
|
|
67
|
+
type: varchar("type", { length: 255 })
|
|
68
|
+
.$type<AdapterAccount["type"]>()
|
|
69
|
+
.notNull(),
|
|
70
|
+
provider: varchar("provider", { length: 255 }).notNull(),
|
|
71
|
+
providerAccountId: varchar("provider_account_id", {
|
|
72
|
+
length: 255,
|
|
73
|
+
}).notNull(),
|
|
74
|
+
refresh_token: text("refresh_token"),
|
|
75
|
+
access_token: text("access_token"),
|
|
76
|
+
expires_at: integer("expires_at"),
|
|
77
|
+
token_type: varchar("token_type", { length: 255 }),
|
|
78
|
+
scope: varchar("scope", { length: 255 }),
|
|
79
|
+
id_token: text("id_token"),
|
|
80
|
+
session_state: varchar("session_state", { length: 255 }),
|
|
81
|
+
},
|
|
82
|
+
(account) => ({
|
|
83
|
+
compoundKey: primaryKey({
|
|
84
|
+
columns: [account.provider, account.providerAccountId],
|
|
85
|
+
}),
|
|
86
|
+
userIdIdx: index("account_user_id_idx").on(account.userId),
|
|
87
|
+
})
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
export const accountsRelations = relations(accounts, ({ one }) => ({
|
|
91
|
+
user: one(users, { fields: [accounts.userId], references: [users.id] }),
|
|
92
|
+
}));
|
|
93
|
+
|
|
94
|
+
export const sessions = createTable(
|
|
95
|
+
"session",
|
|
96
|
+
{
|
|
97
|
+
sessionToken: varchar("session_token", { length: 255 })
|
|
98
|
+
.notNull()
|
|
99
|
+
.primaryKey(),
|
|
100
|
+
userId: varchar("user_id", { length: 255 })
|
|
101
|
+
.notNull()
|
|
102
|
+
.references(() => users.id),
|
|
103
|
+
expires: timestamp("expires", {
|
|
104
|
+
mode: "date",
|
|
105
|
+
withTimezone: true,
|
|
106
|
+
}).notNull(),
|
|
107
|
+
},
|
|
108
|
+
(session) => ({
|
|
109
|
+
userIdIdx: index("session_user_id_idx").on(session.userId),
|
|
110
|
+
})
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
export const sessionsRelations = relations(sessions, ({ one }) => ({
|
|
114
|
+
user: one(users, { fields: [sessions.userId], references: [users.id] }),
|
|
115
|
+
}));
|
|
116
|
+
|
|
117
|
+
export const verificationTokens = createTable(
|
|
118
|
+
"verification_token",
|
|
119
|
+
{
|
|
120
|
+
identifier: varchar("identifier", { length: 255 }).notNull(),
|
|
121
|
+
token: varchar("token", { length: 255 }).notNull(),
|
|
122
|
+
expires: timestamp("expires", {
|
|
123
|
+
mode: "date",
|
|
124
|
+
withTimezone: true,
|
|
125
|
+
}).notNull(),
|
|
126
|
+
},
|
|
127
|
+
(vt) => ({
|
|
128
|
+
compoundKey: primaryKey({ columns: [vt.identifier, vt.token] }),
|
|
129
|
+
})
|
|
130
|
+
);
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { relations, sql } from "drizzle-orm";
|
|
2
|
+
import {
|
|
3
|
+
index,
|
|
4
|
+
int,
|
|
5
|
+
primaryKey,
|
|
6
|
+
sqliteTableCreator,
|
|
7
|
+
text,
|
|
8
|
+
} from "drizzle-orm/sqlite-core";
|
|
9
|
+
import { type AdapterAccount } from "next-auth/adapters";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* This is an example of how to use the multi-project schema feature of Drizzle ORM. Use the same
|
|
13
|
+
* database instance for multiple projects.
|
|
14
|
+
*
|
|
15
|
+
* @see https://orm.drizzle.team/docs/goodies#multi-project-schema
|
|
16
|
+
*/
|
|
17
|
+
export const createTable = sqliteTableCreator((name) => `project1_${name}`);
|
|
18
|
+
|
|
19
|
+
export const posts = createTable(
|
|
20
|
+
"post",
|
|
21
|
+
{
|
|
22
|
+
id: int("id", { mode: "number" }).primaryKey({ autoIncrement: true }),
|
|
23
|
+
name: text("name", { length: 256 }),
|
|
24
|
+
createdById: text("created_by", { length: 255 })
|
|
25
|
+
.notNull()
|
|
26
|
+
.references(() => users.id),
|
|
27
|
+
createdAt: int("created_at", { mode: "timestamp" })
|
|
28
|
+
.default(sql`(unixepoch())`)
|
|
29
|
+
.notNull(),
|
|
30
|
+
updatedAt: int("updatedAt", { mode: "timestamp" }).$onUpdate(
|
|
31
|
+
() => new Date()
|
|
32
|
+
),
|
|
33
|
+
},
|
|
34
|
+
(example) => ({
|
|
35
|
+
createdByIdIdx: index("created_by_idx").on(example.createdById),
|
|
36
|
+
nameIndex: index("name_idx").on(example.name),
|
|
37
|
+
})
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
export const users = createTable("user", {
|
|
41
|
+
id: text("id", { length: 255 })
|
|
42
|
+
.notNull()
|
|
43
|
+
.primaryKey()
|
|
44
|
+
.$defaultFn(() => crypto.randomUUID()),
|
|
45
|
+
name: text("name", { length: 255 }),
|
|
46
|
+
email: text("email", { length: 255 }).notNull(),
|
|
47
|
+
emailVerified: int("email_verified", {
|
|
48
|
+
mode: "timestamp",
|
|
49
|
+
}).default(sql`(unixepoch())`),
|
|
50
|
+
image: text("image", { length: 255 }),
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
export const usersRelations = relations(users, ({ many }) => ({
|
|
54
|
+
accounts: many(accounts),
|
|
55
|
+
}));
|
|
56
|
+
|
|
57
|
+
export const accounts = createTable(
|
|
58
|
+
"account",
|
|
59
|
+
{
|
|
60
|
+
userId: text("user_id", { length: 255 })
|
|
61
|
+
.notNull()
|
|
62
|
+
.references(() => users.id),
|
|
63
|
+
type: text("type", { length: 255 })
|
|
64
|
+
.$type<AdapterAccount["type"]>()
|
|
65
|
+
.notNull(),
|
|
66
|
+
provider: text("provider", { length: 255 }).notNull(),
|
|
67
|
+
providerAccountId: text("provider_account_id", { length: 255 }).notNull(),
|
|
68
|
+
refresh_token: text("refresh_token"),
|
|
69
|
+
access_token: text("access_token"),
|
|
70
|
+
expires_at: int("expires_at"),
|
|
71
|
+
token_type: text("token_type", { length: 255 }),
|
|
72
|
+
scope: text("scope", { length: 255 }),
|
|
73
|
+
id_token: text("id_token"),
|
|
74
|
+
session_state: text("session_state", { length: 255 }),
|
|
75
|
+
},
|
|
76
|
+
(account) => ({
|
|
77
|
+
compoundKey: primaryKey({
|
|
78
|
+
columns: [account.provider, account.providerAccountId],
|
|
79
|
+
}),
|
|
80
|
+
userIdIdx: index("account_user_id_idx").on(account.userId),
|
|
81
|
+
})
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
export const accountsRelations = relations(accounts, ({ one }) => ({
|
|
85
|
+
user: one(users, { fields: [accounts.userId], references: [users.id] }),
|
|
86
|
+
}));
|
|
87
|
+
|
|
88
|
+
export const sessions = createTable(
|
|
89
|
+
"session",
|
|
90
|
+
{
|
|
91
|
+
sessionToken: text("session_token", { length: 255 }).notNull().primaryKey(),
|
|
92
|
+
userId: text("userId", { length: 255 })
|
|
93
|
+
.notNull()
|
|
94
|
+
.references(() => users.id),
|
|
95
|
+
expires: int("expires", { mode: "timestamp" }).notNull(),
|
|
96
|
+
},
|
|
97
|
+
(session) => ({
|
|
98
|
+
userIdIdx: index("session_userId_idx").on(session.userId),
|
|
99
|
+
})
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
export const sessionsRelations = relations(sessions, ({ one }) => ({
|
|
103
|
+
user: one(users, { fields: [sessions.userId], references: [users.id] }),
|
|
104
|
+
}));
|
|
105
|
+
|
|
106
|
+
export const verificationTokens = createTable(
|
|
107
|
+
"verification_token",
|
|
108
|
+
{
|
|
109
|
+
identifier: text("identifier", { length: 255 }).notNull(),
|
|
110
|
+
token: text("token", { length: 255 }).notNull(),
|
|
111
|
+
expires: int("expires", { mode: "timestamp" }).notNull(),
|
|
112
|
+
},
|
|
113
|
+
(vt) => ({
|
|
114
|
+
compoundKey: primaryKey({ columns: [vt.identifier, vt.token] }),
|
|
115
|
+
})
|
|
116
|
+
);
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
4
|
+
|
|
5
|
+
import { env } from "@/config/env";
|
|
6
|
+
import { OttoAdapter } from "@proofkit/fmdapi";
|
|
7
|
+
import NextAuth, { type DefaultSession } from "next-auth";
|
|
8
|
+
import { FilemakerAdapter } from "next-auth-adapter-filemaker";
|
|
9
|
+
import { type Provider } from "next-auth/providers";
|
|
10
|
+
import Credentials from "next-auth/providers/credentials";
|
|
11
|
+
import { z } from "zod/v4";
|
|
12
|
+
|
|
13
|
+
import { verifyPassword } from "./password";
|
|
14
|
+
|
|
15
|
+
export const fmAdapter = FilemakerAdapter({
|
|
16
|
+
adapter: new OttoAdapter({
|
|
17
|
+
auth: { apiKey: env.OTTO_API_KEY },
|
|
18
|
+
db: env.FM_DATABASE,
|
|
19
|
+
server: env.FM_SERVER,
|
|
20
|
+
}),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Module augmentation for `next-auth` types. Alldows us to add custom properties to the `session`
|
|
25
|
+
* object and keep type safety.
|
|
26
|
+
*
|
|
27
|
+
* @see https://next-auth.js.org/getting-started/typescript#module-augmentation
|
|
28
|
+
*/
|
|
29
|
+
declare module "next-auth" {
|
|
30
|
+
interface Session extends DefaultSession {
|
|
31
|
+
user: {
|
|
32
|
+
id: string;
|
|
33
|
+
// ...other properties
|
|
34
|
+
// role: UserRole;
|
|
35
|
+
} & DefaultSession["user"];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// interface User {
|
|
39
|
+
// // ...other properties
|
|
40
|
+
// // role: UserRole;
|
|
41
|
+
// }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const signInSchema = z.object({
|
|
45
|
+
email: z.string().email(),
|
|
46
|
+
password: z.string(),
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const providers: Provider[] = [
|
|
50
|
+
Credentials({
|
|
51
|
+
credentials: {
|
|
52
|
+
email: { label: "Email", type: "email" },
|
|
53
|
+
password: { label: "Password", type: "password" },
|
|
54
|
+
},
|
|
55
|
+
authorize: async (credentials) => {
|
|
56
|
+
const parsed = signInSchema.safeParse(credentials);
|
|
57
|
+
if (!parsed.success) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const { email, password } = parsed.data;
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
// logic to verify if the user exists with the password hash
|
|
65
|
+
const userResponse =
|
|
66
|
+
await fmAdapter.typedClients.userWithPasswordHash.findOne({
|
|
67
|
+
query: { email: `==${email.replace("@", "\\@")}` },
|
|
68
|
+
});
|
|
69
|
+
const { passwordHash, ...userData } = userResponse.data.fieldData;
|
|
70
|
+
const isValid = await verifyPassword(password, passwordHash);
|
|
71
|
+
if (!isValid) return null;
|
|
72
|
+
|
|
73
|
+
return userData;
|
|
74
|
+
} catch (error) {
|
|
75
|
+
console.log("error", error);
|
|
76
|
+
throw new Error("User not found.");
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
}),
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
export const providerMap = providers
|
|
83
|
+
.map((provider) => {
|
|
84
|
+
if (typeof provider === "function") {
|
|
85
|
+
const providerData = provider();
|
|
86
|
+
return { id: providerData.id, name: providerData.name };
|
|
87
|
+
} else {
|
|
88
|
+
return { id: provider.id, name: provider.name };
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
.filter((provider) => provider.id !== "credentials");
|
|
92
|
+
|
|
93
|
+
export const { auth, handlers, signIn, signOut } = NextAuth({
|
|
94
|
+
pages: {
|
|
95
|
+
signIn: "/auth/signin",
|
|
96
|
+
newUser: "/auth/signup",
|
|
97
|
+
error: "/auth/signin",
|
|
98
|
+
},
|
|
99
|
+
callbacks: {
|
|
100
|
+
session: ({ session, token }) => ({
|
|
101
|
+
...session,
|
|
102
|
+
user: {
|
|
103
|
+
...session.user,
|
|
104
|
+
id: token.sub,
|
|
105
|
+
},
|
|
106
|
+
}),
|
|
107
|
+
},
|
|
108
|
+
adapter: fmAdapter.Adapter,
|
|
109
|
+
session: { strategy: "jwt" },
|
|
110
|
+
providers,
|
|
111
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export async function saltAndHashPassword(password: string): Promise<string> {
|
|
2
|
+
const bcrypt = await import("bcrypt");
|
|
3
|
+
const saltRounds = 12;
|
|
4
|
+
return bcrypt.hash(password, saltRounds);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export async function verifyPassword(
|
|
8
|
+
plainTextPassword: string,
|
|
9
|
+
hashedPassword: string
|
|
10
|
+
): Promise<boolean> {
|
|
11
|
+
const bcrypt = await import("bcrypt");
|
|
12
|
+
return bcrypt.compare(plainTextPassword, hashedPassword);
|
|
13
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { DrizzleAdapter } from "@auth/drizzle-adapter";
|
|
2
|
+
import {
|
|
3
|
+
getServerSession,
|
|
4
|
+
type DefaultSession,
|
|
5
|
+
type NextAuthOptions,
|
|
6
|
+
} from "next-auth";
|
|
7
|
+
import { type Adapter } from "next-auth/adapters";
|
|
8
|
+
import DiscordProvider from "next-auth/providers/discord";
|
|
9
|
+
|
|
10
|
+
import { env } from "~/env";
|
|
11
|
+
import { db } from "~/server/db";
|
|
12
|
+
import {
|
|
13
|
+
accounts,
|
|
14
|
+
sessions,
|
|
15
|
+
users,
|
|
16
|
+
verificationTokens,
|
|
17
|
+
} from "~/server/db/schema";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Module augmentation for `next-auth` types. Allows us to add custom properties to the `session`
|
|
21
|
+
* object and keep type safety.
|
|
22
|
+
*
|
|
23
|
+
* @see https://next-auth.js.org/getting-started/typescript#module-augmentation
|
|
24
|
+
*/
|
|
25
|
+
declare module "next-auth" {
|
|
26
|
+
interface Session extends DefaultSession {
|
|
27
|
+
user: {
|
|
28
|
+
id: string;
|
|
29
|
+
// ...other properties
|
|
30
|
+
// role: UserRole;
|
|
31
|
+
} & DefaultSession["user"];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// interface User {
|
|
35
|
+
// // ...other properties
|
|
36
|
+
// // role: UserRole;
|
|
37
|
+
// }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Options for NextAuth.js used to configure adapters, providers, callbacks, etc.
|
|
42
|
+
*
|
|
43
|
+
* @see https://next-auth.js.org/configuration/options
|
|
44
|
+
*/
|
|
45
|
+
export const authOptions: NextAuthOptions = {
|
|
46
|
+
callbacks: {
|
|
47
|
+
session: ({ session, user }) => ({
|
|
48
|
+
...session,
|
|
49
|
+
user: {
|
|
50
|
+
...session.user,
|
|
51
|
+
id: user.id,
|
|
52
|
+
},
|
|
53
|
+
}),
|
|
54
|
+
},
|
|
55
|
+
adapter: DrizzleAdapter(db, {
|
|
56
|
+
usersTable: users,
|
|
57
|
+
accountsTable: accounts,
|
|
58
|
+
sessionsTable: sessions,
|
|
59
|
+
verificationTokensTable: verificationTokens,
|
|
60
|
+
}) as Adapter,
|
|
61
|
+
providers: [
|
|
62
|
+
DiscordProvider({
|
|
63
|
+
clientId: env.DISCORD_CLIENT_ID,
|
|
64
|
+
clientSecret: env.DISCORD_CLIENT_SECRET,
|
|
65
|
+
}),
|
|
66
|
+
/**
|
|
67
|
+
* ...add more providers here.
|
|
68
|
+
*
|
|
69
|
+
* Most other providers require a bit more work than the Discord provider. For example, the
|
|
70
|
+
* GitHub provider requires you to add the `refresh_token_expires_in` field to the Account
|
|
71
|
+
* model. Refer to the NextAuth.js docs for the provider you want to use. Example:
|
|
72
|
+
*
|
|
73
|
+
* @see https://next-auth.js.org/providers/github
|
|
74
|
+
*/
|
|
75
|
+
],
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Wrapper for `getServerSession` so that you don't need to import the `authOptions` in every file.
|
|
80
|
+
*
|
|
81
|
+
* @see https://next-auth.js.org/configuration/nextjs
|
|
82
|
+
*/
|
|
83
|
+
export const getServerAuthSession = () => getServerSession(authOptions);
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { PrismaAdapter } from "@auth/prisma-adapter";
|
|
2
|
+
import {
|
|
3
|
+
getServerSession,
|
|
4
|
+
type DefaultSession,
|
|
5
|
+
type NextAuthOptions,
|
|
6
|
+
} from "next-auth";
|
|
7
|
+
import { type Adapter } from "next-auth/adapters";
|
|
8
|
+
import DiscordProvider from "next-auth/providers/discord";
|
|
9
|
+
|
|
10
|
+
import { env } from "~/env";
|
|
11
|
+
import { db } from "~/server/db";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Module augmentation for `next-auth` types. Allows us to add custom properties to the `session`
|
|
15
|
+
* object and keep type safety.
|
|
16
|
+
*
|
|
17
|
+
* @see https://next-auth.js.org/getting-started/typescript#module-augmentation
|
|
18
|
+
*/
|
|
19
|
+
declare module "next-auth" {
|
|
20
|
+
interface Session extends DefaultSession {
|
|
21
|
+
user: {
|
|
22
|
+
id: string;
|
|
23
|
+
// ...other properties
|
|
24
|
+
// role: UserRole;
|
|
25
|
+
} & DefaultSession["user"];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// interface User {
|
|
29
|
+
// // ...other properties
|
|
30
|
+
// // role: UserRole;
|
|
31
|
+
// }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Options for NextAuth.js used to configure adapters, providers, callbacks, etc.
|
|
36
|
+
*
|
|
37
|
+
* @see https://next-auth.js.org/configuration/options
|
|
38
|
+
*/
|
|
39
|
+
export const authOptions: NextAuthOptions = {
|
|
40
|
+
callbacks: {
|
|
41
|
+
session: ({ session, user }) => ({
|
|
42
|
+
...session,
|
|
43
|
+
user: {
|
|
44
|
+
...session.user,
|
|
45
|
+
id: user.id,
|
|
46
|
+
},
|
|
47
|
+
}),
|
|
48
|
+
},
|
|
49
|
+
adapter: PrismaAdapter(db) as Adapter,
|
|
50
|
+
providers: [
|
|
51
|
+
DiscordProvider({
|
|
52
|
+
clientId: env.DISCORD_CLIENT_ID,
|
|
53
|
+
clientSecret: env.DISCORD_CLIENT_SECRET,
|
|
54
|
+
}),
|
|
55
|
+
/**
|
|
56
|
+
* ...add more providers here.
|
|
57
|
+
*
|
|
58
|
+
* Most other providers require a bit more work than the Discord provider. For example, the
|
|
59
|
+
* GitHub provider requires you to add the `refresh_token_expires_in` field to the Account
|
|
60
|
+
* model. Refer to the NextAuth.js docs for the provider you want to use. Example:
|
|
61
|
+
*
|
|
62
|
+
* @see https://next-auth.js.org/providers/github
|
|
63
|
+
*/
|
|
64
|
+
],
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Wrapper for `getServerSession` so that you don't need to import the `authOptions` in every file.
|
|
69
|
+
*
|
|
70
|
+
* @see https://next-auth.js.org/configuration/nextjs
|
|
71
|
+
*/
|
|
72
|
+
export const getServerAuthSession = () => getServerSession(authOptions);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defaultShouldDehydrateQuery,
|
|
3
|
+
QueryClient,
|
|
4
|
+
} from "@tanstack/react-query";
|
|
5
|
+
import SuperJSON from "superjson";
|
|
6
|
+
|
|
7
|
+
export const createQueryClient = () =>
|
|
8
|
+
new QueryClient({
|
|
9
|
+
defaultOptions: {
|
|
10
|
+
queries: {
|
|
11
|
+
// With SSR, we usually want to set some default staleTime
|
|
12
|
+
// above 0 to avoid refetching immediately on the client
|
|
13
|
+
staleTime: 30 * 1000,
|
|
14
|
+
},
|
|
15
|
+
dehydrate: {
|
|
16
|
+
serializeData: SuperJSON.serialize,
|
|
17
|
+
shouldDehydrateQuery: (query) =>
|
|
18
|
+
defaultShouldDehydrateQuery(query) ||
|
|
19
|
+
query.state.status === "pending",
|
|
20
|
+
},
|
|
21
|
+
hydrate: {
|
|
22
|
+
deserializeData: SuperJSON.deserialize,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
});
|