@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,56 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useHookFormAction } from "@next-safe-action/adapter-react-hook-form/hooks";
|
|
3
|
+
import { updateEmailSchema } from "./schema";
|
|
4
|
+
import { updateEmailAction } from "./actions";
|
|
5
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
6
|
+
import {
|
|
7
|
+
Anchor,
|
|
8
|
+
Button,
|
|
9
|
+
Group,
|
|
10
|
+
Paper,
|
|
11
|
+
PasswordInput,
|
|
12
|
+
Text,
|
|
13
|
+
} from "@mantine/core";
|
|
14
|
+
import { TextInput } from "@mantine/core";
|
|
15
|
+
import { Stack } from "@mantine/core";
|
|
16
|
+
|
|
17
|
+
export default function UpdateEmailForm({
|
|
18
|
+
currentEmail,
|
|
19
|
+
}: {
|
|
20
|
+
currentEmail: string;
|
|
21
|
+
}) {
|
|
22
|
+
const { form, handleSubmitWithAction, action } = useHookFormAction(
|
|
23
|
+
updateEmailAction,
|
|
24
|
+
zodResolver(updateEmailSchema),
|
|
25
|
+
{ formProps: { defaultValues: { email: currentEmail } } }
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<form onSubmit={handleSubmitWithAction}>
|
|
30
|
+
<Stack>
|
|
31
|
+
<TextInput
|
|
32
|
+
label="Email"
|
|
33
|
+
type="email"
|
|
34
|
+
required
|
|
35
|
+
withAsterisk={false}
|
|
36
|
+
{...form.register("email")}
|
|
37
|
+
error={form.formState.errors.email?.message}
|
|
38
|
+
/>
|
|
39
|
+
|
|
40
|
+
{action.result.data?.error ? (
|
|
41
|
+
<Text c="red">{action.result.data.error}</Text>
|
|
42
|
+
) : action.hasErrored ? (
|
|
43
|
+
<Text c="red">An error occured</Text>
|
|
44
|
+
) : null}
|
|
45
|
+
|
|
46
|
+
{form.formState.isDirty && (
|
|
47
|
+
<Group justify="end">
|
|
48
|
+
<Button type="submit" loading={action.isPending}>
|
|
49
|
+
Update Email
|
|
50
|
+
</Button>
|
|
51
|
+
</Group>
|
|
52
|
+
)}
|
|
53
|
+
</Stack>
|
|
54
|
+
</form>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useHookFormAction } from "@next-safe-action/adapter-react-hook-form/hooks";
|
|
3
|
+
import { updatePasswordSchema } from "./schema";
|
|
4
|
+
import { updatePasswordAction } from "./actions";
|
|
5
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
6
|
+
import {
|
|
7
|
+
Anchor,
|
|
8
|
+
Button,
|
|
9
|
+
Group,
|
|
10
|
+
Paper,
|
|
11
|
+
PasswordInput,
|
|
12
|
+
Text,
|
|
13
|
+
} from "@mantine/core";
|
|
14
|
+
import { TextInput } from "@mantine/core";
|
|
15
|
+
import { Stack } from "@mantine/core";
|
|
16
|
+
import { useState } from "react";
|
|
17
|
+
import { showSuccessNotification } from "@/utils/notification-helpers";
|
|
18
|
+
|
|
19
|
+
export default function UpdatePasswordForm() {
|
|
20
|
+
const [showForm, setShowForm] = useState(false);
|
|
21
|
+
const { form, handleSubmitWithAction, action } = useHookFormAction(
|
|
22
|
+
updatePasswordAction,
|
|
23
|
+
zodResolver(updatePasswordSchema),
|
|
24
|
+
{
|
|
25
|
+
formProps: { defaultValues: {} },
|
|
26
|
+
actionProps: {
|
|
27
|
+
onSuccess: ({ data }) => {
|
|
28
|
+
if (data?.message) {
|
|
29
|
+
showSuccessNotification(data.message);
|
|
30
|
+
setShowForm(false);
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
if (!showForm) {
|
|
38
|
+
return (
|
|
39
|
+
<Group>
|
|
40
|
+
<TextInput
|
|
41
|
+
variant="subtle"
|
|
42
|
+
label="Password"
|
|
43
|
+
style={{ flexGrow: 1 }}
|
|
44
|
+
value="••••••••"
|
|
45
|
+
readOnly
|
|
46
|
+
/>
|
|
47
|
+
<Button
|
|
48
|
+
size="sm"
|
|
49
|
+
variant="subtle"
|
|
50
|
+
color="gray"
|
|
51
|
+
onClick={() => setShowForm(true)}
|
|
52
|
+
>
|
|
53
|
+
Update
|
|
54
|
+
</Button>
|
|
55
|
+
</Group>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<form onSubmit={handleSubmitWithAction}>
|
|
61
|
+
<Stack>
|
|
62
|
+
<PasswordInput
|
|
63
|
+
label="Current Password"
|
|
64
|
+
type="password"
|
|
65
|
+
autoComplete="current-password"
|
|
66
|
+
required
|
|
67
|
+
withAsterisk={false}
|
|
68
|
+
{...form.register("currentPassword")}
|
|
69
|
+
error={form.formState.errors.currentPassword?.message}
|
|
70
|
+
/>
|
|
71
|
+
|
|
72
|
+
<PasswordInput
|
|
73
|
+
label="New Password"
|
|
74
|
+
type="password"
|
|
75
|
+
required
|
|
76
|
+
withAsterisk={false}
|
|
77
|
+
{...form.register("newPassword")}
|
|
78
|
+
error={form.formState.errors.newPassword?.message}
|
|
79
|
+
autoComplete="new-password"
|
|
80
|
+
/>
|
|
81
|
+
|
|
82
|
+
<PasswordInput
|
|
83
|
+
label="Confirm New Password"
|
|
84
|
+
type="password"
|
|
85
|
+
required
|
|
86
|
+
autoComplete="new-password"
|
|
87
|
+
withAsterisk={false}
|
|
88
|
+
{...form.register("confirmNewPassword")}
|
|
89
|
+
/>
|
|
90
|
+
|
|
91
|
+
{action.result.data?.error ? (
|
|
92
|
+
<Text c="red">{action.result.data.error}</Text>
|
|
93
|
+
) : action.hasErrored ? (
|
|
94
|
+
<Text c="red">An error occured</Text>
|
|
95
|
+
) : null}
|
|
96
|
+
|
|
97
|
+
<Group justify="end">
|
|
98
|
+
<Button
|
|
99
|
+
type="submit"
|
|
100
|
+
variant="light"
|
|
101
|
+
disabled={!form.formState.isDirty}
|
|
102
|
+
loading={action.isPending}
|
|
103
|
+
>
|
|
104
|
+
Update Password
|
|
105
|
+
</Button>
|
|
106
|
+
</Group>
|
|
107
|
+
</Stack>
|
|
108
|
+
</form>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
|
|
3
|
+
export const updateEmailSchema = z.object({
|
|
4
|
+
email: z.string().email(),
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
export const updatePasswordSchema = z
|
|
8
|
+
.object({
|
|
9
|
+
currentPassword: z.string(),
|
|
10
|
+
newPassword: z
|
|
11
|
+
.string()
|
|
12
|
+
.min(8, { message: "Password must be at least 8 characters long" })
|
|
13
|
+
.max(255, { message: "Password is too long" }),
|
|
14
|
+
confirmNewPassword: z.string(),
|
|
15
|
+
})
|
|
16
|
+
.refine((data) => data.newPassword === data.confirmNewPassword, {
|
|
17
|
+
path: ["confirmNewPassword"],
|
|
18
|
+
message: "Passwords do not match",
|
|
19
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
import { actionClient } from "@/server/safe-action";
|
|
3
|
+
import { forgotPasswordSchema } from "./schema";
|
|
4
|
+
import { getUserFromEmail } from "@/server/auth/utils/user";
|
|
5
|
+
import { generateSessionToken } from "@/server/auth/utils/session";
|
|
6
|
+
import { redirect } from "next/navigation";
|
|
7
|
+
import {
|
|
8
|
+
createPasswordResetSession,
|
|
9
|
+
invalidateUserPasswordResetSessions,
|
|
10
|
+
sendPasswordResetEmail,
|
|
11
|
+
setPasswordResetSessionTokenCookie,
|
|
12
|
+
} from "@/server/auth/utils/password-reset";
|
|
13
|
+
|
|
14
|
+
export const forgotPasswordAction = actionClient
|
|
15
|
+
.schema(forgotPasswordSchema)
|
|
16
|
+
.action(async ({ parsedInput }) => {
|
|
17
|
+
const { email } = parsedInput;
|
|
18
|
+
|
|
19
|
+
const user = await getUserFromEmail(email);
|
|
20
|
+
if (user === null) {
|
|
21
|
+
return {
|
|
22
|
+
error: "Account does not exist",
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
await invalidateUserPasswordResetSessions(user.id);
|
|
27
|
+
const sessionToken = generateSessionToken();
|
|
28
|
+
const session = await createPasswordResetSession(
|
|
29
|
+
sessionToken,
|
|
30
|
+
user.id,
|
|
31
|
+
user.email
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
await sendPasswordResetEmail(session.email, session.code);
|
|
35
|
+
await setPasswordResetSessionTokenCookie(sessionToken, session.expires_at);
|
|
36
|
+
return redirect("/auth/reset-password/verify-email");
|
|
37
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useHookFormAction } from "@next-safe-action/adapter-react-hook-form/hooks";
|
|
4
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
5
|
+
import { TextInput, Button, Stack, Paper, Text } from "@mantine/core";
|
|
6
|
+
import { forgotPasswordAction } from "./actions";
|
|
7
|
+
import { forgotPasswordSchema } from "./schema";
|
|
8
|
+
|
|
9
|
+
export default function ForgotForm() {
|
|
10
|
+
const { form, handleSubmitWithAction, action } = useHookFormAction(
|
|
11
|
+
forgotPasswordAction,
|
|
12
|
+
zodResolver(forgotPasswordSchema),
|
|
13
|
+
{}
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<form onSubmit={handleSubmitWithAction}>
|
|
18
|
+
<Paper withBorder shadow="md" p={30} mt={30} radius="md">
|
|
19
|
+
<Stack>
|
|
20
|
+
<TextInput
|
|
21
|
+
autoFocus
|
|
22
|
+
label="Email"
|
|
23
|
+
placeholder="you@proofkit.dev"
|
|
24
|
+
required
|
|
25
|
+
withAsterisk={false}
|
|
26
|
+
{...form.register("email")}
|
|
27
|
+
error={form.formState.errors.email?.message}
|
|
28
|
+
/>
|
|
29
|
+
|
|
30
|
+
{action.result.data?.error && (
|
|
31
|
+
<Text c="red">{action.result.data.error}</Text>
|
|
32
|
+
)}
|
|
33
|
+
|
|
34
|
+
<Button fullWidth type="submit" loading={action.isPending}>
|
|
35
|
+
Send Reset Email
|
|
36
|
+
</Button>
|
|
37
|
+
</Stack>
|
|
38
|
+
</Paper>
|
|
39
|
+
</form>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Anchor, Container, Text, Title } from "@mantine/core";
|
|
2
|
+
import ForgotForm from "./forgot-form";
|
|
3
|
+
|
|
4
|
+
export default async function Page() {
|
|
5
|
+
return (
|
|
6
|
+
<Container size={420} my={40}>
|
|
7
|
+
<Title ta="center">Forgot Password</Title>
|
|
8
|
+
<Text c="dimmed" size="sm" ta="center" mt={5}>
|
|
9
|
+
Enter your email for a link to reset your password.
|
|
10
|
+
</Text>
|
|
11
|
+
|
|
12
|
+
<ForgotForm />
|
|
13
|
+
|
|
14
|
+
<Text ta="center" mt={10}>
|
|
15
|
+
<Anchor size="sm" component="a" href="/auth/login" c="dimmed">
|
|
16
|
+
Back to login
|
|
17
|
+
</Anchor>
|
|
18
|
+
</Text>
|
|
19
|
+
</Container>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
|
|
3
|
+
import { actionClient } from "@/server/safe-action";
|
|
4
|
+
import { loginSchema } from "./schema";
|
|
5
|
+
import { validateLogin } from "@/server/auth/utils/user";
|
|
6
|
+
import {
|
|
7
|
+
createSession,
|
|
8
|
+
generateSessionToken,
|
|
9
|
+
setSessionTokenCookie,
|
|
10
|
+
} from "@/server/auth/utils/session";
|
|
11
|
+
import { redirect } from "next/navigation";
|
|
12
|
+
import { getRedirectCookie } from "@/server/auth/utils/redirect";
|
|
13
|
+
|
|
14
|
+
export const loginAction = actionClient
|
|
15
|
+
.schema(loginSchema)
|
|
16
|
+
.action(async ({ parsedInput }) => {
|
|
17
|
+
const { email, password } = parsedInput;
|
|
18
|
+
const user = await validateLogin(email, password);
|
|
19
|
+
|
|
20
|
+
if (user === null) {
|
|
21
|
+
return { error: "Invalid email or password" };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const sessionToken = generateSessionToken();
|
|
25
|
+
const session = await createSession(sessionToken, user.id);
|
|
26
|
+
setSessionTokenCookie(sessionToken, session.expiresAt);
|
|
27
|
+
|
|
28
|
+
if (!user.emailVerified) {
|
|
29
|
+
return redirect("/auth/verify-email");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const redirectTo = await getRedirectCookie();
|
|
33
|
+
return redirect(redirectTo);
|
|
34
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useHookFormAction } from "@next-safe-action/adapter-react-hook-form/hooks";
|
|
3
|
+
import { loginSchema } from "./schema";
|
|
4
|
+
import { loginAction } from "./actions";
|
|
5
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
6
|
+
import {
|
|
7
|
+
Anchor,
|
|
8
|
+
Button,
|
|
9
|
+
Group,
|
|
10
|
+
Paper,
|
|
11
|
+
PasswordInput,
|
|
12
|
+
Text,
|
|
13
|
+
} from "@mantine/core";
|
|
14
|
+
import { TextInput } from "@mantine/core";
|
|
15
|
+
import { Stack } from "@mantine/core";
|
|
16
|
+
|
|
17
|
+
export default function LoginForm() {
|
|
18
|
+
const { form, handleSubmitWithAction, action } = useHookFormAction(
|
|
19
|
+
loginAction,
|
|
20
|
+
zodResolver(loginSchema),
|
|
21
|
+
{}
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<form onSubmit={handleSubmitWithAction}>
|
|
26
|
+
<Paper withBorder shadow="md" p={30} mt={30} radius="md">
|
|
27
|
+
<Stack>
|
|
28
|
+
<TextInput
|
|
29
|
+
autoFocus
|
|
30
|
+
label="Email"
|
|
31
|
+
placeholder="you@proofkit.dev"
|
|
32
|
+
required
|
|
33
|
+
withAsterisk={false}
|
|
34
|
+
{...form.register("email")}
|
|
35
|
+
error={form.formState.errors.email?.message}
|
|
36
|
+
/>
|
|
37
|
+
<PasswordInput
|
|
38
|
+
label="Password"
|
|
39
|
+
placeholder="Your password"
|
|
40
|
+
autoComplete="current-password"
|
|
41
|
+
required
|
|
42
|
+
withAsterisk={false}
|
|
43
|
+
{...form.register("password")}
|
|
44
|
+
error={form.formState.errors.password?.message}
|
|
45
|
+
/>
|
|
46
|
+
|
|
47
|
+
<Group justify="end">
|
|
48
|
+
<Anchor size="sm" component="a" href="/auth/forgot-password">
|
|
49
|
+
Forgot password?
|
|
50
|
+
</Anchor>
|
|
51
|
+
</Group>
|
|
52
|
+
{action.result.data?.error ? (
|
|
53
|
+
<Text c="red">{action.result.data.error}</Text>
|
|
54
|
+
) : action.hasErrored ? (
|
|
55
|
+
<Text c="red">An error occured</Text>
|
|
56
|
+
) : null}
|
|
57
|
+
<Button fullWidth type="submit" loading={action.isPending}>
|
|
58
|
+
Sign in
|
|
59
|
+
</Button>
|
|
60
|
+
</Stack>
|
|
61
|
+
</Paper>
|
|
62
|
+
</form>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { getCurrentSession } from "@/server/auth/utils/session";
|
|
2
|
+
import { Anchor, Container, Text, Title } from "@mantine/core";
|
|
3
|
+
import { redirect } from "next/navigation";
|
|
4
|
+
import LoginForm from "./login-form";
|
|
5
|
+
|
|
6
|
+
export default async function Page() {
|
|
7
|
+
const { session } = await getCurrentSession();
|
|
8
|
+
|
|
9
|
+
if (session !== null) {
|
|
10
|
+
return redirect("/");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<Container size={420} my={40}>
|
|
15
|
+
<Title ta="center">Welcome back!</Title>
|
|
16
|
+
<Text c="dimmed" size="sm" ta="center" mt={5}>
|
|
17
|
+
Do not have an account yet?{" "}
|
|
18
|
+
<Anchor size="sm" component="a" href="/auth/signup">
|
|
19
|
+
Create account
|
|
20
|
+
</Anchor>
|
|
21
|
+
</Text>
|
|
22
|
+
|
|
23
|
+
<LoginForm />
|
|
24
|
+
</Container>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
|
|
3
|
+
import { actionClient } from "@/server/safe-action";
|
|
4
|
+
import { resetPasswordSchema } from "./schema";
|
|
5
|
+
import {
|
|
6
|
+
deletePasswordResetSessionTokenCookie,
|
|
7
|
+
invalidateUserPasswordResetSessions,
|
|
8
|
+
} from "@/server/auth/utils/password-reset";
|
|
9
|
+
import { validatePasswordResetSessionRequest } from "@/server/auth/utils/password-reset";
|
|
10
|
+
import { createSession } from "@/server/auth/utils/session";
|
|
11
|
+
import { generateSessionToken } from "@/server/auth/utils/session";
|
|
12
|
+
import { setSessionTokenCookie } from "@/server/auth/utils/session";
|
|
13
|
+
import { verifyPasswordStrength } from "@/server/auth/utils/password";
|
|
14
|
+
import { invalidateUserSessions } from "@/server/auth/utils/session";
|
|
15
|
+
import { updateUserPassword } from "@/server/auth/utils/user";
|
|
16
|
+
import { redirect } from "next/navigation";
|
|
17
|
+
|
|
18
|
+
export const resetPasswordAction = actionClient
|
|
19
|
+
.schema(resetPasswordSchema)
|
|
20
|
+
.action(async ({ parsedInput }) => {
|
|
21
|
+
const { password } = parsedInput;
|
|
22
|
+
const { session: passwordResetSession, user } =
|
|
23
|
+
await validatePasswordResetSessionRequest();
|
|
24
|
+
if (passwordResetSession === null) {
|
|
25
|
+
return {
|
|
26
|
+
error: "Not authenticated",
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
if (!passwordResetSession.email_verified) {
|
|
30
|
+
return {
|
|
31
|
+
error: "Forbidden",
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const strongPassword = await verifyPasswordStrength(password);
|
|
36
|
+
if (!strongPassword) {
|
|
37
|
+
return {
|
|
38
|
+
error: "Weak password",
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
await invalidateUserPasswordResetSessions(passwordResetSession.id_user);
|
|
42
|
+
await invalidateUserSessions(passwordResetSession.id_user);
|
|
43
|
+
await updateUserPassword(passwordResetSession.id_user, password);
|
|
44
|
+
|
|
45
|
+
const sessionToken = generateSessionToken();
|
|
46
|
+
const session = await createSession(sessionToken, user.id);
|
|
47
|
+
await setSessionTokenCookie(sessionToken, session.expiresAt);
|
|
48
|
+
await deletePasswordResetSessionTokenCookie();
|
|
49
|
+
return redirect("/");
|
|
50
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Alert, Anchor, Container, Text, Title } from "@mantine/core";
|
|
2
|
+
import ResetPasswordForm from "./reset-password-form";
|
|
3
|
+
import { env } from "@/config/env";
|
|
4
|
+
import { validatePasswordResetSessionRequest } from "@/server/auth/utils/password-reset";
|
|
5
|
+
import { redirect } from "next/navigation";
|
|
6
|
+
|
|
7
|
+
export default async function Page() {
|
|
8
|
+
const { session, user } = await validatePasswordResetSessionRequest();
|
|
9
|
+
if (session === null) {
|
|
10
|
+
return redirect("/auth/forgot-password");
|
|
11
|
+
}
|
|
12
|
+
if (!session.email_verified) {
|
|
13
|
+
return redirect("/auth/reset-password/verify-email");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<Container size={420} my={40}>
|
|
18
|
+
<Title ta="center">Reset Password</Title>
|
|
19
|
+
<Text c="dimmed" size="sm" ta="center" mt={5}>
|
|
20
|
+
Enter your new password.
|
|
21
|
+
</Text>
|
|
22
|
+
|
|
23
|
+
<ResetPasswordForm />
|
|
24
|
+
|
|
25
|
+
<Text ta="center" mt={10}>
|
|
26
|
+
<Anchor size="sm" component="a" href="/auth/login" c="dimmed">
|
|
27
|
+
Back to login
|
|
28
|
+
</Anchor>
|
|
29
|
+
</Text>
|
|
30
|
+
</Container>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useHookFormAction } from "@next-safe-action/adapter-react-hook-form/hooks";
|
|
4
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
5
|
+
import {
|
|
6
|
+
TextInput,
|
|
7
|
+
Button,
|
|
8
|
+
Stack,
|
|
9
|
+
Paper,
|
|
10
|
+
Text,
|
|
11
|
+
PasswordInput,
|
|
12
|
+
} from "@mantine/core";
|
|
13
|
+
import { resetPasswordAction } from "./actions";
|
|
14
|
+
import { resetPasswordSchema } from "./schema";
|
|
15
|
+
|
|
16
|
+
export default function ForgotForm() {
|
|
17
|
+
const { form, handleSubmitWithAction, action } = useHookFormAction(
|
|
18
|
+
resetPasswordAction,
|
|
19
|
+
zodResolver(resetPasswordSchema),
|
|
20
|
+
{}
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<form onSubmit={handleSubmitWithAction}>
|
|
25
|
+
<Paper withBorder shadow="md" p={30} mt={30} radius="md">
|
|
26
|
+
<Stack>
|
|
27
|
+
<PasswordInput
|
|
28
|
+
autoFocus
|
|
29
|
+
label="Password"
|
|
30
|
+
required
|
|
31
|
+
withAsterisk={false}
|
|
32
|
+
{...form.register("password")}
|
|
33
|
+
error={form.formState.errors.password?.message}
|
|
34
|
+
autoComplete="new-password"
|
|
35
|
+
/>
|
|
36
|
+
|
|
37
|
+
<PasswordInput
|
|
38
|
+
label="Confirm Password"
|
|
39
|
+
required
|
|
40
|
+
withAsterisk={false}
|
|
41
|
+
{...form.register("confirmPassword")}
|
|
42
|
+
error={form.formState.errors.confirmPassword?.message}
|
|
43
|
+
autoComplete="new-password"
|
|
44
|
+
/>
|
|
45
|
+
|
|
46
|
+
{action.result.data?.error ? (
|
|
47
|
+
<Text c="red">{action.result.data.error}</Text>
|
|
48
|
+
) : action.hasErrored ? (
|
|
49
|
+
<Text c="red">An error occured</Text>
|
|
50
|
+
) : null}
|
|
51
|
+
|
|
52
|
+
<Button fullWidth type="submit" loading={action.isPending}>
|
|
53
|
+
Reset Password
|
|
54
|
+
</Button>
|
|
55
|
+
</Stack>
|
|
56
|
+
</Paper>
|
|
57
|
+
</form>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
|
|
3
|
+
export const resetPasswordSchema = z
|
|
4
|
+
.object({
|
|
5
|
+
password: z
|
|
6
|
+
.string()
|
|
7
|
+
.min(8, { message: "Your password should be at least 8 characters" })
|
|
8
|
+
.max(255, { message: "Password is too long" }),
|
|
9
|
+
confirmPassword: z.string(),
|
|
10
|
+
})
|
|
11
|
+
.refine((data) => data.password === data.confirmPassword, {
|
|
12
|
+
path: ["confirmPassword"],
|
|
13
|
+
message: "Passwords do not match",
|
|
14
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
|
|
3
|
+
import { actionClient } from "@/server/safe-action";
|
|
4
|
+
import { verifyEmailSchema } from "./schema";
|
|
5
|
+
import {
|
|
6
|
+
setPasswordResetSessionAsEmailVerified,
|
|
7
|
+
validatePasswordResetSessionRequest,
|
|
8
|
+
} from "@/server/auth/utils/password-reset";
|
|
9
|
+
import { setUserAsEmailVerifiedIfEmailMatches } from "@/server/auth/utils/user";
|
|
10
|
+
import { redirect } from "next/navigation";
|
|
11
|
+
|
|
12
|
+
export const verifyEmailAction = actionClient
|
|
13
|
+
.schema(verifyEmailSchema)
|
|
14
|
+
.action(async ({ parsedInput }) => {
|
|
15
|
+
const { session } = await validatePasswordResetSessionRequest();
|
|
16
|
+
if (session === null) {
|
|
17
|
+
return {
|
|
18
|
+
error: "Not authenticated",
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
if (Boolean(session.email_verified)) {
|
|
22
|
+
return {
|
|
23
|
+
error: "Forbidden",
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const { code } = parsedInput;
|
|
28
|
+
|
|
29
|
+
if (code !== session.code) {
|
|
30
|
+
return {
|
|
31
|
+
error: "Incorrect code",
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
await setPasswordResetSessionAsEmailVerified(session.id);
|
|
35
|
+
const emailMatches = await setUserAsEmailVerifiedIfEmailMatches(
|
|
36
|
+
session.id_user,
|
|
37
|
+
session.email
|
|
38
|
+
);
|
|
39
|
+
if (!emailMatches) {
|
|
40
|
+
return {
|
|
41
|
+
error: "Please restart the process",
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return redirect("/auth/reset-password");
|
|
45
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Alert, Anchor, Container, Text, Title } from "@mantine/core";
|
|
2
|
+
import VerifyEmailForm from "./verify-email-form";
|
|
3
|
+
import { env } from "@/config/env";
|
|
4
|
+
import { validatePasswordResetSessionRequest } from "@/server/auth/utils/password-reset";
|
|
5
|
+
import { redirect } from "next/navigation";
|
|
6
|
+
|
|
7
|
+
export default async function Page() {
|
|
8
|
+
const { session } = await validatePasswordResetSessionRequest();
|
|
9
|
+
if (session === null) {
|
|
10
|
+
return redirect("/auth/forgot-password");
|
|
11
|
+
}
|
|
12
|
+
if (session.email_verified) {
|
|
13
|
+
return redirect("/auth/reset-password");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<Container size={420} my={40}>
|
|
18
|
+
<Title ta="center">Verify Email</Title>
|
|
19
|
+
<Text c="dimmed" size="sm" ta="center" mt={5}>
|
|
20
|
+
Enter the code sent to your email.
|
|
21
|
+
</Text>
|
|
22
|
+
|
|
23
|
+
<VerifyEmailForm />
|
|
24
|
+
|
|
25
|
+
<Text ta="center" mt={10}>
|
|
26
|
+
<Anchor size="sm" component="a" href="/auth/login" c="dimmed">
|
|
27
|
+
Back to login
|
|
28
|
+
</Anchor>
|
|
29
|
+
</Text>
|
|
30
|
+
</Container>
|
|
31
|
+
);
|
|
32
|
+
}
|