@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
|
@@ -23,8 +23,8 @@ export declare const reactSessionGenerator: import("@baseplate-dev/sync").Genera
|
|
|
23
23
|
isTypeOnly: true;
|
|
24
24
|
};
|
|
25
25
|
useLogOut: {};
|
|
26
|
-
useRequiredUserId: {};
|
|
27
26
|
useSession: {};
|
|
27
|
+
useUserIdOrThrow: {};
|
|
28
28
|
AuthRole: {
|
|
29
29
|
isTypeOnly: true;
|
|
30
30
|
};
|
|
@@ -46,6 +46,7 @@ export declare const reactSessionGenerator: import("@baseplate-dev/sync").Genera
|
|
|
46
46
|
isTypeOnly: true;
|
|
47
47
|
};
|
|
48
48
|
Alert: {};
|
|
49
|
+
AlertAction: {};
|
|
49
50
|
AlertDescription: {};
|
|
50
51
|
AlertTitle: {};
|
|
51
52
|
Autocomplete: {};
|
|
@@ -75,6 +76,7 @@ export declare const reactSessionGenerator: import("@baseplate-dev/sync").Genera
|
|
|
75
76
|
buttonVariants: {};
|
|
76
77
|
Calendar: {};
|
|
77
78
|
Card: {};
|
|
79
|
+
CardAction: {};
|
|
78
80
|
CardContent: {};
|
|
79
81
|
CardDescription: {};
|
|
80
82
|
CardFooter: {};
|
|
@@ -159,6 +161,12 @@ export declare const reactSessionGenerator: import("@baseplate-dev/sync").Genera
|
|
|
159
161
|
InputGroupInput: {};
|
|
160
162
|
InputGroupText: {};
|
|
161
163
|
InputGroupTextarea: {};
|
|
164
|
+
InputOtp: {};
|
|
165
|
+
InputOtpField: {};
|
|
166
|
+
InputOtpFieldController: {};
|
|
167
|
+
InputOtpGroup: {};
|
|
168
|
+
InputOtpSeparator: {};
|
|
169
|
+
InputOtpSlot: {};
|
|
162
170
|
inputVariants: {};
|
|
163
171
|
Item: {};
|
|
164
172
|
ItemActions: {};
|
|
@@ -195,6 +203,10 @@ export declare const reactSessionGenerator: import("@baseplate-dev/sync").Genera
|
|
|
195
203
|
NotFoundCard: {};
|
|
196
204
|
NumberField: {};
|
|
197
205
|
NumberFieldController: {};
|
|
206
|
+
PageHeader: {};
|
|
207
|
+
PageHeaderActions: {};
|
|
208
|
+
PageHeaderDescription: {};
|
|
209
|
+
PageHeaderTitle: {};
|
|
198
210
|
Popover: {};
|
|
199
211
|
PopoverContent: {};
|
|
200
212
|
PopoverTrigger: {};
|
|
@@ -204,6 +216,11 @@ export declare const reactSessionGenerator: import("@baseplate-dev/sync").Genera
|
|
|
204
216
|
isTypeOnly: true;
|
|
205
217
|
};
|
|
206
218
|
ScrollArea: {};
|
|
219
|
+
Section: {};
|
|
220
|
+
SectionActions: {};
|
|
221
|
+
SectionDescription: {};
|
|
222
|
+
SectionHeader: {};
|
|
223
|
+
SectionTitle: {};
|
|
207
224
|
Select: {};
|
|
208
225
|
SelectField: {};
|
|
209
226
|
SelectFieldController: {};
|
|
@@ -259,7 +276,27 @@ export declare const reactSessionGenerator: import("@baseplate-dev/sync").Genera
|
|
|
259
276
|
Textarea: {};
|
|
260
277
|
TextareaField: {};
|
|
261
278
|
TextareaFieldController: {};
|
|
279
|
+
Toast: {};
|
|
280
|
+
toast: {};
|
|
281
|
+
ToastAction: {};
|
|
282
|
+
ToastClose: {};
|
|
283
|
+
ToastContent: {};
|
|
284
|
+
ToastDescription: {};
|
|
262
285
|
Toaster: {};
|
|
286
|
+
toastManager: {};
|
|
287
|
+
ToastOptions: {
|
|
288
|
+
isTypeOnly: true;
|
|
289
|
+
};
|
|
290
|
+
ToastPortal: {};
|
|
291
|
+
ToastProvider: {};
|
|
292
|
+
ToastTitle: {};
|
|
293
|
+
ToastType: {
|
|
294
|
+
isTypeOnly: true;
|
|
295
|
+
};
|
|
296
|
+
ToastUpdateOptions: {
|
|
297
|
+
isTypeOnly: true;
|
|
298
|
+
};
|
|
299
|
+
ToastViewport: {};
|
|
263
300
|
Tooltip: {};
|
|
264
301
|
TooltipContent: {};
|
|
265
302
|
TooltipProvider: {};
|
|
@@ -294,6 +331,22 @@ export declare const reactSessionGenerator: import("@baseplate-dev/sync").Genera
|
|
|
294
331
|
}>, "getValues">>;
|
|
295
332
|
paths: import("@baseplate-dev/sync").ProviderType<import("./generated/template-paths.js").LocalAuthCoreReactSessionPaths>;
|
|
296
333
|
}, any>;
|
|
334
|
+
reactRouterConfig: import("@baseplate-dev/sync").GeneratorTask<any, {
|
|
335
|
+
reactRouterConfig: import("@baseplate-dev/sync").ProviderType<Omit<import("@baseplate-dev/utils").FieldMap<{
|
|
336
|
+
routerSetupFragments: import("@baseplate-dev/utils").MapContainer<string, import("@baseplate-dev/core-generators").TsCodeFragment>;
|
|
337
|
+
routerBodyFragments: import("@baseplate-dev/utils").MapContainer<string, import("@baseplate-dev/core-generators").TsCodeFragment>;
|
|
338
|
+
rootLayoutComponent: import("@baseplate-dev/utils").ScalarContainer<import("@baseplate-dev/core-generators").TsCodeFragment | undefined>;
|
|
339
|
+
rootContextFields: import("@baseplate-dev/utils").NamedArrayFieldContainer<import("@baseplate-dev/react-generators").RootRouteContextField>;
|
|
340
|
+
errorComponentHeaderFragments: import("@baseplate-dev/utils").MapContainer<string, import("@baseplate-dev/core-generators").TsCodeFragment>;
|
|
341
|
+
errorComponentBodyFragments: import("@baseplate-dev/utils").MapContainer<string, import("@baseplate-dev/core-generators").TsCodeFragment>;
|
|
342
|
+
}>, "getValues">>;
|
|
343
|
+
reactRouterImports: import("@baseplate-dev/sync").ProviderType<import("@baseplate-dev/core-generators").InferTsImportMapFromSchema<{
|
|
344
|
+
AppRoutes: {};
|
|
345
|
+
ErrorComponent: {};
|
|
346
|
+
router: {};
|
|
347
|
+
}>>;
|
|
348
|
+
paths: import("@baseplate-dev/sync").ProviderType<import("./generated/template-paths.js").LocalAuthCoreReactSessionPaths>;
|
|
349
|
+
}, any>;
|
|
297
350
|
main: import("@baseplate-dev/sync").GeneratorTask<any, {
|
|
298
351
|
renderers: import("@baseplate-dev/sync").ProviderType<import("./generated/template-renderers.js").LocalAuthCoreReactSessionRenderers>;
|
|
299
352
|
}, any>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TsCodeUtils, tsImportBuilder } from '@baseplate-dev/core-generators';
|
|
2
|
-
import { reactAppConfigProvider } from '@baseplate-dev/react-generators';
|
|
2
|
+
import { reactAppConfigProvider, reactRouterConfigProvider, reactRouterImportsProvider, } from '@baseplate-dev/react-generators';
|
|
3
3
|
import { createGenerator, createGeneratorTask } from '@baseplate-dev/sync';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { LOCAL_AUTH_CORE_REACT_SESSION_GENERATED as GENERATED_TEMPLATES } from './generated/index.js';
|
|
@@ -29,6 +29,40 @@ export const reactSessionGenerator = createGenerator({
|
|
|
29
29
|
});
|
|
30
30
|
},
|
|
31
31
|
}),
|
|
32
|
+
reactRouterConfig: createGeneratorTask({
|
|
33
|
+
dependencies: {
|
|
34
|
+
reactRouterConfig: reactRouterConfigProvider,
|
|
35
|
+
reactRouterImports: reactRouterImportsProvider,
|
|
36
|
+
paths: GENERATED_TEMPLATES.paths.provider,
|
|
37
|
+
},
|
|
38
|
+
run({ reactRouterConfig, reactRouterImports, paths }) {
|
|
39
|
+
reactRouterConfig.routerSetupFragments.set('auth-session-router-sync', TsCodeUtils.templateWithImports([
|
|
40
|
+
tsImportBuilder(['useEffect']).from('react'),
|
|
41
|
+
tsImportBuilder(['userSessionClient']).from(paths.userSessionClient),
|
|
42
|
+
reactRouterImports.router.declaration(),
|
|
43
|
+
]) `
|
|
44
|
+
// RouterProvider only copies the context into the router when it renders, so push
|
|
45
|
+
// the session in as soon as it changes. Otherwise a navigation triggered in the
|
|
46
|
+
// same tick as a sign in or sign out runs its guards against the old session.
|
|
47
|
+
useEffect(
|
|
48
|
+
() =>
|
|
49
|
+
userSessionClient.subscribe(() => {
|
|
50
|
+
const currentSession = userSessionClient.getSession();
|
|
51
|
+
if (!currentSession) return;
|
|
52
|
+
router.update({
|
|
53
|
+
...router.options,
|
|
54
|
+
context: {
|
|
55
|
+
...router.options.context,
|
|
56
|
+
session: currentSession,
|
|
57
|
+
userId: currentSession.userId,
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
}),
|
|
61
|
+
[],
|
|
62
|
+
);
|
|
63
|
+
`);
|
|
64
|
+
},
|
|
65
|
+
}),
|
|
32
66
|
main: createGeneratorTask({
|
|
33
67
|
dependencies: {
|
|
34
68
|
renderers: GENERATED_TEMPLATES.renderers.provider,
|
package/dist/local-auth/core/generators/react-session/templates/src/app/user-session-provider.js
CHANGED
|
@@ -5,7 +5,7 @@ import { AuthSessionContext } from '%localAuthHooksImports';
|
|
|
5
5
|
import { ErrorableLoader } from '%reactComponentsImports';
|
|
6
6
|
import { logError } from '%reactErrorImports';
|
|
7
7
|
import { useApolloClient, useQuery } from '@apollo/client/react';
|
|
8
|
-
import { useEffect,
|
|
8
|
+
import { useEffect, useRef, useSyncExternalStore } from 'react';
|
|
9
9
|
const getCurrentUserSessionQuery = graphql(`
|
|
10
10
|
query CurrentUserSession {
|
|
11
11
|
currentUserSession {
|
|
@@ -15,55 +15,28 @@ const getCurrentUserSessionQuery = graphql(`
|
|
|
15
15
|
}
|
|
16
16
|
`);
|
|
17
17
|
export function UserSessionProvider({ children, }) {
|
|
18
|
-
const [cachedUserId, setCachedUserId] = useState(userSessionClient.getUserId());
|
|
19
18
|
const apolloClient = useApolloClient();
|
|
19
|
+
// The session comes from the session client rather than the query, since signing
|
|
20
|
+
// in clears the Apollo cache and would otherwise blank the session mid-transition.
|
|
21
|
+
const session = useSyncExternalStore(userSessionClient.subscribe, userSessionClient.getSession);
|
|
20
22
|
const { data: sessionQueryData, error: sessionError } = useQuery(getCurrentUserSessionQuery, {
|
|
21
23
|
notifyOnNetworkStatusChange: true,
|
|
22
24
|
});
|
|
23
|
-
const session = useMemo(() => {
|
|
24
|
-
if (!sessionQueryData && cachedUserId) {
|
|
25
|
-
// wait for server to fetch before loading session
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
28
|
-
if (!sessionQueryData?.currentUserSession) {
|
|
29
|
-
return {
|
|
30
|
-
userId: undefined,
|
|
31
|
-
isAuthenticated: false,
|
|
32
|
-
roles: ['public'],
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
userId: sessionQueryData.currentUserSession.userId,
|
|
37
|
-
isAuthenticated: true,
|
|
38
|
-
roles: sessionQueryData.currentUserSession.roles,
|
|
39
|
-
};
|
|
40
|
-
}, [sessionQueryData, cachedUserId]);
|
|
41
25
|
useEffect(() => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
// Make sure to reset the Apollo client to clear any cached data
|
|
46
|
-
apolloClient.resetStore().catch(logError);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
return unsubscribe;
|
|
50
|
-
}, [cachedUserId, apolloClient]);
|
|
51
|
-
useEffect(() => {
|
|
52
|
-
// Once we have server session data, sync it with the client
|
|
53
|
-
if (sessionQueryData) {
|
|
54
|
-
const serverUserId = sessionQueryData.currentUserSession?.userId;
|
|
55
|
-
const clientUserId = userSessionClient.getUserId();
|
|
56
|
-
// If server says different user (or no user), update the client
|
|
57
|
-
if (serverUserId !== clientUserId) {
|
|
58
|
-
if (serverUserId) {
|
|
59
|
-
userSessionClient.signIn(serverUserId);
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
userSessionClient.signOut();
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
26
|
+
if (!sessionQueryData)
|
|
27
|
+
return;
|
|
28
|
+
userSessionClient.setServerSession(sessionQueryData.currentUserSession ?? undefined);
|
|
66
29
|
}, [sessionQueryData]);
|
|
30
|
+
// The Apollo cache belongs to exactly one identity, so reset it whenever the
|
|
31
|
+
// identity changes and no data fetched for the previous user survives.
|
|
32
|
+
const cacheUserId = useRef(userSessionClient.getPersistedUserId());
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (!session || session.userId === cacheUserId.current)
|
|
35
|
+
return;
|
|
36
|
+
cacheUserId.current = session.userId;
|
|
37
|
+
apolloClient.resetStore().catch(logError);
|
|
38
|
+
}, [session, apolloClient]);
|
|
39
|
+
// Only reachable before the first session is known, when nothing has mounted yet.
|
|
67
40
|
if (!session) {
|
|
68
41
|
return _jsx(ErrorableLoader, { error: sessionError });
|
|
69
42
|
}
|
package/dist/local-auth/core/generators/react-session/templates/src/app/user-session-provider.tsx
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
|
|
3
|
-
import type { SessionData } from '%authHooksImports';
|
|
4
3
|
import type React from 'react';
|
|
5
4
|
|
|
6
5
|
import { userSessionClient } from '$userSessionClient';
|
|
@@ -9,7 +8,7 @@ import { AuthSessionContext } from '%localAuthHooksImports';
|
|
|
9
8
|
import { ErrorableLoader } from '%reactComponentsImports';
|
|
10
9
|
import { logError } from '%reactErrorImports';
|
|
11
10
|
import { useApolloClient, useQuery } from '@apollo/client/react';
|
|
12
|
-
import { useEffect,
|
|
11
|
+
import { useEffect, useRef, useSyncExternalStore } from 'react';
|
|
13
12
|
|
|
14
13
|
interface UserSessionProviderProps {
|
|
15
14
|
children: React.ReactNode;
|
|
@@ -27,11 +26,15 @@ const getCurrentUserSessionQuery = graphql(`
|
|
|
27
26
|
export function UserSessionProvider({
|
|
28
27
|
children,
|
|
29
28
|
}: UserSessionProviderProps): React.JSX.Element {
|
|
30
|
-
const [cachedUserId, setCachedUserId] = useState<string | undefined>(
|
|
31
|
-
userSessionClient.getUserId(),
|
|
32
|
-
);
|
|
33
29
|
const apolloClient = useApolloClient();
|
|
34
30
|
|
|
31
|
+
// The session comes from the session client rather than the query, since signing
|
|
32
|
+
// in clears the Apollo cache and would otherwise blank the session mid-transition.
|
|
33
|
+
const session = useSyncExternalStore(
|
|
34
|
+
userSessionClient.subscribe,
|
|
35
|
+
userSessionClient.getSession,
|
|
36
|
+
);
|
|
37
|
+
|
|
35
38
|
const { data: sessionQueryData, error: sessionError } = useQuery(
|
|
36
39
|
getCurrentUserSessionQuery,
|
|
37
40
|
{
|
|
@@ -39,54 +42,23 @@ export function UserSessionProvider({
|
|
|
39
42
|
},
|
|
40
43
|
);
|
|
41
44
|
|
|
42
|
-
const session = useMemo((): SessionData | undefined => {
|
|
43
|
-
if (!sessionQueryData && cachedUserId) {
|
|
44
|
-
// wait for server to fetch before loading session
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
if (!sessionQueryData?.currentUserSession) {
|
|
48
|
-
return {
|
|
49
|
-
userId: undefined,
|
|
50
|
-
isAuthenticated: false,
|
|
51
|
-
roles: ['public'],
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
return {
|
|
55
|
-
userId: sessionQueryData.currentUserSession.userId,
|
|
56
|
-
isAuthenticated: true,
|
|
57
|
-
roles: sessionQueryData.currentUserSession.roles,
|
|
58
|
-
};
|
|
59
|
-
}, [sessionQueryData, cachedUserId]);
|
|
60
|
-
|
|
61
45
|
useEffect(() => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
return unsubscribe;
|
|
71
|
-
}, [cachedUserId, apolloClient]);
|
|
46
|
+
if (!sessionQueryData) return;
|
|
47
|
+
userSessionClient.setServerSession(
|
|
48
|
+
sessionQueryData.currentUserSession ?? undefined,
|
|
49
|
+
);
|
|
50
|
+
}, [sessionQueryData]);
|
|
72
51
|
|
|
52
|
+
// The Apollo cache belongs to exactly one identity, so reset it whenever the
|
|
53
|
+
// identity changes and no data fetched for the previous user survives.
|
|
54
|
+
const cacheUserId = useRef(userSessionClient.getPersistedUserId());
|
|
73
55
|
useEffect(() => {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
// If server says different user (or no user), update the client
|
|
80
|
-
if (serverUserId !== clientUserId) {
|
|
81
|
-
if (serverUserId) {
|
|
82
|
-
userSessionClient.signIn(serverUserId);
|
|
83
|
-
} else {
|
|
84
|
-
userSessionClient.signOut();
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}, [sessionQueryData]);
|
|
56
|
+
if (!session || session.userId === cacheUserId.current) return;
|
|
57
|
+
cacheUserId.current = session.userId;
|
|
58
|
+
apolloClient.resetStore().catch(logError);
|
|
59
|
+
}, [session, apolloClient]);
|
|
89
60
|
|
|
61
|
+
// Only reachable before the first session is known, when nothing has mounted yet.
|
|
90
62
|
if (!session) {
|
|
91
63
|
return <ErrorableLoader error={sessionError} />;
|
|
92
64
|
}
|
|
@@ -1,55 +1,64 @@
|
|
|
1
|
+
import type { SessionData } from '%authHooksImports';
|
|
2
|
+
import type { AuthRole } from '%graphqlImports';
|
|
1
3
|
/**
|
|
2
|
-
* Callback function for
|
|
4
|
+
* Callback function for session change events
|
|
3
5
|
*/
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
* User session client for managing session persistence using localStorage
|
|
7
|
-
* Handles session state persistence and cross-tab synchronization
|
|
8
|
-
*/
|
|
9
|
-
export declare class UserSessionClient {
|
|
10
|
-
private static readonly USER_ID_STORAGE_KEY;
|
|
11
|
-
private readonly storage;
|
|
12
|
-
private readonly callbacks;
|
|
13
|
-
private cleanupListener?;
|
|
14
|
-
constructor();
|
|
15
|
-
/**
|
|
16
|
-
* Sign in a user with the given user ID
|
|
17
|
-
* @param userId - The user ID to sign in
|
|
18
|
-
*/
|
|
19
|
-
signIn(userId: string): void;
|
|
6
|
+
type SessionChangeCallback = () => void;
|
|
7
|
+
export interface UserSessionClient {
|
|
20
8
|
/**
|
|
21
|
-
*
|
|
9
|
+
* Get the current session, or `undefined` if it is not known yet.
|
|
10
|
+
*
|
|
11
|
+
* Returns a stable reference that only changes when the session itself changes,
|
|
12
|
+
* so it is safe to use as a `useSyncExternalStore` snapshot.
|
|
22
13
|
*/
|
|
23
|
-
|
|
14
|
+
getSession: () => SessionData | undefined;
|
|
24
15
|
/**
|
|
25
|
-
* Subscribe to
|
|
26
|
-
* @param callback - Function to call when
|
|
16
|
+
* Subscribe to session changes
|
|
17
|
+
* @param callback - Function to call when the session changes
|
|
27
18
|
* @returns Cleanup function to unsubscribe
|
|
28
19
|
*/
|
|
29
|
-
|
|
20
|
+
subscribe: (callback: SessionChangeCallback) => () => void;
|
|
30
21
|
/**
|
|
31
|
-
*
|
|
22
|
+
* Sign in a user with a session the server has already returned
|
|
23
|
+
* @param userId - The user ID to sign in
|
|
24
|
+
* @param roles - The roles the server issued alongside the session
|
|
32
25
|
*/
|
|
33
|
-
|
|
26
|
+
signIn: (userId: string, roles: AuthRole[]) => void;
|
|
34
27
|
/**
|
|
35
|
-
*
|
|
36
|
-
* @returns User ID or null if not authenticated
|
|
28
|
+
* Sign out the current user
|
|
37
29
|
*/
|
|
38
|
-
|
|
30
|
+
signOut: () => void;
|
|
39
31
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
32
|
+
* Apply the session reported by the server, confirming or replacing whatever was
|
|
33
|
+
* published locally
|
|
34
|
+
* @param session - The session from the server, or undefined if signed out
|
|
42
35
|
*/
|
|
43
|
-
|
|
36
|
+
setServerSession: (session: {
|
|
37
|
+
userId: string;
|
|
38
|
+
roles: AuthRole[];
|
|
39
|
+
} | undefined) => void;
|
|
44
40
|
/**
|
|
45
|
-
*
|
|
41
|
+
* Get the user ID persisted in storage, which may not be confirmed yet
|
|
42
|
+
* @returns User ID or undefined if not signed in
|
|
46
43
|
*/
|
|
47
|
-
|
|
44
|
+
getPersistedUserId: () => string | undefined;
|
|
48
45
|
/**
|
|
49
|
-
*
|
|
46
|
+
* Clean up resources when the client is no longer needed
|
|
50
47
|
*/
|
|
51
|
-
|
|
48
|
+
destroy: () => void;
|
|
52
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Creates the client-side source of truth for the current user session.
|
|
52
|
+
*
|
|
53
|
+
* The session is published synchronously when it is known locally (sign in / sign
|
|
54
|
+
* out) and refined asynchronously when the server confirms it. It is deliberately
|
|
55
|
+
* not derived from the Apollo cache, since signing in clears that cache.
|
|
56
|
+
*
|
|
57
|
+
* The user ID is persisted to localStorage for cold starts and cross-tab
|
|
58
|
+
* synchronisation. Roles are never persisted — they are only ever trusted from the
|
|
59
|
+
* server, and are enforced there regardless.
|
|
60
|
+
*/
|
|
61
|
+
export declare function createUserSessionClient(): UserSessionClient;
|
|
53
62
|
/**
|
|
54
63
|
* Global user session client instance
|
|
55
64
|
*/
|
package/dist/local-auth/core/generators/react-session/templates/src/services/user-session-client.js
CHANGED
|
@@ -1,103 +1,119 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
import { getSafeLocalStorage } from '%reactUtilsImports';
|
|
3
|
+
const USER_ID_STORAGE_KEY = 'APP_USER_ID';
|
|
4
|
+
const PUBLIC_SESSION = {
|
|
5
|
+
userId: undefined,
|
|
6
|
+
isAuthenticated: false,
|
|
7
|
+
roles: ['public'],
|
|
8
|
+
isPending: false,
|
|
9
|
+
};
|
|
10
|
+
function areSessionsEqual(a, b) {
|
|
11
|
+
return (a.userId === b.userId &&
|
|
12
|
+
a.isPending === b.isPending &&
|
|
13
|
+
a.roles.length === b.roles.length &&
|
|
14
|
+
a.roles.every((role, idx) => role === b.roles[idx]));
|
|
15
|
+
}
|
|
3
16
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
17
|
+
* Creates the client-side source of truth for the current user session.
|
|
18
|
+
*
|
|
19
|
+
* The session is published synchronously when it is known locally (sign in / sign
|
|
20
|
+
* out) and refined asynchronously when the server confirms it. It is deliberately
|
|
21
|
+
* not derived from the Apollo cache, since signing in clears that cache.
|
|
22
|
+
*
|
|
23
|
+
* The user ID is persisted to localStorage for cold starts and cross-tab
|
|
24
|
+
* synchronisation. Roles are never persisted — they are only ever trusted from the
|
|
25
|
+
* server, and are enforced there regardless.
|
|
6
26
|
*/
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
constructor() {
|
|
13
|
-
// Initialize storage listener for cross-tab synchronization
|
|
14
|
-
this.setupStorageListener();
|
|
27
|
+
export function createUserSessionClient() {
|
|
28
|
+
const storage = getSafeLocalStorage();
|
|
29
|
+
const callbacks = new Set();
|
|
30
|
+
function getPersistedUserId() {
|
|
31
|
+
return storage.getItem(USER_ID_STORAGE_KEY) ?? undefined;
|
|
15
32
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (
|
|
24
|
-
|
|
33
|
+
// A persisted user ID means we expect a session, so hold off publishing until the
|
|
34
|
+
// server confirms it. With no persisted user ID there is nothing to wait for and
|
|
35
|
+
// the public session can be published immediately.
|
|
36
|
+
let session = getPersistedUserId()
|
|
37
|
+
? undefined
|
|
38
|
+
: PUBLIC_SESSION;
|
|
39
|
+
function publish(newSession) {
|
|
40
|
+
if (session && areSessionsEqual(session, newSession)) {
|
|
41
|
+
return;
|
|
25
42
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
*/
|
|
30
|
-
signOut() {
|
|
31
|
-
const existingUserId = this.getUserId();
|
|
32
|
-
this.setUserId(null);
|
|
33
|
-
if (existingUserId) {
|
|
34
|
-
this.notifyCallbacks();
|
|
43
|
+
session = newSession;
|
|
44
|
+
for (const callback of callbacks) {
|
|
45
|
+
callback();
|
|
35
46
|
}
|
|
36
47
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
* @param callback - Function to call when user ID changes
|
|
40
|
-
* @returns Cleanup function to unsubscribe
|
|
41
|
-
*/
|
|
42
|
-
onUserIdChange(callback) {
|
|
43
|
-
this.callbacks.add(callback);
|
|
44
|
-
return () => {
|
|
45
|
-
this.callbacks.delete(callback);
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Clean up resources when the client is no longer needed
|
|
50
|
-
*/
|
|
51
|
-
destroy() {
|
|
52
|
-
this.cleanupListener?.();
|
|
53
|
-
this.callbacks.clear();
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Get the current user ID from storage
|
|
57
|
-
* @returns User ID or null if not authenticated
|
|
58
|
-
*/
|
|
59
|
-
getUserId() {
|
|
60
|
-
return (this.storage.getItem(UserSessionClient.USER_ID_STORAGE_KEY) ?? undefined);
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Set the user ID in storage
|
|
64
|
-
* @param userId - User ID to store, or null to clear
|
|
65
|
-
*/
|
|
66
|
-
setUserId(userId) {
|
|
67
|
-
const currentUserId = this.getUserId();
|
|
68
|
-
const userIdChanged = userId !== currentUserId;
|
|
69
|
-
if (!userIdChanged) {
|
|
48
|
+
function persistUserId(userId) {
|
|
49
|
+
if (userId === getPersistedUserId()) {
|
|
70
50
|
return;
|
|
71
51
|
}
|
|
72
52
|
if (userId) {
|
|
73
|
-
|
|
53
|
+
storage.setItem(USER_ID_STORAGE_KEY, userId);
|
|
74
54
|
}
|
|
75
55
|
else {
|
|
76
|
-
|
|
56
|
+
storage.removeItem(USER_ID_STORAGE_KEY);
|
|
77
57
|
}
|
|
78
58
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
this.notifyCallbacks();
|
|
86
|
-
}
|
|
59
|
+
function signIn(userId, roles) {
|
|
60
|
+
publish({
|
|
61
|
+
userId,
|
|
62
|
+
isAuthenticated: true,
|
|
63
|
+
roles,
|
|
64
|
+
isPending: false,
|
|
87
65
|
});
|
|
66
|
+
persistUserId(userId);
|
|
88
67
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
notifyCallbacks() {
|
|
93
|
-
const userId = this.getUserId();
|
|
94
|
-
for (const callback of this.callbacks) {
|
|
95
|
-
callback(userId);
|
|
96
|
-
}
|
|
68
|
+
function signOut() {
|
|
69
|
+
publish(PUBLIC_SESSION);
|
|
70
|
+
persistUserId(undefined);
|
|
97
71
|
}
|
|
72
|
+
const cleanupListener = storage.addEventListener((key, newValue) => {
|
|
73
|
+
if (key !== USER_ID_STORAGE_KEY) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const userId = newValue ?? undefined;
|
|
77
|
+
// Writes from this tab publish the session themselves before persisting it, so
|
|
78
|
+
// anything already matching is our own write echoing back. A session that is
|
|
79
|
+
// not known yet never matches, since no session has been published.
|
|
80
|
+
if (session && userId === session.userId) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
// Another tab changed the identity. Publish it right away so we never render
|
|
84
|
+
// one user's identity with another's data, with roles marked pending until the
|
|
85
|
+
// server confirms them.
|
|
86
|
+
publish(userId
|
|
87
|
+
? { userId, isAuthenticated: true, roles: [], isPending: true }
|
|
88
|
+
: PUBLIC_SESSION);
|
|
89
|
+
});
|
|
90
|
+
return {
|
|
91
|
+
getSession: () => session,
|
|
92
|
+
subscribe(callback) {
|
|
93
|
+
callbacks.add(callback);
|
|
94
|
+
return () => {
|
|
95
|
+
callbacks.delete(callback);
|
|
96
|
+
};
|
|
97
|
+
},
|
|
98
|
+
signIn,
|
|
99
|
+
signOut,
|
|
100
|
+
setServerSession(serverSession) {
|
|
101
|
+
if (serverSession) {
|
|
102
|
+
signIn(serverSession.userId, serverSession.roles);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
signOut();
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
getPersistedUserId,
|
|
109
|
+
destroy() {
|
|
110
|
+
cleanupListener();
|
|
111
|
+
callbacks.clear();
|
|
112
|
+
},
|
|
113
|
+
};
|
|
98
114
|
}
|
|
99
115
|
/**
|
|
100
116
|
* Global user session client instance
|
|
101
117
|
*/
|
|
102
|
-
export const userSessionClient =
|
|
118
|
+
export const userSessionClient = createUserSessionClient();
|
|
103
119
|
//# sourceMappingURL=user-session-client.js.map
|