@baseplate-dev/plugin-auth 0.6.17 → 0.6.19
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 +54 -0
- package/dist/better-auth/admin/generators/admin-crud-manage-roles-action/admin-crud-manage-roles-action.generator.d.ts +74 -0
- package/dist/better-auth/admin/generators/admin-crud-manage-roles-action/generated/index.d.ts +74 -0
- package/dist/better-auth/admin/generators/admin-crud-manage-roles-action/generated/template-renderers.d.ts +37 -0
- package/dist/better-auth/admin/generators/admin-crud-manage-roles-action/generated/typed-templates.d.ts +37 -0
- package/dist/better-auth/admin/generators/admin-crud-manage-roles-action/templates/routes/-components/role-manager-dialog.js +1 -2
- package/dist/better-auth/admin/generators/admin-crud-manage-roles-action/templates/routes/-components/role-manager-dialog.tsx +1 -1
- package/dist/better-auth/admin/generators/admin-crud-reset-password-action/admin-crud-reset-password-action.generator.d.ts +74 -0
- package/dist/better-auth/admin/generators/admin-crud-reset-password-action/generated/index.d.ts +74 -0
- package/dist/better-auth/admin/generators/admin-crud-reset-password-action/generated/template-renderers.d.ts +37 -0
- package/dist/better-auth/admin/generators/admin-crud-reset-password-action/generated/typed-templates.d.ts +74 -0
- package/dist/better-auth/admin/generators/admin-crud-reset-password-action/templates/routes/-components/password-reset-dialog.js +1 -2
- package/dist/better-auth/admin/generators/admin-crud-reset-password-action/templates/routes/-components/password-reset-dialog.tsx +1 -1
- package/dist/better-auth/admin/generators/admin-crud-roles-column/admin-crud-roles-column.generator.d.ts +37 -0
- package/dist/better-auth/core/node.js +7 -8
- package/dist/better-auth/generators/fastify/better-auth-admin-module/generated/index.d.ts +1 -0
- package/dist/better-auth/generators/fastify/better-auth-admin-module/generated/ts-import-providers.d.ts +1 -0
- package/dist/better-auth/generators/fastify/better-auth-admin-module/generated/ts-import-providers.js +1 -0
- package/dist/better-auth/generators/fastify/better-auth-module/better-auth-module.generator.d.ts +20 -3
- package/dist/better-auth/generators/fastify/better-auth-module/better-auth-module.generator.js +5 -24
- package/dist/better-auth/generators/fastify/better-auth-module/generated/index.d.ts +40 -2
- package/dist/better-auth/generators/fastify/better-auth-module/generated/template-renderers.d.ts +19 -1
- package/dist/better-auth/generators/fastify/better-auth-module/generated/template-renderers.js +6 -2
- package/dist/better-auth/generators/fastify/better-auth-module/generated/ts-import-providers.d.ts +1 -0
- package/dist/better-auth/generators/fastify/better-auth-module/generated/ts-import-providers.js +1 -0
- package/dist/better-auth/generators/fastify/better-auth-module/generated/typed-templates.d.ts +20 -1
- package/dist/better-auth/generators/fastify/better-auth-module/generated/typed-templates.js +4 -1
- package/dist/better-auth/generators/fastify/better-auth-module/templates/module/services/auth.ts +16 -8
- package/dist/better-auth/generators/react/better-auth-hooks/better-auth-hooks.generator.d.ts +1 -1
- package/dist/better-auth/generators/react/better-auth-hooks/generated/index.d.ts +5 -4
- package/dist/better-auth/generators/react/better-auth-hooks/generated/template-paths.d.ts +1 -1
- package/dist/better-auth/generators/react/better-auth-hooks/generated/template-paths.js +1 -1
- package/dist/better-auth/generators/react/better-auth-hooks/generated/ts-import-providers.d.ts +2 -1
- package/dist/better-auth/generators/react/better-auth-hooks/generated/ts-import-providers.js +2 -1
- package/dist/better-auth/generators/react/better-auth-hooks/generated/typed-templates.d.ts +6 -6
- package/dist/better-auth/generators/react/better-auth-hooks/generated/typed-templates.js +13 -13
- package/dist/better-auth/generators/react/better-auth-hooks/templates/src/hooks/{use-required-user-id.ts → use-user-id-or-throw.ts} +1 -1
- package/dist/better-auth/generators/react/better-auth-pages/better-auth-pages.generator.d.ts +37 -0
- package/dist/better-auth/generators/react/better-auth-pages/generated/index.d.ts +222 -0
- package/dist/better-auth/generators/react/better-auth-pages/generated/template-renderers.d.ts +37 -0
- package/dist/better-auth/generators/react/better-auth-pages/generated/typed-templates.d.ts +370 -0
- package/dist/better-auth/generators/react/better-auth-pages/templates/routes/forgot-password.tsx +1 -4
- package/dist/better-auth/generators/react/react-better-auth/generated/index.d.ts +77 -2
- package/dist/better-auth/generators/react/react-better-auth/generated/template-renderers.d.ts +38 -1
- package/dist/better-auth/generators/react/react-better-auth/generated/ts-import-providers.d.ts +1 -0
- package/dist/better-auth/generators/react/react-better-auth/generated/ts-import-providers.js +1 -0
- package/dist/better-auth/generators/react/react-better-auth/generated/typed-templates.d.ts +38 -1
- package/dist/better-auth/generators/react/react-better-auth/react-better-auth.generator.d.ts +38 -1
- package/dist/better-auth/generators/react/react-better-auth/templates/src/app/auth-loaded-gate.tsx +12 -3
- package/dist/local-auth/admin/common.js +6 -0
- package/dist/local-auth/admin/generators/admin-crud-invite-user-action/admin-crud-invite-user-action.generator.d.ts +593 -0
- package/dist/local-auth/admin/generators/admin-crud-invite-user-action/admin-crud-invite-user-action.generator.js +119 -0
- package/dist/local-auth/admin/generators/admin-crud-invite-user-action/generated/index.d.ts +602 -0
- package/dist/local-auth/admin/generators/admin-crud-invite-user-action/generated/index.js +11 -0
- package/dist/local-auth/admin/generators/admin-crud-invite-user-action/generated/template-paths.d.ts +12 -0
- package/dist/local-auth/admin/generators/admin-crud-invite-user-action/generated/template-paths.js +24 -0
- package/dist/local-auth/admin/generators/admin-crud-invite-user-action/generated/template-renderers.d.ts +307 -0
- package/dist/local-auth/admin/generators/admin-crud-invite-user-action/generated/template-renderers.js +45 -0
- package/dist/local-auth/admin/generators/admin-crud-invite-user-action/generated/typed-templates.d.ts +294 -0
- package/dist/local-auth/admin/generators/admin-crud-invite-user-action/generated/typed-templates.js +21 -0
- package/dist/local-auth/admin/generators/admin-crud-invite-user-action/index.d.ts +2 -0
- package/dist/local-auth/admin/generators/admin-crud-invite-user-action/index.js +2 -0
- package/dist/local-auth/admin/generators/admin-crud-invite-user-action/templates/routes/-components/invite-user-dialog.d.ts +21 -0
- package/dist/local-auth/admin/generators/admin-crud-invite-user-action/templates/routes/-components/invite-user-dialog.js +68 -0
- package/dist/local-auth/admin/generators/admin-crud-invite-user-action/templates/routes/-components/invite-user-dialog.tsx +122 -0
- package/dist/local-auth/admin/generators/admin-crud-manage-roles-action/admin-crud-manage-roles-action.generator.d.ts +74 -0
- package/dist/local-auth/admin/generators/admin-crud-manage-roles-action/generated/index.d.ts +74 -0
- package/dist/local-auth/admin/generators/admin-crud-manage-roles-action/generated/template-renderers.d.ts +37 -0
- package/dist/local-auth/admin/generators/admin-crud-manage-roles-action/generated/typed-templates.d.ts +37 -0
- package/dist/local-auth/admin/generators/admin-crud-manage-roles-action/templates/routes/-components/role-manager-dialog.js +1 -2
- package/dist/local-auth/admin/generators/admin-crud-manage-roles-action/templates/routes/-components/role-manager-dialog.tsx +1 -1
- package/dist/local-auth/admin/generators/admin-crud-reset-password-action/admin-crud-reset-password-action.generator.d.ts +74 -0
- package/dist/local-auth/admin/generators/admin-crud-reset-password-action/generated/index.d.ts +74 -0
- package/dist/local-auth/admin/generators/admin-crud-reset-password-action/generated/template-renderers.d.ts +37 -0
- package/dist/local-auth/admin/generators/admin-crud-reset-password-action/generated/typed-templates.d.ts +74 -0
- package/dist/local-auth/admin/generators/admin-crud-reset-password-action/templates/routes/-components/password-reset-dialog.js +1 -2
- package/dist/local-auth/admin/generators/admin-crud-reset-password-action/templates/routes/-components/password-reset-dialog.tsx +1 -1
- package/dist/local-auth/admin/generators/admin-crud-roles-column/admin-crud-roles-column.generator.d.ts +37 -0
- package/dist/local-auth/admin/node.js +13 -0
- package/dist/local-auth/admin/schema/invite-user-action.d.ts +12 -0
- package/dist/local-auth/admin/schema/invite-user-action.js +6 -0
- package/dist/local-auth/admin/web.js +8 -0
- package/dist/local-auth/core/common.js +7 -2
- package/dist/local-auth/core/components/local-auth-definition-editor.js +2 -1
- package/dist/local-auth/core/components/local-auth-web-app-settings-form.d.ts +9 -0
- package/dist/local-auth/core/components/local-auth-web-app-settings-form.js +11 -0
- package/dist/local-auth/core/generators/auth-email-password/auth-email-password.generator.d.ts +16 -7
- package/dist/local-auth/core/generators/auth-email-password/auth-email-password.generator.js +73 -16
- package/dist/local-auth/core/generators/auth-email-password/generated/index.d.ts +222 -7
- package/dist/local-auth/core/generators/auth-email-password/generated/template-paths.d.ts +5 -0
- package/dist/local-auth/core/generators/auth-email-password/generated/template-paths.js +5 -0
- package/dist/local-auth/core/generators/auth-email-password/generated/template-renderers.d.ts +27 -0
- package/dist/local-auth/core/generators/auth-email-password/generated/template-renderers.js +71 -4
- package/dist/local-auth/core/generators/auth-email-password/generated/ts-import-providers.d.ts +1 -3
- package/dist/local-auth/core/generators/auth-email-password/generated/ts-import-providers.js +1 -2
- package/dist/local-auth/core/generators/auth-email-password/generated/typed-templates.d.ts +226 -10
- package/dist/local-auth/core/generators/auth-email-password/generated/typed-templates.js +91 -7
- package/dist/local-auth/core/generators/auth-email-password/templates/module/constants/otp.constants.d.ts +19 -0
- package/dist/local-auth/core/generators/auth-email-password/templates/module/constants/otp.constants.js +20 -0
- package/dist/local-auth/core/generators/auth-email-password/templates/module/constants/otp.constants.ts +22 -0
- package/dist/local-auth/core/generators/auth-email-password/templates/module/constants/password.constants.d.ts +12 -0
- package/dist/local-auth/core/generators/auth-email-password/templates/module/constants/password.constants.js +12 -0
- package/dist/local-auth/core/generators/auth-email-password/templates/module/constants/password.constants.ts +14 -0
- package/dist/local-auth/core/generators/auth-email-password/templates/module/schema/email-otp.mutations.d.ts +2 -0
- package/dist/local-auth/core/generators/auth-email-password/templates/module/schema/email-otp.mutations.js +30 -0
- package/dist/local-auth/core/generators/auth-email-password/templates/module/schema/email-otp.mutations.ts +38 -0
- package/dist/local-auth/core/generators/auth-email-password/templates/module/schema/invite.mutations.d.ts +2 -0
- package/dist/local-auth/core/generators/auth-email-password/templates/module/schema/invite.mutations.js +42 -0
- package/dist/local-auth/core/generators/auth-email-password/templates/module/schema/invite.mutations.ts +54 -0
- package/dist/local-auth/core/generators/auth-email-password/templates/module/schema/user-password.mutations.js +2 -19
- package/dist/local-auth/core/generators/auth-email-password/templates/module/schema/user-password.mutations.ts +1 -22
- package/dist/local-auth/core/generators/auth-email-password/templates/module/services/email-otp.service.d.ts +37 -0
- package/dist/local-auth/core/generators/auth-email-password/templates/module/services/email-otp.service.js +225 -0
- package/dist/local-auth/core/generators/auth-email-password/templates/module/services/email-otp.service.ts +333 -0
- package/dist/local-auth/core/generators/auth-email-password/templates/module/services/email-verification.service.js +2 -3
- package/dist/local-auth/core/generators/auth-email-password/templates/module/services/email-verification.service.ts +5 -3
- package/dist/local-auth/core/generators/auth-email-password/templates/module/services/invite.service.d.ts +39 -0
- package/dist/local-auth/core/generators/auth-email-password/templates/module/services/invite.service.js +142 -0
- package/dist/local-auth/core/generators/auth-email-password/templates/module/services/invite.service.ts +221 -0
- package/dist/local-auth/core/generators/auth-email-password/templates/module/services/password-reset.service.js +5 -6
- package/dist/local-auth/core/generators/auth-email-password/templates/module/services/password-reset.service.ts +8 -5
- package/dist/local-auth/core/generators/auth-email-templates/auth-email-templates.generator.d.ts +3 -1
- package/dist/local-auth/core/generators/auth-email-templates/auth-email-templates.generator.js +18 -3
- package/dist/local-auth/core/generators/auth-email-templates/generated/index.d.ts +40 -0
- package/dist/local-auth/core/generators/auth-email-templates/generated/template-paths.d.ts +2 -0
- package/dist/local-auth/core/generators/auth-email-templates/generated/template-paths.js +2 -0
- package/dist/local-auth/core/generators/auth-email-templates/generated/template-renderers.d.ts +6 -0
- package/dist/local-auth/core/generators/auth-email-templates/generated/template-renderers.js +20 -0
- package/dist/local-auth/core/generators/auth-email-templates/generated/typed-templates.d.ts +40 -0
- package/dist/local-auth/core/generators/auth-email-templates/generated/typed-templates.js +24 -0
- package/dist/local-auth/core/generators/auth-email-templates/templates/src/emails/auth/email-otp.email.d.ts +3 -0
- package/dist/local-auth/core/generators/auth-email-templates/templates/src/emails/auth/email-otp.email.js +18 -0
- package/dist/local-auth/core/generators/auth-email-templates/templates/src/emails/auth/email-otp.email.tsx +57 -0
- package/dist/local-auth/core/generators/auth-email-templates/templates/src/emails/auth/invite.email.d.ts +3 -0
- package/dist/local-auth/core/generators/auth-email-templates/templates/src/emails/auth/invite.email.js +14 -0
- package/dist/local-auth/core/generators/auth-email-templates/templates/src/emails/auth/invite.email.tsx +47 -0
- package/dist/local-auth/core/generators/auth-hooks/auth-hooks.generator.d.ts +272 -1
- package/dist/local-auth/core/generators/auth-hooks/generated/index.d.ts +547 -4
- package/dist/local-auth/core/generators/auth-hooks/generated/template-paths.d.ts +1 -1
- package/dist/local-auth/core/generators/auth-hooks/generated/template-paths.js +1 -1
- package/dist/local-auth/core/generators/auth-hooks/generated/template-renderers.d.ts +271 -0
- package/dist/local-auth/core/generators/auth-hooks/generated/template-renderers.js +4 -2
- package/dist/local-auth/core/generators/auth-hooks/generated/ts-import-providers.d.ts +2 -1
- package/dist/local-auth/core/generators/auth-hooks/generated/ts-import-providers.js +2 -1
- package/dist/local-auth/core/generators/auth-hooks/generated/typed-templates.d.ts +548 -6
- package/dist/local-auth/core/generators/auth-hooks/generated/typed-templates.js +15 -14
- package/dist/local-auth/core/generators/auth-hooks/templates/src/hooks/use-log-out.js +1 -1
- package/dist/local-auth/core/generators/auth-hooks/templates/src/hooks/use-log-out.ts +1 -1
- package/dist/local-auth/core/generators/auth-hooks/templates/src/hooks/use-session.d.ts +7 -0
- package/dist/local-auth/core/generators/auth-hooks/templates/src/hooks/use-session.ts +7 -0
- package/dist/local-auth/core/generators/auth-module/auth-module.generator.d.ts +23 -7
- package/dist/local-auth/core/generators/auth-module/auth-module.generator.js +7 -26
- package/dist/local-auth/core/generators/auth-module/generated/index.d.ts +65 -4
- package/dist/local-auth/core/generators/auth-module/generated/template-paths.d.ts +1 -1
- package/dist/local-auth/core/generators/auth-module/generated/template-paths.js +1 -1
- package/dist/local-auth/core/generators/auth-module/generated/template-renderers.d.ts +22 -1
- package/dist/local-auth/core/generators/auth-module/generated/template-renderers.js +19 -2
- package/dist/local-auth/core/generators/auth-module/generated/ts-import-providers.d.ts +10 -0
- package/dist/local-auth/core/generators/auth-module/generated/ts-import-providers.js +7 -0
- package/dist/local-auth/core/generators/auth-module/generated/typed-templates.d.ts +42 -4
- package/dist/local-auth/core/generators/auth-module/generated/typed-templates.js +24 -13
- package/dist/local-auth/core/generators/auth-module/templates/module/services/auth-verification.service.d.ts +4 -0
- package/dist/local-auth/core/generators/auth-module/templates/module/services/auth-verification.service.js +1 -1
- package/dist/local-auth/core/generators/auth-module/templates/module/services/auth-verification.service.ts +1 -1
- package/dist/local-auth/core/generators/auth-module/templates/module/services/code-verification.service.d.ts +67 -0
- package/dist/local-auth/core/generators/auth-module/templates/module/services/code-verification.service.js +140 -0
- package/dist/local-auth/core/generators/auth-module/templates/module/services/code-verification.service.ts +191 -0
- package/dist/local-auth/core/generators/auth-module/templates/module/services/user-session.service.js +8 -9
- package/dist/local-auth/core/generators/auth-module/templates/module/services/user-session.service.ts +10 -11
- package/dist/local-auth/core/generators/auth-routes/auth-routes.generator.d.ts +39 -0
- package/dist/local-auth/core/generators/auth-routes/auth-routes.generator.js +38 -5
- package/dist/local-auth/core/generators/auth-routes/generated/index.d.ts +1089 -268
- package/dist/local-auth/core/generators/auth-routes/generated/template-paths.d.ts +3 -0
- package/dist/local-auth/core/generators/auth-routes/generated/template-paths.js +3 -0
- package/dist/local-auth/core/generators/auth-routes/generated/template-renderers.d.ts +49 -0
- package/dist/local-auth/core/generators/auth-routes/generated/template-renderers.js +51 -0
- package/dist/local-auth/core/generators/auth-routes/generated/ts-import-providers.d.ts +1 -0
- package/dist/local-auth/core/generators/auth-routes/generated/ts-import-providers.js +1 -0
- package/dist/local-auth/core/generators/auth-routes/generated/typed-templates.d.ts +918 -283
- package/dist/local-auth/core/generators/auth-routes/generated/typed-templates.js +69 -23
- package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/-otp-constants.d.ts +9 -0
- package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/-otp-constants.js +10 -0
- package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/-otp-constants.ts +11 -0
- package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/accept-invite.d.ts +7 -0
- package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/accept-invite.js +155 -0
- package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/accept-invite.tsx +274 -0
- package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/forgot-password.js +1 -2
- package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/forgot-password.tsx +1 -1
- package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/login-otp.d.ts +7 -0
- package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/login-otp.js +184 -0
- package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/login-otp.tsx +312 -0
- package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/login.js +5 -5
- package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/login.tsx +6 -12
- package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/register.js +4 -4
- package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/register.tsx +4 -3
- package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/reset-password.js +1 -2
- package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/reset-password.tsx +1 -1
- package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/verify-email.js +1 -2
- package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/verify-email.tsx +1 -1
- package/dist/local-auth/core/generators/react-session/generated/index.d.ts +90 -7
- package/dist/local-auth/core/generators/react-session/generated/template-renderers.d.ts +38 -1
- package/dist/local-auth/core/generators/react-session/generated/ts-import-providers.d.ts +1 -0
- package/dist/local-auth/core/generators/react-session/generated/ts-import-providers.js +1 -0
- package/dist/local-auth/core/generators/react-session/generated/typed-templates.d.ts +102 -12
- package/dist/local-auth/core/generators/react-session/generated/typed-templates.js +5 -2
- package/dist/local-auth/core/generators/react-session/react-session.generator.d.ts +54 -1
- package/dist/local-auth/core/generators/react-session/react-session.generator.js +35 -1
- package/dist/local-auth/core/generators/react-session/templates/src/app/user-session-provider.js +17 -44
- package/dist/local-auth/core/generators/react-session/templates/src/app/user-session-provider.tsx +21 -49
- package/dist/local-auth/core/generators/react-session/templates/src/services/user-session-client.d.ts +43 -34
- package/dist/local-auth/core/generators/react-session/templates/src/services/user-session-client.js +96 -80
- package/dist/local-auth/core/generators/react-session/templates/src/services/user-session-client.ts +148 -82
- package/dist/local-auth/core/generators/seed-initial-user/generated/index.d.ts +0 -2
- package/dist/local-auth/core/generators/seed-initial-user/generated/template-renderers.d.ts +0 -1
- package/dist/local-auth/core/generators/seed-initial-user/generated/typed-templates.d.ts +0 -1
- package/dist/local-auth/core/generators/seed-initial-user/seed-initial-user.generator.d.ts +0 -1
- package/dist/local-auth/core/node.js +30 -12
- package/dist/local-auth/core/schema/migrations.d.ts +3 -0
- package/dist/local-auth/core/schema/migrations.js +36 -0
- package/dist/local-auth/core/schema/models.js +8 -0
- package/dist/local-auth/core/schema/plugin-definition.d.ts +1 -0
- package/dist/local-auth/core/schema/plugin-definition.js +1 -0
- package/dist/local-auth/core/schema/web-app-schema.d.ts +15 -0
- package/dist/local-auth/core/schema/web-app-schema.js +16 -0
- package/dist/local-auth/core/web.js +8 -1
- package/dist/placeholder-auth/core/generators/placeholder-auth-hooks/generated/index.d.ts +4 -3
- package/dist/placeholder-auth/core/generators/placeholder-auth-hooks/generated/template-paths.d.ts +1 -1
- package/dist/placeholder-auth/core/generators/placeholder-auth-hooks/generated/template-paths.js +1 -1
- package/dist/placeholder-auth/core/generators/placeholder-auth-hooks/generated/ts-import-providers.d.ts +2 -1
- package/dist/placeholder-auth/core/generators/placeholder-auth-hooks/generated/ts-import-providers.js +2 -1
- package/dist/placeholder-auth/core/generators/placeholder-auth-hooks/generated/typed-templates.d.ts +4 -4
- package/dist/placeholder-auth/core/generators/placeholder-auth-hooks/generated/typed-templates.js +13 -13
- package/dist/placeholder-auth/core/generators/placeholder-auth-hooks/placeholder-auth-hooks.generator.d.ts +1 -1
- package/dist/placeholder-auth/core/generators/placeholder-auth-hooks/templates/src/hooks/use-session.d.ts +1 -0
- package/dist/placeholder-auth/core/generators/placeholder-auth-hooks/templates/src/hooks/use-session.ts +2 -0
- package/dist/placeholder-auth/core/generators/placeholder-auth-module/generated/index.d.ts +1 -2
- package/dist/placeholder-auth/core/generators/placeholder-auth-module/generated/template-renderers.d.ts +0 -1
- package/dist/placeholder-auth/core/generators/placeholder-auth-module/generated/ts-import-providers.d.ts +1 -0
- package/dist/placeholder-auth/core/generators/placeholder-auth-module/generated/ts-import-providers.js +1 -0
- package/dist/placeholder-auth/core/generators/placeholder-auth-module/generated/typed-templates.d.ts +0 -1
- package/dist/placeholder-auth/core/generators/placeholder-auth-module/placeholder-auth-module.generator.d.ts +0 -1
- package/dist/web/assets/{_virtual_mf-localSharedImportMap___mfe_internal__plugin_mf_2_auth-ChkXxpXe.js → _virtual_mf-localSharedImportMap___mfe_internal__plugin_mf_2_auth__mf_owner__1-DUupKqD4.js} +42 -34
- package/dist/web/assets/{dist-DY7ZXvq4.js → _virtual_mf___mfe_internal__plugin_mf_2_auth__mf_owner__1__loadShare___mf_0_baseplate_mf_2_dev_mf_1_project_mf_2_builder_mf_2_lib__loadShare__.js-DE4rTqEA.js} +16857 -381
- package/dist/web/assets/{_virtual_mf___mfe_internal__plugin_mf_2_auth__loadShare___mf_0_baseplate_mf_2_dev_mf_1_project_mf_2_builder_mf_2_lib_mf_1_web__loadShare__.js-37vlYRxk.js → _virtual_mf___mfe_internal__plugin_mf_2_auth__mf_owner__1__loadShare___mf_0_baseplate_mf_2_dev_mf_1_project_mf_2_builder_mf_2_lib_mf_1_web__loadShare__.js-mszeXpf-.js} +90 -38
- package/dist/web/assets/{_virtual_mf___mfe_internal__plugin_mf_2_auth__loadShare___mf_0_baseplate_mf_2_dev_mf_1_ui_mf_2_components__loadShare__.js-DRSNXPPo.js → _virtual_mf___mfe_internal__plugin_mf_2_auth__mf_owner__1__loadShare___mf_0_baseplate_mf_2_dev_mf_1_ui_mf_2_components__loadShare__.js-CtIleM_e.js} +4095 -2399
- package/dist/web/assets/{_virtual_mf___mfe_internal__plugin_mf_2_auth__loadShare___mf_0_tanstack_mf_1_react_mf_2_router__loadShare__.js-DfiQqvVC.js → _virtual_mf___mfe_internal__plugin_mf_2_auth__mf_owner__1__loadShare___mf_0_tanstack_mf_1_react_mf_2_router__loadShare__.js-BckLhSjF.js} +212 -57
- package/dist/web/assets/auth-DR6QxrAW.js +1 -0
- package/dist/web/assets/{common-iHaemino.js → common-BsyRiQi3.js} +6 -6
- package/dist/web/assets/{common-TDf_PrjX.js → common-CRwNlCMn.js} +10 -10
- package/dist/web/assets/{common-ByxS61u8.js → common-CvqlRZC9.js} +12 -12
- package/dist/web/assets/common-D3atSs7O.js +70 -0
- package/dist/web/assets/common-DuFyXa6l.js +36 -0
- package/dist/web/assets/common-islduJTj.js +43 -0
- package/dist/web/assets/{dist-CrLSslv6.js → dist-DQd1TAJX.js} +273 -132
- package/dist/web/assets/{get-auth-plugin-definition-kDCtXq_6.js → get-auth-plugin-definition-BgWWHl_Y.js} +3 -3
- package/dist/web/assets/{hostInit-Cruek6c6.js → hostInit-DNA4kLRY.js} +32 -5
- package/dist/web/assets/{mf-entry-bootstrap-0-dfed0275.js → mf-entry-bootstrap-0-ea77c09b.js} +2 -1
- package/dist/web/assets/{mf-entry-bootstrap-1-5275674a.js → mf-entry-bootstrap-1-9dee3d8d.js} +3 -2
- package/dist/web/assets/{mf-entry-bootstrap-2-39fb9255.js → mf-entry-bootstrap-2-3179040b.js} +3 -2
- package/dist/web/assets/{mf-entry-bootstrap-3-49e64336.js → mf-entry-bootstrap-3-370d200d.js} +3 -2
- package/dist/web/assets/{models-DSvs_3bA.js → models-BOeSYfRn.js} +4 -5
- package/dist/web/assets/{models-BZmCbizK.js → models-DF6DoXt6.js} +11 -6
- package/dist/web/assets/{plugin-definition-CYj29S3q.js → plugin-definition--k0VAeK3.js} +9 -10
- package/dist/web/assets/plugin-definition-CMwSlxsJ.js +10 -0
- package/dist/web/assets/{styles-yjbHBTlw.js → styles-BQEcQHoR.js} +9 -10
- package/dist/web/assets/{virtualExposes-CbPBmicF.js → virtualExposes-C7fDiAmS.js} +1 -1
- package/dist/web/assets/virtual_mf-REMOTE_ENTRY_ID___mfe_internal__plugin-auth__remoteEntry_js-BZBRyml2.js +747 -0
- package/dist/web/assets/{virtual_mf-exposes___mfe_internal__plugin-auth__remoteEntry_js-B6BXIeF1.js → virtual_mf-exposes___mfe_internal__plugin-auth__remoteEntry_js-6SjVUCs8.js} +13 -13
- package/dist/web/assets/web-8wz0ad-V.js +59 -0
- package/dist/web/assets/{web-CXAHKjIY.js → web-BGixH_gT.js} +27 -27
- package/dist/web/assets/{web-1eTcxMhf.js → web-BxIwkN3O.js} +6 -6
- package/dist/web/assets/{web-VqBA3jxZ.js → web-CQMfABjr.js} +24 -24
- package/dist/web/assets/{web-CDAKPPK9.js → web-CcNpItSu.js} +22 -22
- package/dist/web/assets/web-CypPeiVv.js +148 -0
- package/dist/web/assets/{web-D0MSKfyv.js → web-CzK_la2_.js} +53 -53
- package/dist/web/index.html +5 -5
- package/dist/web/remoteEntry.js +1 -1
- package/package.json +14 -14
- package/dist/local-auth/core/generators/auth-module/templates/module/utils/cookie-signer.d.ts +0 -38
- package/dist/local-auth/core/generators/auth-module/templates/module/utils/cookie-signer.js +0 -71
- package/dist/local-auth/core/generators/auth-module/templates/module/utils/cookie-signer.ts +0 -77
- package/dist/web/assets/_virtual_mf___mfe_internal__plugin_mf_2_auth__loadShare___mf_0_baseplate_mf_2_dev_mf_1_project_mf_2_builder_mf_2_lib__loadShare__.js-CO5Pvo0y.js +0 -384
- package/dist/web/assets/_virtual_mf___mfe_internal__plugin_mf_2_auth__loadShare__zod__loadShare__.js-BEZ7A-cz.js +0 -13566
- package/dist/web/assets/auth-BxAE0rgh.js +0 -1
- package/dist/web/assets/common-CKl_XlvH.js +0 -37
- package/dist/web/assets/common-UpVCKZeW.js +0 -41
- package/dist/web/assets/common-crSwCD36.js +0 -37
- package/dist/web/assets/model-utils-C0WDb_Ec.js +0 -1599
- package/dist/web/assets/plugin-definition-DOMmPL2Z.js +0 -11
- package/dist/web/assets/virtual_mf-REMOTE_ENTRY_ID___mfe_internal__plugin-auth__remoteEntry_js-XM6iYVxf.js +0 -259
- package/dist/web/assets/virtual_mf-exposes-ssr___mfe_internal__plugin-auth__remoteEntry_js-DGjg7Brm.js +0 -129
- package/dist/web/assets/web-DbeAaDTV.js +0 -118
- package/dist/web/assets/web-miDovYk_.js +0 -46
- package/dist/web/remoteEntry.ssr.js +0 -43
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
import { EMAIL_OTP_LENGTH, EMAIL_OTP_RESEND_COOLDOWN_SEC } from '$otpConstants';
|
|
4
|
+
import { getApolloErrorCode } from '%apolloErrorImports';
|
|
5
|
+
import { graphql } from '%graphqlImports';
|
|
6
|
+
import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, InputFieldController, InputOtpFieldController, toast, } from '%reactComponentsImports';
|
|
7
|
+
import { logAndFormatError, logError } from '%reactErrorImports';
|
|
8
|
+
import { userSessionClient } from '%reactSessionImports';
|
|
9
|
+
import { useMutation } from '@apollo/client/react';
|
|
10
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
11
|
+
import { createFileRoute, Link, redirect, useNavigate, } from '@tanstack/react-router';
|
|
12
|
+
import { useEffect, useState } from 'react';
|
|
13
|
+
import { useForm } from 'react-hook-form';
|
|
14
|
+
import { z } from 'zod';
|
|
15
|
+
export const Route = createFileRoute('/auth_/login-otp')({
|
|
16
|
+
validateSearch: z.object({
|
|
17
|
+
return_to: z
|
|
18
|
+
.string()
|
|
19
|
+
.refine((v) => v.startsWith('/') && !v.startsWith('//'))
|
|
20
|
+
.optional(),
|
|
21
|
+
}),
|
|
22
|
+
component: LoginOtpPage,
|
|
23
|
+
beforeLoad: ({ search: { return_to }, context: { userId } }) => {
|
|
24
|
+
if (userId) {
|
|
25
|
+
throw redirect({ to: return_to ?? '/' });
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
const emailSchema = z.object({
|
|
30
|
+
email: z
|
|
31
|
+
.email('Please enter a valid email address')
|
|
32
|
+
.transform((value) => value.toLowerCase()),
|
|
33
|
+
});
|
|
34
|
+
const codeSchema = z.object({
|
|
35
|
+
code: z
|
|
36
|
+
.string()
|
|
37
|
+
.length(EMAIL_OTP_LENGTH, `Enter the ${EMAIL_OTP_LENGTH}-digit code`),
|
|
38
|
+
name: z.string().max(100).optional(),
|
|
39
|
+
});
|
|
40
|
+
const requestEmailOtpMutation = graphql(`
|
|
41
|
+
mutation RequestEmailOtp($input: RequestEmailOtpInput!) {
|
|
42
|
+
requestEmailOtp(input: $input) {
|
|
43
|
+
success
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
`);
|
|
47
|
+
const signInWithEmailOtpMutation = graphql(`
|
|
48
|
+
mutation SignInWithEmailOtp($input: SignInWithEmailOtpInput!) {
|
|
49
|
+
signInWithEmailOtp(input: $input) {
|
|
50
|
+
session {
|
|
51
|
+
userId
|
|
52
|
+
roles
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
`);
|
|
57
|
+
function LoginOtpPage() {
|
|
58
|
+
const [sentToEmail, setSentToEmail] = useState();
|
|
59
|
+
// Set once the server reports the code is valid but the address is new and
|
|
60
|
+
// needs a name. Revealing the field any earlier would leak whether an
|
|
61
|
+
// account exists.
|
|
62
|
+
const [needsName, setNeedsName] = useState(false);
|
|
63
|
+
const [resendCooldown, setResendCooldown] = useState(0);
|
|
64
|
+
const navigate = useNavigate();
|
|
65
|
+
const { return_to } = Route.useSearch();
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (resendCooldown <= 0)
|
|
68
|
+
return;
|
|
69
|
+
const timer = setTimeout(() => {
|
|
70
|
+
setResendCooldown((seconds) => seconds - 1);
|
|
71
|
+
}, 1000);
|
|
72
|
+
return () => {
|
|
73
|
+
clearTimeout(timer);
|
|
74
|
+
};
|
|
75
|
+
}, [resendCooldown]);
|
|
76
|
+
const emailForm = useForm({
|
|
77
|
+
resolver: zodResolver(emailSchema),
|
|
78
|
+
reValidateMode: 'onBlur',
|
|
79
|
+
});
|
|
80
|
+
const codeForm = useForm({
|
|
81
|
+
resolver: zodResolver(codeSchema),
|
|
82
|
+
reValidateMode: 'onBlur',
|
|
83
|
+
});
|
|
84
|
+
const [requestEmailOtp, { loading: isRequesting }] = useMutation(requestEmailOtpMutation);
|
|
85
|
+
const [signInWithEmailOtp, { loading: isVerifying }] = useMutation(signInWithEmailOtpMutation);
|
|
86
|
+
const onRequestCode = ({ email }) => {
|
|
87
|
+
requestEmailOtp({ variables: { input: { email } } })
|
|
88
|
+
.then(() => {
|
|
89
|
+
setSentToEmail(email);
|
|
90
|
+
setResendCooldown(EMAIL_OTP_RESEND_COOLDOWN_SEC);
|
|
91
|
+
// Only the code is cleared: a resend keeps any name already collected
|
|
92
|
+
// so the user does not have to type it a second time.
|
|
93
|
+
codeForm.resetField('code');
|
|
94
|
+
})
|
|
95
|
+
.catch((err) => {
|
|
96
|
+
const errorCode = getApolloErrorCode(err, ['too-many-requests']);
|
|
97
|
+
if (errorCode === 'too-many-requests') {
|
|
98
|
+
const message = 'Too many sign-in code requests. Please try again later.';
|
|
99
|
+
// The email form is unmounted once a code has been sent, so a
|
|
100
|
+
// rate-limited resend has nowhere to show a field error.
|
|
101
|
+
if (sentToEmail) {
|
|
102
|
+
toast.error(message);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
emailForm.setError('email', { message });
|
|
106
|
+
}
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
toast.error(logAndFormatError(err, 'Sorry, we could not send you a code.'));
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
const onVerifyCode = ({ code, name }) => {
|
|
113
|
+
if (!sentToEmail)
|
|
114
|
+
return;
|
|
115
|
+
const trimmedName = name?.trim();
|
|
116
|
+
// Send a blank name as absent so the server answers with `name-required`
|
|
117
|
+
// rather than a validation error.
|
|
118
|
+
const nameInput = trimmedName ? trimmedName : undefined;
|
|
119
|
+
if (needsName && !nameInput) {
|
|
120
|
+
codeForm.setError('name', { message: 'Please enter your name' }, { shouldFocus: true });
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
signInWithEmailOtp({
|
|
124
|
+
variables: { input: { email: sentToEmail, code, name: nameInput } },
|
|
125
|
+
})
|
|
126
|
+
.then(({ data }) => {
|
|
127
|
+
if (!data) {
|
|
128
|
+
throw new Error('No data returned from sign-in mutation');
|
|
129
|
+
}
|
|
130
|
+
const { userId, roles } = data.signInWithEmailOtp.session;
|
|
131
|
+
userSessionClient.signIn(userId, roles);
|
|
132
|
+
navigate({ to: return_to ?? '/', replace: true }).catch(logError);
|
|
133
|
+
})
|
|
134
|
+
.catch((err) => {
|
|
135
|
+
const errorCode = getApolloErrorCode(err, [
|
|
136
|
+
'invalid-code',
|
|
137
|
+
'name-required',
|
|
138
|
+
'too-many-requests',
|
|
139
|
+
'verification-context-missing',
|
|
140
|
+
]);
|
|
141
|
+
switch (errorCode) {
|
|
142
|
+
case 'invalid-code': {
|
|
143
|
+
codeForm.setError('code', { message: 'That code is incorrect or has expired' }, { shouldFocus: true });
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
case 'verification-context-missing': {
|
|
147
|
+
codeForm.setError('code', {
|
|
148
|
+
message: 'Codes can only be used in the browser that requested them. Request a new one to continue.',
|
|
149
|
+
});
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
case 'name-required': {
|
|
153
|
+
// The code is still valid — collect a name and submit it again.
|
|
154
|
+
setNeedsName(true);
|
|
155
|
+
codeForm.setError('name', { message: 'Please enter your name' }, { shouldFocus: true });
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
case 'too-many-requests': {
|
|
159
|
+
codeForm.setError('code', {
|
|
160
|
+
message: 'Too many attempts. Please try again later.',
|
|
161
|
+
});
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
case null: {
|
|
165
|
+
toast.error(logAndFormatError(err, 'Sorry, we could not sign you in.'));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
return (_jsxs(Card, { children: [_jsxs(CardHeader, { children: [_jsxs(CardTitle, { children: [!sentToEmail && 'Sign in with a code', sentToEmail &&
|
|
171
|
+
(needsName ? 'Finish creating your account' : 'Enter your code')] }), _jsxs(CardDescription, { children: [!sentToEmail &&
|
|
172
|
+
`We'll email you a code so you can sign in without a password.`, sentToEmail &&
|
|
173
|
+
(needsName
|
|
174
|
+
? 'Your code checked out — tell us your name to finish setting up your account.'
|
|
175
|
+
: `We sent a ${EMAIL_OTP_LENGTH}-digit code to ${sentToEmail}.`)] })] }), _jsx(CardContent, { children: sentToEmail ? (_jsxs("form", { onSubmit: codeForm.handleSubmit(onVerifyCode), children: [_jsxs("div", { className: "flex flex-col items-center gap-4", children: [_jsx(InputOtpFieldController, { control: codeForm.control, name: "code", length: EMAIL_OTP_LENGTH }), needsName && (_jsx(InputFieldController, { control: codeForm.control, name: "name", label: "Your name", autoComplete: "name", className: "w-full" })), _jsx(Button, { type: "submit", className: "w-full", disabled: isVerifying, children: needsName ? 'Create account' : 'Sign in' })] }), _jsxs("div", { className: "mt-4 flex flex-col gap-4 text-center text-sm", children: [_jsx("button", { type: "button", className: "text-muted-foreground underline-offset-4 hover:underline disabled:no-underline disabled:opacity-70", disabled: resendCooldown > 0 || isRequesting, onClick: () => {
|
|
176
|
+
onRequestCode({ email: sentToEmail });
|
|
177
|
+
}, children: resendCooldown > 0
|
|
178
|
+
? `Resend code in ${resendCooldown}s`
|
|
179
|
+
: 'Resend code' }), _jsx("button", { type: "button", className: "text-muted-foreground underline-offset-4 hover:underline", onClick: () => {
|
|
180
|
+
setSentToEmail(undefined);
|
|
181
|
+
setNeedsName(false);
|
|
182
|
+
}, children: "Use a different email" })] })] })) : (_jsxs("form", { onSubmit: emailForm.handleSubmit(onRequestCode), children: [_jsxs("div", { className: "flex flex-col gap-4", children: [_jsx(InputFieldController, { control: emailForm.control, name: "email", type: "email", autoComplete: "email", placeholder: "user@example.com" }), _jsx(Button, { type: "submit", className: "w-full", disabled: isRequesting, children: "Email me a code" })] }), _jsx("div", { className: "mt-4 flex flex-col gap-4 text-center text-sm", children: _jsx(Link, { to: "/auth/login", search: { return_to }, className: "text-muted-foreground underline-offset-4 hover:underline", children: "Sign in with a password instead" }) })] })) })] }));
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=login-otp.js.map
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
|
|
3
|
+
import { EMAIL_OTP_LENGTH, EMAIL_OTP_RESEND_COOLDOWN_SEC } from '$otpConstants';
|
|
4
|
+
import { getApolloErrorCode } from '%apolloErrorImports';
|
|
5
|
+
import { graphql } from '%graphqlImports';
|
|
6
|
+
import {
|
|
7
|
+
Button,
|
|
8
|
+
Card,
|
|
9
|
+
CardContent,
|
|
10
|
+
CardDescription,
|
|
11
|
+
CardHeader,
|
|
12
|
+
CardTitle,
|
|
13
|
+
InputFieldController,
|
|
14
|
+
InputOtpFieldController,
|
|
15
|
+
toast,
|
|
16
|
+
} from '%reactComponentsImports';
|
|
17
|
+
import { logAndFormatError, logError } from '%reactErrorImports';
|
|
18
|
+
import { userSessionClient } from '%reactSessionImports';
|
|
19
|
+
import { useMutation } from '@apollo/client/react';
|
|
20
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
21
|
+
import {
|
|
22
|
+
createFileRoute,
|
|
23
|
+
Link,
|
|
24
|
+
redirect,
|
|
25
|
+
useNavigate,
|
|
26
|
+
} from '@tanstack/react-router';
|
|
27
|
+
import { useEffect, useState } from 'react';
|
|
28
|
+
import { useForm } from 'react-hook-form';
|
|
29
|
+
import { z } from 'zod';
|
|
30
|
+
|
|
31
|
+
export const Route = createFileRoute('/auth_/login-otp')({
|
|
32
|
+
validateSearch: z.object({
|
|
33
|
+
return_to: z
|
|
34
|
+
.string()
|
|
35
|
+
.refine((v) => v.startsWith('/') && !v.startsWith('//'))
|
|
36
|
+
.optional(),
|
|
37
|
+
}),
|
|
38
|
+
component: LoginOtpPage,
|
|
39
|
+
beforeLoad: ({ search: { return_to }, context: { userId } }) => {
|
|
40
|
+
if (userId) {
|
|
41
|
+
throw redirect({ to: return_to ?? '/' });
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const emailSchema = z.object({
|
|
47
|
+
email: z
|
|
48
|
+
.email('Please enter a valid email address')
|
|
49
|
+
.transform((value) => value.toLowerCase()),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const codeSchema = z.object({
|
|
53
|
+
code: z
|
|
54
|
+
.string()
|
|
55
|
+
.length(EMAIL_OTP_LENGTH, `Enter the ${EMAIL_OTP_LENGTH}-digit code`),
|
|
56
|
+
name: z.string().max(100).optional(),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
type EmailFormData = z.infer<typeof emailSchema>;
|
|
60
|
+
type CodeFormData = z.infer<typeof codeSchema>;
|
|
61
|
+
|
|
62
|
+
const requestEmailOtpMutation = graphql(`
|
|
63
|
+
mutation RequestEmailOtp($input: RequestEmailOtpInput!) {
|
|
64
|
+
requestEmailOtp(input: $input) {
|
|
65
|
+
success
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
`);
|
|
69
|
+
|
|
70
|
+
const signInWithEmailOtpMutation = graphql(`
|
|
71
|
+
mutation SignInWithEmailOtp($input: SignInWithEmailOtpInput!) {
|
|
72
|
+
signInWithEmailOtp(input: $input) {
|
|
73
|
+
session {
|
|
74
|
+
userId
|
|
75
|
+
roles
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
`);
|
|
80
|
+
|
|
81
|
+
function LoginOtpPage(): React.JSX.Element {
|
|
82
|
+
const [sentToEmail, setSentToEmail] = useState<string | undefined>();
|
|
83
|
+
// Set once the server reports the code is valid but the address is new and
|
|
84
|
+
// needs a name. Revealing the field any earlier would leak whether an
|
|
85
|
+
// account exists.
|
|
86
|
+
const [needsName, setNeedsName] = useState(false);
|
|
87
|
+
const [resendCooldown, setResendCooldown] = useState(0);
|
|
88
|
+
const navigate = useNavigate();
|
|
89
|
+
const { return_to } = Route.useSearch();
|
|
90
|
+
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
if (resendCooldown <= 0) return;
|
|
93
|
+
const timer = setTimeout(() => {
|
|
94
|
+
setResendCooldown((seconds) => seconds - 1);
|
|
95
|
+
}, 1000);
|
|
96
|
+
return () => {
|
|
97
|
+
clearTimeout(timer);
|
|
98
|
+
};
|
|
99
|
+
}, [resendCooldown]);
|
|
100
|
+
|
|
101
|
+
const emailForm = useForm<EmailFormData>({
|
|
102
|
+
resolver: zodResolver(emailSchema),
|
|
103
|
+
reValidateMode: 'onBlur',
|
|
104
|
+
});
|
|
105
|
+
const codeForm = useForm<CodeFormData>({
|
|
106
|
+
resolver: zodResolver(codeSchema),
|
|
107
|
+
reValidateMode: 'onBlur',
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const [requestEmailOtp, { loading: isRequesting }] = useMutation(
|
|
111
|
+
requestEmailOtpMutation,
|
|
112
|
+
);
|
|
113
|
+
const [signInWithEmailOtp, { loading: isVerifying }] = useMutation(
|
|
114
|
+
signInWithEmailOtpMutation,
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
const onRequestCode = ({ email }: EmailFormData): void => {
|
|
118
|
+
requestEmailOtp({ variables: { input: { email } } })
|
|
119
|
+
.then(() => {
|
|
120
|
+
setSentToEmail(email);
|
|
121
|
+
setResendCooldown(EMAIL_OTP_RESEND_COOLDOWN_SEC);
|
|
122
|
+
// Only the code is cleared: a resend keeps any name already collected
|
|
123
|
+
// so the user does not have to type it a second time.
|
|
124
|
+
codeForm.resetField('code');
|
|
125
|
+
})
|
|
126
|
+
.catch((err: unknown) => {
|
|
127
|
+
const errorCode = getApolloErrorCode(err, ['too-many-requests']);
|
|
128
|
+
if (errorCode === 'too-many-requests') {
|
|
129
|
+
const message =
|
|
130
|
+
'Too many sign-in code requests. Please try again later.';
|
|
131
|
+
// The email form is unmounted once a code has been sent, so a
|
|
132
|
+
// rate-limited resend has nowhere to show a field error.
|
|
133
|
+
if (sentToEmail) {
|
|
134
|
+
toast.error(message);
|
|
135
|
+
} else {
|
|
136
|
+
emailForm.setError('email', { message });
|
|
137
|
+
}
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
toast.error(
|
|
141
|
+
logAndFormatError(err, 'Sorry, we could not send you a code.'),
|
|
142
|
+
);
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const onVerifyCode = ({ code, name }: CodeFormData): void => {
|
|
147
|
+
if (!sentToEmail) return;
|
|
148
|
+
const trimmedName = name?.trim();
|
|
149
|
+
// Send a blank name as absent so the server answers with `name-required`
|
|
150
|
+
// rather than a validation error.
|
|
151
|
+
const nameInput = trimmedName ? trimmedName : undefined;
|
|
152
|
+
if (needsName && !nameInput) {
|
|
153
|
+
codeForm.setError(
|
|
154
|
+
'name',
|
|
155
|
+
{ message: 'Please enter your name' },
|
|
156
|
+
{ shouldFocus: true },
|
|
157
|
+
);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
signInWithEmailOtp({
|
|
161
|
+
variables: { input: { email: sentToEmail, code, name: nameInput } },
|
|
162
|
+
})
|
|
163
|
+
.then(({ data }) => {
|
|
164
|
+
if (!data) {
|
|
165
|
+
throw new Error('No data returned from sign-in mutation');
|
|
166
|
+
}
|
|
167
|
+
const { userId, roles } = data.signInWithEmailOtp.session;
|
|
168
|
+
userSessionClient.signIn(userId, roles);
|
|
169
|
+
|
|
170
|
+
navigate({ to: return_to ?? '/', replace: true }).catch(logError);
|
|
171
|
+
})
|
|
172
|
+
.catch((err: unknown) => {
|
|
173
|
+
const errorCode = getApolloErrorCode(err, [
|
|
174
|
+
'invalid-code',
|
|
175
|
+
'name-required',
|
|
176
|
+
'too-many-requests',
|
|
177
|
+
'verification-context-missing',
|
|
178
|
+
] as const);
|
|
179
|
+
switch (errorCode) {
|
|
180
|
+
case 'invalid-code': {
|
|
181
|
+
codeForm.setError(
|
|
182
|
+
'code',
|
|
183
|
+
{ message: 'That code is incorrect or has expired' },
|
|
184
|
+
{ shouldFocus: true },
|
|
185
|
+
);
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
case 'verification-context-missing': {
|
|
189
|
+
codeForm.setError('code', {
|
|
190
|
+
message:
|
|
191
|
+
'Codes can only be used in the browser that requested them. Request a new one to continue.',
|
|
192
|
+
});
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
case 'name-required': {
|
|
196
|
+
// The code is still valid — collect a name and submit it again.
|
|
197
|
+
setNeedsName(true);
|
|
198
|
+
codeForm.setError(
|
|
199
|
+
'name',
|
|
200
|
+
{ message: 'Please enter your name' },
|
|
201
|
+
{ shouldFocus: true },
|
|
202
|
+
);
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
case 'too-many-requests': {
|
|
206
|
+
codeForm.setError('code', {
|
|
207
|
+
message: 'Too many attempts. Please try again later.',
|
|
208
|
+
});
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
case null: {
|
|
212
|
+
toast.error(
|
|
213
|
+
logAndFormatError(err, 'Sorry, we could not sign you in.'),
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
return (
|
|
221
|
+
<Card>
|
|
222
|
+
<CardHeader>
|
|
223
|
+
<CardTitle>
|
|
224
|
+
{!sentToEmail && 'Sign in with a code'}
|
|
225
|
+
{sentToEmail &&
|
|
226
|
+
(needsName ? 'Finish creating your account' : 'Enter your code')}
|
|
227
|
+
</CardTitle>
|
|
228
|
+
<CardDescription>
|
|
229
|
+
{!sentToEmail &&
|
|
230
|
+
`We'll email you a code so you can sign in without a password.`}
|
|
231
|
+
{sentToEmail &&
|
|
232
|
+
(needsName
|
|
233
|
+
? 'Your code checked out — tell us your name to finish setting up your account.'
|
|
234
|
+
: `We sent a ${EMAIL_OTP_LENGTH}-digit code to ${sentToEmail}.`)}
|
|
235
|
+
</CardDescription>
|
|
236
|
+
</CardHeader>
|
|
237
|
+
<CardContent>
|
|
238
|
+
{sentToEmail ? (
|
|
239
|
+
<form onSubmit={codeForm.handleSubmit(onVerifyCode)}>
|
|
240
|
+
<div className="flex flex-col items-center gap-4">
|
|
241
|
+
<InputOtpFieldController
|
|
242
|
+
control={codeForm.control}
|
|
243
|
+
name="code"
|
|
244
|
+
length={EMAIL_OTP_LENGTH}
|
|
245
|
+
/>
|
|
246
|
+
{needsName && (
|
|
247
|
+
<InputFieldController
|
|
248
|
+
control={codeForm.control}
|
|
249
|
+
name="name"
|
|
250
|
+
label="Your name"
|
|
251
|
+
autoComplete="name"
|
|
252
|
+
className="w-full"
|
|
253
|
+
/>
|
|
254
|
+
)}
|
|
255
|
+
<Button type="submit" className="w-full" disabled={isVerifying}>
|
|
256
|
+
{needsName ? 'Create account' : 'Sign in'}
|
|
257
|
+
</Button>
|
|
258
|
+
</div>
|
|
259
|
+
<div className="mt-4 flex flex-col gap-4 text-center text-sm">
|
|
260
|
+
<button
|
|
261
|
+
type="button"
|
|
262
|
+
className="text-muted-foreground underline-offset-4 hover:underline disabled:no-underline disabled:opacity-70"
|
|
263
|
+
disabled={resendCooldown > 0 || isRequesting}
|
|
264
|
+
onClick={() => {
|
|
265
|
+
onRequestCode({ email: sentToEmail });
|
|
266
|
+
}}
|
|
267
|
+
>
|
|
268
|
+
{resendCooldown > 0
|
|
269
|
+
? `Resend code in ${resendCooldown}s`
|
|
270
|
+
: 'Resend code'}
|
|
271
|
+
</button>
|
|
272
|
+
<button
|
|
273
|
+
type="button"
|
|
274
|
+
className="text-muted-foreground underline-offset-4 hover:underline"
|
|
275
|
+
onClick={() => {
|
|
276
|
+
setSentToEmail(undefined);
|
|
277
|
+
setNeedsName(false);
|
|
278
|
+
}}
|
|
279
|
+
>
|
|
280
|
+
Use a different email
|
|
281
|
+
</button>
|
|
282
|
+
</div>
|
|
283
|
+
</form>
|
|
284
|
+
) : (
|
|
285
|
+
<form onSubmit={emailForm.handleSubmit(onRequestCode)}>
|
|
286
|
+
<div className="flex flex-col gap-4">
|
|
287
|
+
<InputFieldController
|
|
288
|
+
control={emailForm.control}
|
|
289
|
+
name="email"
|
|
290
|
+
type="email"
|
|
291
|
+
autoComplete="email"
|
|
292
|
+
placeholder="user@example.com"
|
|
293
|
+
/>
|
|
294
|
+
<Button type="submit" className="w-full" disabled={isRequesting}>
|
|
295
|
+
Email me a code
|
|
296
|
+
</Button>
|
|
297
|
+
</div>
|
|
298
|
+
<div className="mt-4 flex flex-col gap-4 text-center text-sm">
|
|
299
|
+
<Link
|
|
300
|
+
to="/auth/login"
|
|
301
|
+
search={{ return_to }}
|
|
302
|
+
className="text-muted-foreground underline-offset-4 hover:underline"
|
|
303
|
+
>
|
|
304
|
+
Sign in with a password instead
|
|
305
|
+
</Link>
|
|
306
|
+
</div>
|
|
307
|
+
</form>
|
|
308
|
+
)}
|
|
309
|
+
</CardContent>
|
|
310
|
+
</Card>
|
|
311
|
+
);
|
|
312
|
+
}
|
|
@@ -3,14 +3,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { PASSWORD_MAX_LENGTH, PASSWORD_MIN_LENGTH } from '$constants';
|
|
4
4
|
import { getApolloErrorCode } from '%apolloErrorImports';
|
|
5
5
|
import { graphql } from '%graphqlImports';
|
|
6
|
-
import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, InputFieldController, } from '%reactComponentsImports';
|
|
6
|
+
import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, InputFieldController, toast, } from '%reactComponentsImports';
|
|
7
7
|
import { logAndFormatError, logError } from '%reactErrorImports';
|
|
8
8
|
import { userSessionClient } from '%reactSessionImports';
|
|
9
9
|
import { useMutation } from '@apollo/client/react';
|
|
10
10
|
import { zodResolver } from '@hookform/resolvers/zod';
|
|
11
11
|
import { createFileRoute, Link, redirect, useNavigate, } from '@tanstack/react-router';
|
|
12
12
|
import { useForm } from 'react-hook-form';
|
|
13
|
-
import { toast } from 'sonner';
|
|
14
13
|
import { z } from 'zod';
|
|
15
14
|
export const Route = createFileRoute('/auth_/login')({
|
|
16
15
|
validateSearch: z.object({
|
|
@@ -40,6 +39,7 @@ const loginWithEmailPasswordMutation = graphql(`
|
|
|
40
39
|
loginWithEmailPassword(input: $input) {
|
|
41
40
|
session {
|
|
42
41
|
userId
|
|
42
|
+
roles
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -65,8 +65,8 @@ function LoginPage() {
|
|
|
65
65
|
if (!data) {
|
|
66
66
|
throw new Error('No data returned from login mutation');
|
|
67
67
|
}
|
|
68
|
-
const { userId } = data.loginWithEmailPassword.session;
|
|
69
|
-
userSessionClient.signIn(userId);
|
|
68
|
+
const { userId, roles } = data.loginWithEmailPassword.session;
|
|
69
|
+
userSessionClient.signIn(userId, roles);
|
|
70
70
|
navigate({ to: return_to ?? '/', replace: true }).catch(logError);
|
|
71
71
|
})
|
|
72
72
|
.catch((err) => {
|
|
@@ -95,6 +95,6 @@ function LoginPage() {
|
|
|
95
95
|
}
|
|
96
96
|
});
|
|
97
97
|
};
|
|
98
|
-
return (_jsxs(Card, { children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { children: "Login to your account" }), _jsx(CardDescription, { children: "Enter your email below to login to your account" })] }), _jsx(CardContent, { children: _jsxs("form", { onSubmit: handleSubmit(onSubmit), children: [_jsxs("div", { className: "flex flex-col gap-4", children: [_jsx(InputFieldController, { control: control, name: "email", type: "email", autoComplete: "email", placeholder: "user@example.com" }), _jsx(InputFieldController, { control: control, name: "password", type: "password", autoComplete: "current-password", placeholder: "Password" }), _jsx(Button, { type: "submit", className: "w-full", disabled: loading, children: "Login" })] }), _jsxs("div", { className: "mt-4 flex flex-col gap-4 text-center text-sm", children: [_jsx(Link, { to: "/auth/forgot-password", className: "text-muted-foreground underline-offset-4 hover:underline", children: "Forgot your password?" }),
|
|
98
|
+
return (_jsxs(Card, { children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { children: "Login to your account" }), _jsx(CardDescription, { children: "Enter your email below to login to your account" })] }), _jsx(CardContent, { children: _jsxs("form", { onSubmit: handleSubmit(onSubmit), children: [_jsxs("div", { className: "flex flex-col gap-4", children: [_jsx(InputFieldController, { control: control, name: "email", type: "email", autoComplete: "email", placeholder: "user@example.com" }), _jsx(InputFieldController, { control: control, name: "password", type: "password", autoComplete: "current-password", placeholder: "Password" }), _jsx(Button, { type: "submit", className: "w-full", disabled: loading, children: "Login" })] }), _jsxs("div", { className: "mt-4 flex flex-col gap-4 text-center text-sm", children: [_jsx(TPL_OTP_LOGIN_LINK, {}), _jsx(Link, { to: "/auth/forgot-password", className: "text-muted-foreground underline-offset-4 hover:underline", children: "Forgot your password?" }), _jsx(TPL_REGISTER_LINK, {})] })] }) })] }));
|
|
99
99
|
}
|
|
100
100
|
//# sourceMappingURL=login.js.map
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
CardHeader,
|
|
12
12
|
CardTitle,
|
|
13
13
|
InputFieldController,
|
|
14
|
+
toast,
|
|
14
15
|
} from '%reactComponentsImports';
|
|
15
16
|
import { logAndFormatError, logError } from '%reactErrorImports';
|
|
16
17
|
import { userSessionClient } from '%reactSessionImports';
|
|
@@ -23,7 +24,6 @@ import {
|
|
|
23
24
|
useNavigate,
|
|
24
25
|
} from '@tanstack/react-router';
|
|
25
26
|
import { useForm } from 'react-hook-form';
|
|
26
|
-
import { toast } from 'sonner';
|
|
27
27
|
import { z } from 'zod';
|
|
28
28
|
|
|
29
29
|
export const Route = createFileRoute('/auth_/login')({
|
|
@@ -61,6 +61,7 @@ const loginWithEmailPasswordMutation = graphql(`
|
|
|
61
61
|
loginWithEmailPassword(input: $input) {
|
|
62
62
|
session {
|
|
63
63
|
userId
|
|
64
|
+
roles
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
67
|
}
|
|
@@ -95,8 +96,8 @@ function LoginPage(): React.JSX.Element {
|
|
|
95
96
|
if (!data) {
|
|
96
97
|
throw new Error('No data returned from login mutation');
|
|
97
98
|
}
|
|
98
|
-
const { userId } = data.loginWithEmailPassword.session;
|
|
99
|
-
userSessionClient.signIn(userId);
|
|
99
|
+
const { userId, roles } = data.loginWithEmailPassword.session;
|
|
100
|
+
userSessionClient.signIn(userId, roles);
|
|
100
101
|
|
|
101
102
|
navigate({ to: return_to ?? '/', replace: true }).catch(logError);
|
|
102
103
|
})
|
|
@@ -164,21 +165,14 @@ function LoginPage(): React.JSX.Element {
|
|
|
164
165
|
</Button>
|
|
165
166
|
</div>
|
|
166
167
|
<div className="mt-4 flex flex-col gap-4 text-center text-sm">
|
|
168
|
+
<TPL_OTP_LOGIN_LINK />
|
|
167
169
|
<Link
|
|
168
170
|
to="/auth/forgot-password"
|
|
169
171
|
className="text-muted-foreground underline-offset-4 hover:underline"
|
|
170
172
|
>
|
|
171
173
|
Forgot your password?
|
|
172
174
|
</Link>
|
|
173
|
-
<
|
|
174
|
-
Don't have an account?{' '}
|
|
175
|
-
<Link
|
|
176
|
-
to="/auth/register"
|
|
177
|
-
className="underline underline-offset-4"
|
|
178
|
-
>
|
|
179
|
-
Sign up
|
|
180
|
-
</Link>
|
|
181
|
-
</div>
|
|
175
|
+
<TPL_REGISTER_LINK />
|
|
182
176
|
</div>
|
|
183
177
|
</form>
|
|
184
178
|
</CardContent>
|
|
@@ -2,14 +2,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
// @ts-nocheck
|
|
3
3
|
import { getApolloErrorCode } from '%apolloErrorImports';
|
|
4
4
|
import { graphql } from '%graphqlImports';
|
|
5
|
-
import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, InputFieldController, } from '%reactComponentsImports';
|
|
5
|
+
import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, InputFieldController, toast, } from '%reactComponentsImports';
|
|
6
6
|
import { logAndFormatError, logError } from '%reactErrorImports';
|
|
7
7
|
import { userSessionClient } from '%reactSessionImports';
|
|
8
8
|
import { useMutation } from '@apollo/client/react';
|
|
9
9
|
import { zodResolver } from '@hookform/resolvers/zod';
|
|
10
10
|
import { createFileRoute, Link, redirect, useNavigate, } from '@tanstack/react-router';
|
|
11
11
|
import { useForm } from 'react-hook-form';
|
|
12
|
-
import { toast } from 'sonner';
|
|
13
12
|
import { z } from 'zod';
|
|
14
13
|
export const Route = createFileRoute('/auth_/register')({
|
|
15
14
|
validateSearch: z.object({
|
|
@@ -31,6 +30,7 @@ const registerWithEmailPasswordMutation = graphql(`
|
|
|
31
30
|
registerWithEmailPassword(input: $input) {
|
|
32
31
|
session {
|
|
33
32
|
userId
|
|
33
|
+
roles
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -53,8 +53,8 @@ function RegisterPage() {
|
|
|
53
53
|
if (!data) {
|
|
54
54
|
throw new Error('No data returned from login mutation');
|
|
55
55
|
}
|
|
56
|
-
const { userId } = data.registerWithEmailPassword.session;
|
|
57
|
-
userSessionClient.signIn(userId);
|
|
56
|
+
const { userId, roles } = data.registerWithEmailPassword.session;
|
|
57
|
+
userSessionClient.signIn(userId, roles);
|
|
58
58
|
navigate({ to: return_to ?? '/', replace: true }).catch(logError);
|
|
59
59
|
})
|
|
60
60
|
.catch((err) => {
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
CardHeader,
|
|
11
11
|
CardTitle,
|
|
12
12
|
InputFieldController,
|
|
13
|
+
toast,
|
|
13
14
|
} from '%reactComponentsImports';
|
|
14
15
|
import { logAndFormatError, logError } from '%reactErrorImports';
|
|
15
16
|
import { userSessionClient } from '%reactSessionImports';
|
|
@@ -22,7 +23,6 @@ import {
|
|
|
22
23
|
useNavigate,
|
|
23
24
|
} from '@tanstack/react-router';
|
|
24
25
|
import { useForm } from 'react-hook-form';
|
|
25
|
-
import { toast } from 'sonner';
|
|
26
26
|
import { z } from 'zod';
|
|
27
27
|
|
|
28
28
|
export const Route = createFileRoute('/auth_/register')({
|
|
@@ -49,6 +49,7 @@ const registerWithEmailPasswordMutation = graphql(`
|
|
|
49
49
|
registerWithEmailPassword(input: $input) {
|
|
50
50
|
session {
|
|
51
51
|
userId
|
|
52
|
+
roles
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
}
|
|
@@ -79,8 +80,8 @@ function RegisterPage(): React.JSX.Element {
|
|
|
79
80
|
if (!data) {
|
|
80
81
|
throw new Error('No data returned from login mutation');
|
|
81
82
|
}
|
|
82
|
-
const { userId } = data.registerWithEmailPassword.session;
|
|
83
|
-
userSessionClient.signIn(userId);
|
|
83
|
+
const { userId, roles } = data.registerWithEmailPassword.session;
|
|
84
|
+
userSessionClient.signIn(userId, roles);
|
|
84
85
|
|
|
85
86
|
navigate({ to: return_to ?? '/', replace: true }).catch(logError);
|
|
86
87
|
})
|