create-ailk 0.38.0 → 0.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/add-route.js +16 -1
- package/dist/body-heading.d.ts +2 -1
- package/dist/body-heading.js +31 -3
- package/dist/derive-architecture.js +3 -1
- package/dist/module-architecture.js +0 -3
- package/dist/remove-module.js +27 -14
- package/dist/routes.d.ts +36 -2
- package/dist/routes.js +269 -23
- package/dist/site-manifest.js +6 -4
- package/dist/site-roster.d.ts +11 -3
- package/dist/site-roster.js +48 -22
- package/dist/surfaces.d.ts +13 -3
- package/dist/surfaces.js +128 -194
- package/dist/sync-routes.js +22 -5
- package/dist/template-record.js +3 -1
- package/dist/topology.d.ts +11 -0
- package/dist/topology.js +253 -3
- package/package.json +3 -3
- package/templates/apps/web/CLAUDE.md +32 -4
- package/templates/apps/web/__tests__/__mocks__/next-intl-server.ts +6 -1
- package/templates/apps/web/__tests__/__mocks__/next-intl.ts +6 -1
- package/templates/apps/web/__tests__/auth/seam.test.ts +34 -0
- package/templates/apps/web/account.config.tsx +2 -3
- package/templates/apps/web/app/[locale]/(authed)/account/connect/__tests__/page.test.tsx +1 -1
- package/templates/apps/web/app/[locale]/(authed)/account/connect/page.tsx +1 -1
- package/templates/apps/web/app/[locale]/(authed)/signed-out-gate.generated.tsx +1 -1
- package/templates/apps/web/app/[locale]/layout.tsx +2 -2
- package/templates/apps/web/auth.config.tsx +107 -0
- package/templates/apps/web/auth.ts +2 -1
- package/templates/apps/web/i18n/request.ts +13 -2
- package/templates/apps/web/jest.config.cjs +10 -0
- package/templates/apps/web/lib/__tests__/deck-page.test.ts +9 -0
- package/templates/apps/web/lib/__tests__/fixtures/site-topology.ts +3 -0
- package/templates/apps/web/lib/__tests__/in-page-magnet-self-request.test.ts +1 -1
- package/templates/apps/web/lib/__tests__/in-page-magnet.test.ts +2 -2
- package/templates/apps/web/lib/__tests__/pricing-page.test.ts +1 -1
- package/templates/apps/web/lib/__tests__/server-api.test.ts +1 -1
- package/templates/apps/web/lib/__tests__/structured-data.test.tsx +17 -4
- package/templates/apps/web/lib/in-page-magnet.ts +2 -2
- package/templates/apps/web/lib/pricing-page.ts +3 -3
- package/templates/apps/web/lib/server-api.ts +1 -1
- package/templates/apps/web/{app/[locale]/contact → lib}/site-contact-email.ts +1 -1
- package/templates/apps/web/{app/[locale]/contact → lib}/site-contact-lines.ts +1 -1
- package/templates/apps/web/lib/site-header.ts +1 -1
- package/templates/apps/web/lib/topology.generated.ts +5 -0
- package/templates/apps/web/messages/en.json +0 -271
- package/templates/apps/web/middleware.ts +12 -25
- package/templates/apps/web/next.config.mjs +15 -0
- package/templates/apps/web/package.json +2 -0
- package/templates/apps/web/site-pages.config.tsx +85 -0
- package/templates/apps/web/types/messages.d.ts +6 -1
- package/templates/tools/body-heading.ts +30 -3
- package/versions.json +50 -48
- package/templates/apps/web/app/[locale]/(auth)/__tests__/auth-pages.test.tsx +0 -322
- package/templates/apps/web/app/[locale]/(auth)/__tests__/password-reset.test.tsx +0 -554
- package/templates/apps/web/app/[locale]/(auth)/consent/__tests__/consent-actions.test.ts +0 -56
- package/templates/apps/web/app/[locale]/(auth)/consent/__tests__/page.test.tsx +0 -164
- package/templates/apps/web/app/[locale]/(auth)/consent/consent-form.tsx +0 -132
- package/templates/apps/web/app/[locale]/(auth)/consent/consent.actions.ts +0 -51
- package/templates/apps/web/app/[locale]/(auth)/consent/page.tsx +0 -144
- package/templates/apps/web/app/[locale]/(auth)/forgot-password/forgot-password-card.tsx +0 -101
- package/templates/apps/web/app/[locale]/(auth)/forgot-password/page.tsx +0 -111
- package/templates/apps/web/app/[locale]/(auth)/layout.tsx +0 -81
- package/templates/apps/web/app/[locale]/(auth)/legal-footnote.tsx +0 -35
- package/templates/apps/web/app/[locale]/(auth)/reset-password/__tests__/return.test.tsx +0 -179
- package/templates/apps/web/app/[locale]/(auth)/reset-password/page.tsx +0 -157
- package/templates/apps/web/app/[locale]/(auth)/reset-password/reset-password-card.tsx +0 -126
- package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/next-path.test.ts +0 -54
- package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/page.test.tsx +0 -628
- package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/remembered-method.test.ts +0 -43
- package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/sign-in-card.test.tsx +0 -266
- package/templates/apps/web/app/[locale]/(auth)/sign-in/next-path.ts +0 -20
- package/templates/apps/web/app/[locale]/(auth)/sign-in/page.tsx +0 -234
- package/templates/apps/web/app/[locale]/(auth)/sign-in/remembered-method.ts +0 -37
- package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-card.tsx +0 -323
- package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-text.ts +0 -93
- package/templates/apps/web/app/[locale]/(auth)/sign-up/__tests__/page.test.tsx +0 -301
- package/templates/apps/web/app/[locale]/(auth)/sign-up/__tests__/sign-up-card.test.tsx +0 -309
- package/templates/apps/web/app/[locale]/(auth)/sign-up/page.tsx +0 -201
- package/templates/apps/web/app/[locale]/(auth)/sign-up/sign-up-card.tsx +0 -366
- package/templates/apps/web/app/[locale]/(auth)/use-auth-card-flow.ts +0 -116
- package/templates/apps/web/app/[locale]/(auth)/verify-email/__tests__/actions.test.ts +0 -94
- package/templates/apps/web/app/[locale]/(auth)/verify-email/actions.ts +0 -77
- package/templates/apps/web/app/[locale]/(auth)/verify-email/page.tsx +0 -154
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +0 -3
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +0 -3
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +0 -3
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +0 -2
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +0 -3
- package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +0 -12
- package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +0 -12
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +0 -12
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/route.ts +0 -2
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +0 -12
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/page.tsx +0 -3
- package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +0 -10
- package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +0 -3
- package/templates/apps/web/app/[locale]/(authed)/account/onboarding/page.tsx +0 -3
- package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +0 -12
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +0 -2
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +0 -3
- package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +0 -3
- package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +0 -2
- package/templates/apps/web/app/[locale]/(authed)/account/support/page.tsx +0 -3
- package/templates/apps/web/app/[locale]/(authed)/leads/__tests__/page.test.tsx +0 -205
- package/templates/apps/web/app/[locale]/(authed)/leads/components/LeadsTable.tsx +0 -137
- package/templates/apps/web/app/[locale]/(authed)/leads/page.tsx +0 -122
- package/templates/apps/web/app/[locale]/(authed)/waitlist/components/ForbiddenState.tsx +0 -24
- package/templates/apps/web/app/[locale]/(authed)/waitlist/format.ts +0 -111
- package/templates/apps/web/app/[locale]/[slug]/[detail]/__tests__/page.test.tsx +0 -402
- package/templates/apps/web/app/[locale]/[slug]/[detail]/page.tsx +0 -143
- package/templates/apps/web/app/[locale]/[slug]/__tests__/page.test.tsx +0 -148
- package/templates/apps/web/app/[locale]/[slug]/page.tsx +0 -109
- package/templates/apps/web/app/[locale]/about/[slug]/page.tsx +0 -46
- package/templates/apps/web/app/[locale]/about/__tests__/about-routes.test.tsx +0 -353
- package/templates/apps/web/app/[locale]/about/page.tsx +0 -122
- package/templates/apps/web/app/[locale]/alternatives/__tests__/page.test.tsx +0 -161
- package/templates/apps/web/app/[locale]/alternatives/page.tsx +0 -112
- package/templates/apps/web/app/[locale]/careers/[slug]/[action]/page.tsx +0 -244
- package/templates/apps/web/app/[locale]/careers/[slug]/apply.actions.ts +0 -325
- package/templates/apps/web/app/[locale]/careers/[slug]/job-application-form.ts +0 -120
- package/templates/apps/web/app/[locale]/careers/[slug]/page.tsx +0 -73
- package/templates/apps/web/app/[locale]/careers/__tests__/apply.actions.test.ts +0 -497
- package/templates/apps/web/app/[locale]/careers/__tests__/careers-hub.test.tsx +0 -172
- package/templates/apps/web/app/[locale]/careers/__tests__/careers-set.test.tsx +0 -153
- package/templates/apps/web/app/[locale]/careers/__tests__/job-application-form.test.ts +0 -141
- package/templates/apps/web/app/[locale]/careers/__tests__/job-apply-page.test.tsx +0 -546
- package/templates/apps/web/app/[locale]/careers/__tests__/page-renderer-migration.test.tsx +0 -189
- package/templates/apps/web/app/[locale]/careers/page.tsx +0 -165
- package/templates/apps/web/app/[locale]/case-studies/[slug]/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/case-studies/__tests__/hub-children.test.tsx +0 -65
- package/templates/apps/web/app/[locale]/case-studies/__tests__/page-renderer-migration.test.tsx +0 -125
- package/templates/apps/web/app/[locale]/case-studies/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/clients/__tests__/page-renderer-migration.test.tsx +0 -85
- package/templates/apps/web/app/[locale]/clients/page.tsx +0 -47
- package/templates/apps/web/app/[locale]/contact/ConversationalIntakeWrapper.tsx +0 -249
- package/templates/apps/web/app/[locale]/contact/__tests__/ConversationalIntakeWrapper.test.tsx +0 -400
- package/templates/apps/web/app/[locale]/contact/__tests__/contact-form-magnet.test.ts +0 -138
- package/templates/apps/web/app/[locale]/contact/__tests__/contact-form-text.test.ts +0 -49
- package/templates/apps/web/app/[locale]/contact/__tests__/contact-magnet-page.test.tsx +0 -494
- package/templates/apps/web/app/[locale]/contact/__tests__/contact.actions.test.ts +0 -1122
- package/templates/apps/web/app/[locale]/contact/__tests__/intake-analytics.test.ts +0 -51
- package/templates/apps/web/app/[locale]/contact/__tests__/page-renderer-migration.test.tsx +0 -319
- package/templates/apps/web/app/[locale]/contact/contact-form-magnet.ts +0 -77
- package/templates/apps/web/app/[locale]/contact/contact-form-text.ts +0 -52
- package/templates/apps/web/app/[locale]/contact/contact.actions.ts +0 -403
- package/templates/apps/web/app/[locale]/contact/intake-analytics.ts +0 -49
- package/templates/apps/web/app/[locale]/contact/intake-script.ts +0 -92
- package/templates/apps/web/app/[locale]/contact/page.tsx +0 -267
- package/templates/apps/web/app/[locale]/courses/[slug]/page.tsx +0 -50
- package/templates/apps/web/app/[locale]/courses/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/courses/__tests__/page-renderer-migration.test.tsx +0 -123
- package/templates/apps/web/app/[locale]/courses/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/events/[slug]/page.tsx +0 -57
- package/templates/apps/web/app/[locale]/events/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/events/__tests__/page-renderer-migration.test.tsx +0 -164
- package/templates/apps/web/app/[locale]/events/__tests__/program-event.test.tsx +0 -120
- package/templates/apps/web/app/[locale]/events/page.tsx +0 -60
- package/templates/apps/web/app/[locale]/faq/page.tsx +0 -54
- package/templates/apps/web/app/[locale]/features/[slug]/page.tsx +0 -54
- package/templates/apps/web/app/[locale]/features/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/features/page.tsx +0 -50
- package/templates/apps/web/app/[locale]/for/[slug]/page.tsx +0 -54
- package/templates/apps/web/app/[locale]/for/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/for/__tests__/page-renderer-migration.test.tsx +0 -90
- package/templates/apps/web/app/[locale]/for/page.tsx +0 -51
- package/templates/apps/web/app/[locale]/glossary/page.tsx +0 -53
- package/templates/apps/web/app/[locale]/how-to/[slug]/page.tsx +0 -50
- package/templates/apps/web/app/[locale]/how-to/__tests__/page-renderer-migration.test.tsx +0 -78
- package/templates/apps/web/app/[locale]/how-to/page.tsx +0 -50
- package/templates/apps/web/app/[locale]/integrations/[slug]/page.tsx +0 -54
- package/templates/apps/web/app/[locale]/integrations/__tests__/hub-children.test.tsx +0 -38
- package/templates/apps/web/app/[locale]/integrations/__tests__/page-renderer-migration.test.tsx +0 -141
- package/templates/apps/web/app/[locale]/integrations/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/launch-service/page.tsx +0 -44
- package/templates/apps/web/app/[locale]/newsletter/__tests__/page.test.tsx +0 -236
- package/templates/apps/web/app/[locale]/newsletter/page.tsx +0 -179
- package/templates/apps/web/app/[locale]/page.tsx +0 -147
- package/templates/apps/web/app/[locale]/partners/[slug]/page.tsx +0 -45
- package/templates/apps/web/app/[locale]/partners/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/partners/__tests__/page-renderer-migration.test.tsx +0 -125
- package/templates/apps/web/app/[locale]/partners/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/portfolio/[slug]/page.tsx +0 -46
- package/templates/apps/web/app/[locale]/portfolio/__tests__/hub-children.test.tsx +0 -38
- package/templates/apps/web/app/[locale]/portfolio/page.tsx +0 -50
- package/templates/apps/web/app/[locale]/pricing/[slug]/__tests__/page.test.tsx +0 -324
- package/templates/apps/web/app/[locale]/pricing/[slug]/page.tsx +0 -87
- package/templates/apps/web/app/[locale]/pricing/__tests__/__snapshots__/unconnected.test.tsx.snap +0 -7
- package/templates/apps/web/app/[locale]/pricing/__tests__/offerings.test.tsx +0 -605
- package/templates/apps/web/app/[locale]/pricing/__tests__/page.test.tsx +0 -219
- package/templates/apps/web/app/[locale]/pricing/__tests__/pricing-pages.test.tsx +0 -215
- package/templates/apps/web/app/[locale]/pricing/__tests__/unconnected.test.tsx +0 -282
- package/templates/apps/web/app/[locale]/pricing/page.tsx +0 -120
- package/templates/apps/web/app/[locale]/privacy/page.tsx +0 -40
- package/templates/apps/web/app/[locale]/products/[slug]/page.tsx +0 -50
- package/templates/apps/web/app/[locale]/products/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/products/__tests__/page-renderer-migration.test.tsx +0 -141
- package/templates/apps/web/app/[locale]/products/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/projects/[slug]/page.tsx +0 -37
- package/templates/apps/web/app/[locale]/projects/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/projects/__tests__/page-renderer-migration.test.tsx +0 -157
- package/templates/apps/web/app/[locale]/projects/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/purchase-policy/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/resources/[slug]/page.tsx +0 -54
- package/templates/apps/web/app/[locale]/resources/__tests__/hub-children.test.tsx +0 -38
- package/templates/apps/web/app/[locale]/resources/__tests__/page-renderer-migration.test.tsx +0 -151
- package/templates/apps/web/app/[locale]/resources/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/services/[slug]/[child]/page.tsx +0 -68
- package/templates/apps/web/app/[locale]/services/[slug]/page.tsx +0 -88
- package/templates/apps/web/app/[locale]/services/__tests__/hub-children.test.tsx +0 -158
- package/templates/apps/web/app/[locale]/services/__tests__/page-renderer-migration.test.tsx +0 -187
- package/templates/apps/web/app/[locale]/services/__tests__/service-detail-sections.test.tsx +0 -224
- package/templates/apps/web/app/[locale]/services/__tests__/service-families.test.tsx +0 -368
- package/templates/apps/web/app/[locale]/services/page.tsx +0 -71
- package/templates/apps/web/app/[locale]/software/[slug]/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/software/__tests__/page-renderer-migration.test.tsx +0 -81
- package/templates/apps/web/app/[locale]/software/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/team/[slug]/page.tsx +0 -45
- package/templates/apps/web/app/[locale]/team/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/team/__tests__/team-routes.test.tsx +0 -161
- package/templates/apps/web/app/[locale]/team/page.tsx +0 -50
- package/templates/apps/web/app/[locale]/tech-articles/[slug]/page.tsx +0 -54
- package/templates/apps/web/app/[locale]/tech-articles/__tests__/page-renderer-migration.test.tsx +0 -82
- package/templates/apps/web/app/[locale]/tech-articles/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/templates/[slug]/__tests__/page.test.tsx +0 -203
- package/templates/apps/web/app/[locale]/templates/[slug]/page.tsx +0 -81
- package/templates/apps/web/app/[locale]/templates/__tests__/page.test.tsx +0 -237
- package/templates/apps/web/app/[locale]/templates/page.tsx +0 -114
- package/templates/apps/web/app/[locale]/terms/page.tsx +0 -40
- package/templates/apps/web/app/[locale]/testimonials/__tests__/page-renderer-migration.test.tsx +0 -85
- package/templates/apps/web/app/[locale]/testimonials/page.tsx +0 -51
- package/templates/apps/web/app/[locale]/thanks/[slug]/__tests__/page.test.tsx +0 -136
- package/templates/apps/web/app/[locale]/thanks/[slug]/page.tsx +0 -39
- package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe-rsc-boundary.test.tsx +0 -226
- package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe.test.tsx +0 -217
- package/templates/apps/web/app/[locale]/unsubscribe/page.tsx +0 -106
- package/templates/apps/web/app/[locale]/unsubscribe/unsubscribe-button.tsx +0 -94
- package/templates/apps/web/app/[locale]/unsubscribe/unsubscribe.actions.ts +0 -55
- package/templates/apps/web/app/[locale]/vs/[slug]/__tests__/page.test.tsx +0 -100
- package/templates/apps/web/app/[locale]/vs/[slug]/page.tsx +0 -60
- package/templates/apps/web/app/[locale]/whitepapers/[slug]/page.tsx +0 -54
- package/templates/apps/web/app/[locale]/whitepapers/__tests__/page-renderer-migration.test.tsx +0 -82
- package/templates/apps/web/app/[locale]/whitepapers/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/working-agreement/__tests__/page.test.tsx +0 -63
- package/templates/apps/web/app/[locale]/working-agreement/page.tsx +0 -41
- package/templates/apps/web/app/api/auth/[...all]/route.ts +0 -16
- package/templates/apps/web/app/api/auth/hub/__tests__/continuation.test.ts +0 -143
- package/templates/apps/web/app/api/auth/hub/__tests__/entry-routes.test.ts +0 -749
- package/templates/apps/web/app/api/auth/hub/authorize/__tests__/route.test.ts +0 -964
- package/templates/apps/web/app/api/auth/hub/authorize/route.ts +0 -390
- package/templates/apps/web/app/api/auth/hub/continuation.ts +0 -127
- package/templates/apps/web/app/api/auth/hub/continue/[ref]/__tests__/route.test.ts +0 -188
- package/templates/apps/web/app/api/auth/hub/continue/[ref]/route.ts +0 -53
- package/templates/apps/web/app/api/auth/hub/email/route.ts +0 -111
- package/templates/apps/web/app/api/auth/hub/entry-shared.ts +0 -163
- package/templates/apps/web/app/api/auth/hub/password/__tests__/return.test.ts +0 -86
- package/templates/apps/web/app/api/auth/hub/password/__tests__/route.test.ts +0 -368
- package/templates/apps/web/app/api/auth/hub/password/return.ts +0 -86
- package/templates/apps/web/app/api/auth/hub/password/route.ts +0 -171
- package/templates/apps/web/app/api/auth/hub/purchase/route.ts +0 -230
- package/templates/apps/web/app/api/auth/hub/purchase-link/route.ts +0 -174
- package/templates/apps/web/app/api/auth/hub/sign-up/route.ts +0 -60
- package/templates/apps/web/app/api/auth/hub/sign-up-evidence.ts +0 -97
- package/templates/apps/web/app/api/auth/mcp/__tests__/continuation.test.ts +0 -92
- package/templates/apps/web/app/api/auth/mcp/continuation.ts +0 -89
- package/templates/apps/web/app/api/auth/mcp/continue/[ref]/__tests__/route.test.ts +0 -59
- package/templates/apps/web/app/api/auth/mcp/continue/[ref]/route.ts +0 -41
- package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +0 -1166
- package/templates/apps/web/app/api/hub-session/callback/route.ts +0 -134
- package/templates/apps/web/app/api/hub-session/email/route.ts +0 -125
- package/templates/apps/web/app/api/hub-session/one-tap/nonce/route.ts +0 -49
- package/templates/apps/web/app/api/hub-session/one-tap/route.ts +0 -106
- package/templates/apps/web/app/api/hub-session/open/route.ts +0 -111
- package/templates/apps/web/app/api/hub-session/password/return/route.ts +0 -69
- package/templates/apps/web/app/api/hub-session/password/route.ts +0 -106
- package/templates/apps/web/app/api/hub-session/sign-in/route.ts +0 -91
- package/templates/apps/web/app/api/hub-session/sign-out/route.ts +0 -54
- package/templates/apps/web/components/sign-out-trigger.tsx +0 -62
- package/templates/apps/web/lib/__tests__/auth-routes.test.ts +0 -140
- package/templates/apps/web/lib/__tests__/hub-children.fixtures.ts +0 -279
- package/templates/apps/web/lib/__tests__/route-family.test.ts +0 -57
- package/templates/apps/web/lib/__tests__/service-listing.test.ts +0 -111
- package/templates/apps/web/lib/__tests__/template-listing.test.ts +0 -158
- package/templates/apps/web/lib/auth-routes.ts +0 -125
- package/templates/apps/web/lib/hub-children.tsx +0 -351
- package/templates/apps/web/lib/hub-session/__tests__/hub-session.test.ts +0 -433
- package/templates/apps/web/lib/hub-session/__tests__/spoke-sign-in.test.tsx +0 -332
- package/templates/apps/web/lib/hub-session/config.ts +0 -110
- package/templates/apps/web/lib/hub-session/entry.ts +0 -238
- package/templates/apps/web/lib/hub-session/index.ts +0 -21
- package/templates/apps/web/lib/hub-session/one-tap.tsx +0 -148
- package/templates/apps/web/lib/hub-session/reseal.ts +0 -90
- package/templates/apps/web/lib/hub-session/seal.ts +0 -86
- package/templates/apps/web/lib/hub-session/session.ts +0 -298
- package/templates/apps/web/lib/hub-session/spoke-sign-in.tsx +0 -277
- package/templates/apps/web/lib/meet-placeholder.ts +0 -5
- package/templates/apps/web/lib/next-path.ts +0 -35
- package/templates/apps/web/lib/posting-title.ts +0 -39
- package/templates/apps/web/lib/route-family.ts +0 -69
- package/templates/apps/web/lib/service-listing.ts +0 -89
- package/templates/apps/web/lib/template-listing.ts +0 -169
- package/templates/apps/web/src/lib/__tests__/lead-write.test.ts +0 -187
- package/templates/apps/web/src/lib/lead-write.ts +0 -90
- /package/templates/apps/web/{app/[locale]/contact → lib}/__tests__/site-contact-lines.test.ts +0 -0
|
@@ -1,390 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The hub's browser step of "sign in through the hub" (#7894, spec
|
|
3
|
-
* docs/specs/7894-the-hub-signs-in-its-spec.md D2, D4).
|
|
4
|
-
*
|
|
5
|
-
* A spoke redirects a visitor here; this route is the one place the person
|
|
6
|
-
* must be signed in on the HUB'S OWN origin, because that is where the Better
|
|
7
|
-
* Auth session cookie lives. It owns no stored artifact: codes and credentials
|
|
8
|
-
* live behind `apps/api` (`POST /v1/hub-sign-in/codes`), reached through
|
|
9
|
-
* `@working-theory/api-client` with the visitor's own cookie.
|
|
10
|
-
*
|
|
11
|
-
* GET /api/auth/hub/authorize
|
|
12
|
-
* ?response_type=code&client_id=…&redirect_uri=…&state=…
|
|
13
|
-
* &code_challenge=…&code_challenge_method=S256
|
|
14
|
-
* [&login_hint=<email>] (optional, #8757 D9 — see below)
|
|
15
|
-
* [&prompt=create] (optional, #9912 D3 — see below)
|
|
16
|
-
*
|
|
17
|
-
* - a malformed query is a 400 and NEVER a redirect;
|
|
18
|
-
* - no Better Auth session: the six validated keys are sealed into a short
|
|
19
|
-
* ref and the answer is a 303 to `/sign-in?next=<the same-origin path
|
|
20
|
-
* /api/auth/hub/continue/<ref>>` (#8146). `resolveNextPath` keeps that
|
|
21
|
-
* path and the existing sign-in card hands it to Better Auth as the
|
|
22
|
-
* callback for Google and for the emailed link alike; the continue route
|
|
23
|
-
* then returns the visitor here. This route's own URL is NOT the callback:
|
|
24
|
-
* Better Auth's magic-link verify decodes a callback twice, which turns the
|
|
25
|
-
* encoded `redirect_uri` inside it into a URL its origin check refuses. A
|
|
26
|
-
* ref longer than `CONTINUATION_REF_MAX` is a 400, never a redirect;
|
|
27
|
-
* - a session: the API mints a single-use code, and this route redirects to
|
|
28
|
-
* the REGISTERED redirect URI the API echoes back, with `code` and the
|
|
29
|
-
* same `state` — never to the query's own `redirect_uri` until the API has
|
|
30
|
-
* confirmed it is the client's;
|
|
31
|
-
* - a person who has not said yes to this spoke (403 `consent_required`,
|
|
32
|
-
* #9966 D2) goes to the hub's own consent page, `/account/connect?ref=…`,
|
|
33
|
-
* with the six keys sealed as the no-session branch seals them. The GET
|
|
34
|
-
* never sends `consent`: a spoke can send a visitor here on page load, so
|
|
35
|
-
* a GET must never be the yes;
|
|
36
|
-
* - a person whose email is not verified (403 `email_unverified`) goes to the
|
|
37
|
-
* hub's own `/account/settings`, whose For-you item says how to verify —
|
|
38
|
-
* never to the spoke;
|
|
39
|
-
* - any other refusal is a 400 with `{ "error": "invalid_request" }` and no
|
|
40
|
-
* visitor copy: only a misconfigured client reaches it.
|
|
41
|
-
*
|
|
42
|
-
* `login_hint` (#8757 D9) is optional and read beside the six keys with
|
|
43
|
-
* `accountEmailHintSchema` (`hubAuthorizeQuerySchema` is unchanged): repeated
|
|
44
|
-
* → 400 like any repeated key; refused → dropped. It acts only on the
|
|
45
|
-
* no-session branch, as the sign-in page's `email`, so the form opens with the
|
|
46
|
-
* address typed. It never enters the ref, a code or a cookie — the continue
|
|
47
|
-
* route rebuilds the query from the ref, so the hint is gone after sign-in —
|
|
48
|
-
* and with a session it is ignored.
|
|
49
|
-
*
|
|
50
|
-
* `prompt=create` (#9912 D3) is the spoke's "Sign up": read beside
|
|
51
|
-
* `login_hint` by the same once-only rule (repeated → 400, before the session
|
|
52
|
-
* read). On the no-session branch exactly `create` sends the visitor to
|
|
53
|
-
* `/sign-up?next=<the same continue path>` instead of `/sign-in`, with no
|
|
54
|
-
* `email`; any other value does nothing. It never enters the ref — so a
|
|
55
|
-
* password sign-up, which ends with no session, comes back through the
|
|
56
|
-
* continuation to `/sign-in` — nor a code or a cookie, and with a session it
|
|
57
|
-
* is ignored: the person has an account, and the spoke signs them in.
|
|
58
|
-
*
|
|
59
|
-
* `provider_hint=google` (#11096 D4) is the spoke's "Continue with Google":
|
|
60
|
-
* read by the same once-only rule (repeated → 400, before the session read).
|
|
61
|
-
* On the no-session branch, exactly `google` with Google an active provider
|
|
62
|
-
* calls `auth.api.signInSocial` with the continue path as its callback and
|
|
63
|
-
* answers a 303 straight to Google, carrying every `Set-Cookie` the call
|
|
64
|
-
* returned (Better Auth's state cookie) — no sign-in card renders. Any other
|
|
65
|
-
* value, Google off, or a call that throws or answers no URL falls back to
|
|
66
|
-
* the redirect above. With a session it is ignored; with it, `prompt` and
|
|
67
|
-
* `login_hint` are ignored.
|
|
68
|
-
*
|
|
69
|
-
* POST /api/auth/hub/authorize (form field `ref`, #9966 D2)
|
|
70
|
-
*
|
|
71
|
-
* - the consent page's Continue. Accepted only with `Sec-Fetch-Site:
|
|
72
|
-
* same-origin` and an `Origin` equal to the pinned origin (a missing or
|
|
73
|
-
* `null` Origin is refused), before any session read; the ref is opened
|
|
74
|
-
* and its query re-validated, and the session branch runs as GET's does,
|
|
75
|
-
* with `consent: true` — and `x-internal-auth` where the API requires it —
|
|
76
|
-
* on the code request. This is the one call site that sends consent.
|
|
77
|
-
* Its success is a 200 page that navigates to the spoke, never a 303:
|
|
78
|
-
* Chrome holds a form submission's redirects to the hub's own
|
|
79
|
-
* `form-action 'self'`, so a 303 to the spoke is blocked and the person
|
|
80
|
-
* stays on the consent page with a console error (#11091).
|
|
81
|
-
*
|
|
82
|
-
* `BETTER_AUTH_URL` pins the `Origin` sent with the cookie-authenticated write
|
|
83
|
-
* (Node's `fetch` sets none). Unset, the step answers 503: it needs a pinned
|
|
84
|
-
* origin, exactly as the emailed link does.
|
|
85
|
-
*
|
|
86
|
-
* This is the second api-shaped route under `apps/web/app/api/auth/`, beside
|
|
87
|
-
* Better Auth's catch-all; it sits under `app/api/auth`, a spoke removal seed
|
|
88
|
-
* (spec 7426 D4), so no spoke ever carries it. Nothing here logs a code, a
|
|
89
|
-
* state, a challenge or a cookie.
|
|
90
|
-
*/
|
|
91
|
-
import { hubSignIn } from "@working-theory/api-client";
|
|
92
|
-
import {
|
|
93
|
-
accountEmailHintSchema,
|
|
94
|
-
hubAuthorizeQuerySchema,
|
|
95
|
-
type HubAuthorizeQuery,
|
|
96
|
-
} from "@working-theory/validation";
|
|
97
|
-
|
|
98
|
-
import { auth, resolveSecret } from "../../../../../auth";
|
|
99
|
-
import { browserApiOrigin } from "../../../../../lib/api-origin.generated";
|
|
100
|
-
import { getActiveProviderIds } from "../../../../../lib/auth-env";
|
|
101
|
-
import { TOPOLOGY } from "../../../../../lib/topology.generated";
|
|
102
|
-
import {
|
|
103
|
-
AUTHORIZE_QUERY_KEYS as QUERY_KEYS,
|
|
104
|
-
CONTINUE_PATH,
|
|
105
|
-
openContinuation,
|
|
106
|
-
pinnedOrigin,
|
|
107
|
-
sealQuery,
|
|
108
|
-
} from "../continuation";
|
|
109
|
-
|
|
110
|
-
/** Where an unverified person is sent to verify: the hub's own account page. */
|
|
111
|
-
const VERIFY_EMAIL_PATH = "/account/settings";
|
|
112
|
-
|
|
113
|
-
/** The hub's consent page, where a person says yes to one spoke (#9966 D2). */
|
|
114
|
-
const CONSENT_PATH = "/account/connect";
|
|
115
|
-
|
|
116
|
-
const LOOPBACK_HOSTS = new Set(["localhost", "127.0.0.1"]);
|
|
117
|
-
|
|
118
|
-
function json(status: number, error: string): Response {
|
|
119
|
-
return new Response(JSON.stringify({ error }), {
|
|
120
|
-
status,
|
|
121
|
-
headers: {
|
|
122
|
-
"Content-Type": "application/json",
|
|
123
|
-
"Cache-Control": "no-store",
|
|
124
|
-
},
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/** A 303 whose target may be a same-origin path or an absolute spoke URL. */
|
|
129
|
-
function see(location: string): Response {
|
|
130
|
-
return new Response(null, {
|
|
131
|
-
status: 303,
|
|
132
|
-
headers: {
|
|
133
|
-
Location: location,
|
|
134
|
-
"Cache-Control": "no-store",
|
|
135
|
-
// The code rides this URL; no page may leak it through a Referer.
|
|
136
|
-
"Referrer-Policy": "no-referrer",
|
|
137
|
-
},
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/** `&`, `<`, `>`, `"` and `'` as entities, so a URL sits safely in an attribute. */
|
|
142
|
-
function escapeHtml(value: string): string {
|
|
143
|
-
return value
|
|
144
|
-
.replace(/&/g, "&")
|
|
145
|
-
.replace(/</g, "<")
|
|
146
|
-
.replace(/>/g, ">")
|
|
147
|
-
.replace(/"/g, """)
|
|
148
|
-
.replace(/'/g, "'");
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* The consent POST's success: a 200 page that navigates to the spoke. A 303
|
|
153
|
-
* here is what Chrome blocks under the hub's `form-action 'self'` (#11091);
|
|
154
|
-
* a meta refresh and a link are navigations, which that directive never
|
|
155
|
-
* governs. The code rides the URL, so the page is `no-store` and sends no
|
|
156
|
-
* referrer.
|
|
157
|
-
*/
|
|
158
|
-
function arrive(location: string): Response {
|
|
159
|
-
const href = escapeHtml(location);
|
|
160
|
-
const html =
|
|
161
|
-
`<!doctype html><html lang="en"><head><meta charset="utf-8">` +
|
|
162
|
-
`<meta name="referrer" content="no-referrer">` +
|
|
163
|
-
`<meta http-equiv="refresh" content="0;url=${href}">` +
|
|
164
|
-
`<title>Signing you in</title></head>` +
|
|
165
|
-
`<body><p><a href="${href}">Continue</a></p></body></html>`;
|
|
166
|
-
return new Response(html, {
|
|
167
|
-
status: 200,
|
|
168
|
-
headers: {
|
|
169
|
-
"Content-Type": "text/html; charset=utf-8",
|
|
170
|
-
"Cache-Control": "no-store",
|
|
171
|
-
"Referrer-Policy": "no-referrer",
|
|
172
|
-
},
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* #11096 D4 — straight to Google for the continue path, or `null` to fall
|
|
178
|
-
* back to the sign-in card. The 303 carries every `Set-Cookie` the call
|
|
179
|
-
* returned: Better Auth's state cookie is what its callback checks.
|
|
180
|
-
*/
|
|
181
|
-
async function googleRedirect(
|
|
182
|
-
request: Request,
|
|
183
|
-
continuePath: string,
|
|
184
|
-
): Promise<Response | null> {
|
|
185
|
-
if (!getActiveProviderIds().includes("google")) return null;
|
|
186
|
-
try {
|
|
187
|
-
const { headers, response } = await auth.api.signInSocial({
|
|
188
|
-
body: {
|
|
189
|
-
provider: "google",
|
|
190
|
-
callbackURL: continuePath,
|
|
191
|
-
errorCallbackURL: `/sign-in?${new URLSearchParams({ next: continuePath }).toString()}`,
|
|
192
|
-
},
|
|
193
|
-
headers: request.headers,
|
|
194
|
-
returnHeaders: true,
|
|
195
|
-
});
|
|
196
|
-
const url = (response as { url?: unknown } | undefined)?.url;
|
|
197
|
-
if (typeof url !== "string" || !url.startsWith("https://")) return null;
|
|
198
|
-
const res = see(url);
|
|
199
|
-
for (const cookie of headers.getSetCookie()) {
|
|
200
|
-
res.headers.append("Set-Cookie", cookie);
|
|
201
|
-
}
|
|
202
|
-
return res;
|
|
203
|
-
} catch {
|
|
204
|
-
return null;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* `x-internal-auth` for the consent-bearing code request, under the Offerings
|
|
210
|
-
* buy route's `startHeaders` rule: only from a site that is not a spoke, and
|
|
211
|
-
* only to an `https:` or loopback API, so the secret never crosses a plain
|
|
212
|
-
* network hop. The API honours `consent: true` only beside it where it is set.
|
|
213
|
-
*/
|
|
214
|
-
function internalAuthHeader(): Record<string, string> {
|
|
215
|
-
const secret = process.env.OSS_API_INTERNAL_SECRET;
|
|
216
|
-
// The topology alone says "spoke" (#10941). A hub also holds a spoke key —
|
|
217
|
-
// its own, for server-side reads — and reading that key as "this site is a
|
|
218
|
-
// spoke" dropped the header on the one site that mints codes, so no consent
|
|
219
|
-
// ever completed.
|
|
220
|
-
const spoke = TOPOLOGY === "spoke";
|
|
221
|
-
if (!secret || spoke) return {};
|
|
222
|
-
try {
|
|
223
|
-
const api = new URL(
|
|
224
|
-
process.env.AILK_API_URL ||
|
|
225
|
-
browserApiOrigin() ||
|
|
226
|
-
process.env.NEXT_PUBLIC_API_URL ||
|
|
227
|
-
"http://localhost:3001",
|
|
228
|
-
);
|
|
229
|
-
const safe = api.protocol === "https:" || LOOPBACK_HOSTS.has(api.hostname);
|
|
230
|
-
return safe ? { "x-internal-auth": secret } : {};
|
|
231
|
-
} catch {
|
|
232
|
-
return {};
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* The session branch, shared by GET and the consent POST: ask the API for a
|
|
238
|
-
* code and answer with where the visitor goes next. Only the POST passes
|
|
239
|
-
* `consent` (#9966 D2).
|
|
240
|
-
*/
|
|
241
|
-
async function codeRedirect(
|
|
242
|
-
request: Request,
|
|
243
|
-
query: HubAuthorizeQuery,
|
|
244
|
-
consent: boolean,
|
|
245
|
-
): Promise<Response> {
|
|
246
|
-
const origin = pinnedOrigin();
|
|
247
|
-
if (origin === null) return json(503, "temporarily_unavailable");
|
|
248
|
-
|
|
249
|
-
let result: Awaited<ReturnType<typeof hubSignIn.createCode>>;
|
|
250
|
-
try {
|
|
251
|
-
result = await hubSignIn.createCode(
|
|
252
|
-
{
|
|
253
|
-
clientId: query.client_id,
|
|
254
|
-
redirectUri: query.redirect_uri,
|
|
255
|
-
codeChallenge: query.code_challenge,
|
|
256
|
-
...(consent ? { consent: true as const } : {}),
|
|
257
|
-
},
|
|
258
|
-
{
|
|
259
|
-
headers: {
|
|
260
|
-
cookie: request.headers.get("cookie") ?? "",
|
|
261
|
-
origin,
|
|
262
|
-
...(consent ? internalAuthHeader() : {}),
|
|
263
|
-
},
|
|
264
|
-
},
|
|
265
|
-
);
|
|
266
|
-
} catch {
|
|
267
|
-
return json(503, "temporarily_unavailable");
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
if (result.ok) {
|
|
271
|
-
// Redirect to the URI the API confirmed is registered for this client.
|
|
272
|
-
let target: URL;
|
|
273
|
-
try {
|
|
274
|
-
target = new URL(result.body.redirectUri);
|
|
275
|
-
} catch {
|
|
276
|
-
// A registered URI is validated at registration; an unparseable echo is
|
|
277
|
-
// a server fault, never something to redirect to.
|
|
278
|
-
return json(503, "temporarily_unavailable");
|
|
279
|
-
}
|
|
280
|
-
target.searchParams.set("code", result.body.code);
|
|
281
|
-
target.searchParams.set("state", query.state);
|
|
282
|
-
if (!consent) return see(target.toString());
|
|
283
|
-
// The navigating page is markup, so it is built only for the schemes
|
|
284
|
-
// registration admits (#11095 D10, #11094); the GET's 303 is a header.
|
|
285
|
-
const safe =
|
|
286
|
-
target.protocol === "https:" ||
|
|
287
|
-
(target.protocol === "http:" && LOOPBACK_HOSTS.has(target.hostname));
|
|
288
|
-
if (!safe) return json(503, "temporarily_unavailable");
|
|
289
|
-
return arrive(target.toString());
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
const code = (result.body as { error?: { code?: unknown } } | null)?.error
|
|
293
|
-
?.code;
|
|
294
|
-
if (result.status === 403 && code === "email_unverified") {
|
|
295
|
-
return see(VERIFY_EMAIL_PATH);
|
|
296
|
-
}
|
|
297
|
-
// Not yet said yes to this spoke: ask, on the hub's own page. The POST that
|
|
298
|
-
// page sends already carries consent, so it never comes back here.
|
|
299
|
-
if (!consent && result.status === 403 && code === "consent_required") {
|
|
300
|
-
const ref = sealQuery(query, resolveSecret());
|
|
301
|
-
if (ref === null) return json(400, "invalid_request");
|
|
302
|
-
return see(`${CONSENT_PATH}?${new URLSearchParams({ ref }).toString()}`);
|
|
303
|
-
}
|
|
304
|
-
return json(400, "invalid_request");
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
// platform-decisions-waiver: api-versioning — sign-in redirect endpoint, not a versioned API contract (spec 7894 §7)
|
|
308
|
-
export async function GET(request: Request): Promise<Response> {
|
|
309
|
-
const url = new URL(request.url);
|
|
310
|
-
|
|
311
|
-
// Each declared key exactly once: a repeated key is ambiguous, so 400.
|
|
312
|
-
const raw: Record<string, string | undefined> = {};
|
|
313
|
-
for (const key of QUERY_KEYS) {
|
|
314
|
-
const values = url.searchParams.getAll(key);
|
|
315
|
-
if (values.length > 1) return json(400, "invalid_request");
|
|
316
|
-
raw[key] = values[0];
|
|
317
|
-
}
|
|
318
|
-
// #8757 D9 — the optional hint: the same once-only rule; refused → dropped.
|
|
319
|
-
const hints = url.searchParams.getAll("login_hint");
|
|
320
|
-
if (hints.length > 1) return json(400, "invalid_request");
|
|
321
|
-
// #9912 D3 — the sign-up hint, by the same rule; only `create` acts.
|
|
322
|
-
const prompts = url.searchParams.getAll("prompt");
|
|
323
|
-
if (prompts.length > 1) return json(400, "invalid_request");
|
|
324
|
-
// #11096 D4 — the Google hint, by the same rule; only `google` acts.
|
|
325
|
-
const providerHints = url.searchParams.getAll("provider_hint");
|
|
326
|
-
if (providerHints.length > 1) return json(400, "invalid_request");
|
|
327
|
-
const parsed = hubAuthorizeQuerySchema.safeParse(raw);
|
|
328
|
-
if (!parsed.success) return json(400, "invalid_request");
|
|
329
|
-
const query = parsed.data;
|
|
330
|
-
const hint = accountEmailHintSchema.safeParse(hints[0]);
|
|
331
|
-
|
|
332
|
-
const session = await auth.api.getSession({ headers: request.headers });
|
|
333
|
-
if (!session) {
|
|
334
|
-
const ref = sealQuery(query, resolveSecret());
|
|
335
|
-
if (ref === null) return json(400, "invalid_request");
|
|
336
|
-
if (providerHints[0] === "google") {
|
|
337
|
-
const google = await googleRedirect(request, `${CONTINUE_PATH}/${ref}`);
|
|
338
|
-
if (google) return google;
|
|
339
|
-
}
|
|
340
|
-
const signIn = new URLSearchParams({ next: `${CONTINUE_PATH}/${ref}` });
|
|
341
|
-
if (prompts[0] === "create") return see(`/sign-up?${signIn.toString()}`);
|
|
342
|
-
if (hint.success) signIn.set("email", hint.data);
|
|
343
|
-
return see(`/sign-in?${signIn.toString()}`);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
return codeRedirect(request, query, false);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* The consent page's Continue (#9966 D2): the one request that says yes to a
|
|
351
|
-
* spoke. Same-origin only, decided before any session read, so neither a
|
|
352
|
-
* cross-site form nor a sandboxed frame (`Origin: null`) can post it.
|
|
353
|
-
*/
|
|
354
|
-
export async function POST(request: Request): Promise<Response> {
|
|
355
|
-
const origin = pinnedOrigin();
|
|
356
|
-
if (origin === null) return json(503, "temporarily_unavailable");
|
|
357
|
-
const sent = request.headers.get("origin");
|
|
358
|
-
if (
|
|
359
|
-
request.headers.get("sec-fetch-site") !== "same-origin" ||
|
|
360
|
-
sent === null ||
|
|
361
|
-
sent !== origin
|
|
362
|
-
) {
|
|
363
|
-
return json(403, "invalid_request");
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
let refs: FormDataEntryValue[];
|
|
367
|
-
try {
|
|
368
|
-
refs = (await request.formData()).getAll("ref");
|
|
369
|
-
} catch {
|
|
370
|
-
return json(400, "invalid_request");
|
|
371
|
-
}
|
|
372
|
-
const [ref] = refs;
|
|
373
|
-
if (refs.length !== 1 || typeof ref !== "string") {
|
|
374
|
-
return json(400, "invalid_request");
|
|
375
|
-
}
|
|
376
|
-
const search = openContinuation(ref, resolveSecret());
|
|
377
|
-
if (search === null) return json(400, "invalid_request");
|
|
378
|
-
const params = new URLSearchParams(search);
|
|
379
|
-
const raw: Record<string, string | undefined> = {};
|
|
380
|
-
for (const key of QUERY_KEYS) raw[key] = params.get(key) ?? undefined;
|
|
381
|
-
const parsed = hubAuthorizeQuerySchema.safeParse(raw);
|
|
382
|
-
if (!parsed.success) return json(400, "invalid_request");
|
|
383
|
-
|
|
384
|
-
const session = await auth.api.getSession({ headers: request.headers });
|
|
385
|
-
if (!session) {
|
|
386
|
-
const signIn = new URLSearchParams({ next: `${CONTINUE_PATH}/${ref}` });
|
|
387
|
-
return see(`/sign-in?${signIn.toString()}`);
|
|
388
|
-
}
|
|
389
|
-
return codeRedirect(request, parsed.data, true);
|
|
390
|
-
}
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The hub's sign-in continuation (#8146, spec
|
|
3
|
-
* docs/specs/8146-email-link-sign-in-from-spec.md D2, D3).
|
|
4
|
-
*
|
|
5
|
-
* Better Auth's magic-link verify decodes `callbackURL` a second time, so a
|
|
6
|
-
* callback that holds an encoded `redirect_uri` is refused as
|
|
7
|
-
* INVALID_CALLBACK_URL. The authorize step therefore does not hand the sign-in
|
|
8
|
-
* page its own URL. It seals the validated authorize query into a short,
|
|
9
|
-
* opaque ref and hands over the same-origin path `/api/auth/hub/continue/<ref>`
|
|
10
|
-
* instead. A base64url string has no `%`, `?`, `&`, `=` or `:`, so no number of
|
|
11
|
-
* decodes changes it.
|
|
12
|
-
*
|
|
13
|
-
* Sealed (AES-256-GCM, key derived from the caller's secret under its own
|
|
14
|
-
* purpose), with its expiry inside. The ref is opaque but is NOT a secret: it
|
|
15
|
-
* carries what the cleartext `next` carried before (spec § 9 SEC-8146-1).
|
|
16
|
-
* Nothing here logs a ref.
|
|
17
|
-
*
|
|
18
|
-
* #11096: `sealQuery` and `pinnedOrigin` live here so every hub web route
|
|
19
|
-
* under `api/auth/hub/` seals the same six keys and pins the same origin, and
|
|
20
|
-
* `mintContinuation` takes an optional life so a purchase claim (sealed under
|
|
21
|
-
* its own name, `hub-purchase`) can outlive the 600 s a continuation needs.
|
|
22
|
-
*/
|
|
23
|
-
import type { HubAuthorizeQuery } from "@working-theory/validation";
|
|
24
|
-
|
|
25
|
-
import { seal, unseal } from "../../../../lib/hub-session/seal";
|
|
26
|
-
|
|
27
|
-
/** The same-origin path a ref is appended to. */
|
|
28
|
-
export const CONTINUE_PATH = "/api/auth/hub/continue";
|
|
29
|
-
|
|
30
|
-
/** The longest ref the authorize step will mint, and the continue route open. */
|
|
31
|
-
export const CONTINUATION_REF_MAX = 4096;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* 600 s, matching the spoke's flow cookie: a longer life is useless (the spoke
|
|
35
|
-
* refuses the callback once its flow expires) and it covers the 300 s emailed
|
|
36
|
-
* link plus time on the sign-in page.
|
|
37
|
-
*/
|
|
38
|
-
export const CONTINUATION_TTL_SECONDS = 600;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* A fixed name: a value sealed for a cookie never opens here, nor the reverse.
|
|
42
|
-
* The MCP sign-in leg seals under its own name (`../mcp/continuation.ts`).
|
|
43
|
-
*/
|
|
44
|
-
const AAD = "hub-continue";
|
|
45
|
-
|
|
46
|
-
const BASE64URL = /^[A-Za-z0-9_-]+$/;
|
|
47
|
-
|
|
48
|
-
/** The authorize step's six keys, in the order every ref carries them. */
|
|
49
|
-
export const AUTHORIZE_QUERY_KEYS = [
|
|
50
|
-
"response_type",
|
|
51
|
-
"client_id",
|
|
52
|
-
"redirect_uri",
|
|
53
|
-
"state",
|
|
54
|
-
"code_challenge",
|
|
55
|
-
"code_challenge_method",
|
|
56
|
-
] as const;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* `search` (the canonical authorize query, no leading `?`) as a sealed ref.
|
|
60
|
-
* `ttlSeconds` defaults to a continuation's 600 s (#11096 D9's claim passes
|
|
61
|
-
* its 72 hours).
|
|
62
|
-
*/
|
|
63
|
-
export function mintContinuation(
|
|
64
|
-
search: string,
|
|
65
|
-
secret: string,
|
|
66
|
-
now: number = Date.now(),
|
|
67
|
-
name: string = AAD,
|
|
68
|
-
ttlSeconds: number = CONTINUATION_TTL_SECONDS,
|
|
69
|
-
): string {
|
|
70
|
-
return seal(
|
|
71
|
-
{ v: 1, q: search, exp: now + ttlSeconds * 1000 },
|
|
72
|
-
secret,
|
|
73
|
-
"continue",
|
|
74
|
-
name,
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* The six validated keys as a sealed continuation ref, or `null` past the
|
|
80
|
-
* cap. Only the six keys, in `AUTHORIZE_QUERY_KEYS` order: a ref carries
|
|
81
|
-
* nothing that did not pass the schema, and extra or reordered keys are
|
|
82
|
-
* dropped.
|
|
83
|
-
*/
|
|
84
|
-
export function sealQuery(
|
|
85
|
-
query: HubAuthorizeQuery,
|
|
86
|
-
secret: string,
|
|
87
|
-
): string | null {
|
|
88
|
-
const canonical = new URLSearchParams();
|
|
89
|
-
for (const key of AUTHORIZE_QUERY_KEYS) canonical.set(key, query[key]);
|
|
90
|
-
const ref = mintContinuation(canonical.toString(), secret);
|
|
91
|
-
return ref.length > CONTINUATION_REF_MAX ? null : ref;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/** The pinned origin of the hub's own web app, or `null` when unset/invalid. */
|
|
95
|
-
export function pinnedOrigin(): string | null {
|
|
96
|
-
const raw = process.env.BETTER_AUTH_URL;
|
|
97
|
-
if (!raw) return null;
|
|
98
|
-
try {
|
|
99
|
-
return new URL(raw).origin;
|
|
100
|
-
} catch {
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* The authorize query a ref holds, or `null` when the ref is too long, is not
|
|
107
|
-
* base64url, does not open, is not the expected shape, or has expired.
|
|
108
|
-
*
|
|
109
|
-
* The query is re-serialized through `URLSearchParams`: for what
|
|
110
|
-
* `mintContinuation` wrote that is the same string, and for a `q` forged under
|
|
111
|
-
* a known secret it percent-encodes CR/LF so a `Location` can never be split
|
|
112
|
-
* and never throws (spec § 9 SEC-8146-7).
|
|
113
|
-
*/
|
|
114
|
-
export function openContinuation(
|
|
115
|
-
ref: string,
|
|
116
|
-
secret: string,
|
|
117
|
-
now: number = Date.now(),
|
|
118
|
-
name: string = AAD,
|
|
119
|
-
): string | null {
|
|
120
|
-
if (ref.length > CONTINUATION_REF_MAX || !BASE64URL.test(ref)) return null;
|
|
121
|
-
const value = unseal(ref, secret, "continue", name);
|
|
122
|
-
if (typeof value !== "object" || value === null) return null;
|
|
123
|
-
const { v, q, exp } = value as Record<string, unknown>;
|
|
124
|
-
if (v !== 1 || typeof q !== "string" || q === "") return null;
|
|
125
|
-
if (typeof exp !== "number" || exp <= now) return null;
|
|
126
|
-
return new URLSearchParams(q).toString();
|
|
127
|
-
}
|