@wix/agent-skills 1.19.2 → 1.20.1

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.
Files changed (215) hide show
  1. package/package.json +1 -1
  2. package/skills/wix-app/references/SERVICE_PLUGIN.md +14 -1
  3. package/skills/wix-app/references/editor-react-component/ANIMATED-COMPONENTS.md +7 -6
  4. package/skills/wix-app/references/service-plugin/ADDITIONAL-FEES.md +4 -0
  5. package/skills/wix-app/references/service-plugin/AVAILABILITY-TIME-SLOTS-CONFIGURATION.md +118 -0
  6. package/skills/wix-app/references/service-plugin/BOOKING-POLICY.md +65 -0
  7. package/skills/wix-app/references/service-plugin/BOOKINGS-PRICING.md +71 -0
  8. package/skills/wix-app/references/service-plugin/BOOKINGS-STAFF-SORTING.md +11 -3
  9. package/skills/wix-app/references/service-plugin/BOOKINGS-VALIDATION.md +137 -0
  10. package/skills/wix-app/references/service-plugin/DISCOUNT-TRIGGERS.md +23 -16
  11. package/skills/wix-app/references/service-plugin/GIFT-CARDS.md +4 -0
  12. package/skills/wix-app/references/service-plugin/PAYMENT-SETTINGS.md +4 -2
  13. package/skills/wix-app/references/service-plugin/REALTIME-PERMISSIONS.md +45 -0
  14. package/skills/wix-app/references/service-plugin/SHIPPING-RATES.md +15 -0
  15. package/skills/wix-app/references/service-plugin/TOOLS_PROVIDER.md +4 -0
  16. package/skills/wix-app/references/service-plugin/VALIDATIONS.md +4 -0
  17. package/skills/wix-headless/references/CAPABILITIES.md +2 -2
  18. package/skills/wix-headless/references/inline-recipes/experience-store.md +4 -3
  19. package/skills/wix-headless/references/inline-recipes/how-to-code-a-store.md +98 -18
  20. package/skills/wix-headless/references/managed/DEPLOYMENT.md +8 -8
  21. package/skills/wix-headless-fast/SKILL.md +200 -34
  22. package/skills/wix-headless-fast/entry/skill.md +10 -2
  23. package/skills/wix-headless-fast/install/attach.mjs +253 -0
  24. package/skills/wix-headless-fast/install/deploy.mjs +109 -9
  25. package/skills/wix-headless-fast/install/fast-path.mjs +28 -31
  26. package/skills/wix-headless-fast/references/blog/INSTRUCTIONS.md +224 -60
  27. package/skills/wix-headless-fast/references/blog/app/components/blog/BlogFeedView.tsx +2 -3
  28. package/skills/wix-headless-fast/references/blog/app/components/blog/PostView.tsx +2 -3
  29. package/skills/wix-headless-fast/references/blog/app/hooks/blog/useBlogFeed.ts +24 -116
  30. package/skills/wix-headless-fast/references/blog/app/hooks/blog/usePost.ts +16 -64
  31. package/skills/wix-headless-fast/references/blog/app/wix/blog/blog-feed-store.ts +137 -0
  32. package/skills/wix-headless-fast/references/blog/app/wix/blog/post-store.ts +78 -0
  33. package/skills/wix-headless-fast/references/blog/app/wix/blog/posts-core.ts +117 -0
  34. package/skills/wix-headless-fast/references/blog/app/wix/blog/posts.ts +13 -60
  35. package/skills/wix-headless-fast/references/blog/app/wix/blog/taxonomy-core.ts +47 -0
  36. package/skills/wix-headless-fast/references/blog/app/wix/blog/taxonomy.ts +10 -28
  37. package/skills/wix-headless-fast/references/blog/app-astro/pages/blog/[...slug].astro +2 -4
  38. package/skills/wix-headless-fast/references/blog/rest/posts.ts +42 -0
  39. package/skills/wix-headless-fast/references/blog/rest/taxonomy.ts +62 -0
  40. package/skills/wix-headless-fast/references/blog/seed/SEED.md +9 -0
  41. package/skills/wix-headless-fast/references/bookings/INSTRUCTIONS.md +179 -33
  42. package/skills/wix-headless-fast/references/bookings/app/components/bookings/ServiceBookingView.tsx +2 -1
  43. package/skills/wix-headless-fast/references/bookings/app/hooks/bookings/useBookingFlow.ts +26 -132
  44. package/skills/wix-headless-fast/references/bookings/app/hooks/bookings/useServices.ts +18 -49
  45. package/skills/wix-headless-fast/references/bookings/app/wix/bookings/booking-core.ts +218 -0
  46. package/skills/wix-headless-fast/references/bookings/app/wix/bookings/booking-flow-store.ts +169 -0
  47. package/skills/wix-headless-fast/references/bookings/app/wix/bookings/booking.ts +57 -142
  48. package/skills/wix-headless-fast/references/bookings/app/wix/bookings/services-core.ts +92 -0
  49. package/skills/wix-headless-fast/references/bookings/app/wix/bookings/services-store.ts +90 -0
  50. package/skills/wix-headless-fast/references/bookings/app/wix/bookings/services.ts +22 -61
  51. package/skills/wix-headless-fast/references/bookings/app/wix/bookings/types.ts +3 -1
  52. package/skills/wix-headless-fast/references/bookings/rest/booking.ts +113 -0
  53. package/skills/wix-headless-fast/references/bookings/rest/services.ts +55 -0
  54. package/skills/wix-headless-fast/references/bookings/seed/SEED.md +10 -0
  55. package/skills/wix-headless-fast/references/cms/INSTRUCTIONS.md +236 -62
  56. package/skills/wix-headless-fast/references/cms/app/hooks/cms/useCollection.ts +19 -52
  57. package/skills/wix-headless-fast/references/cms/app/hooks/cms/useItem.ts +16 -36
  58. package/skills/wix-headless-fast/references/cms/app/wix/cms/collection-store.ts +158 -0
  59. package/skills/wix-headless-fast/references/cms/app/wix/cms/item-store.ts +93 -0
  60. package/skills/wix-headless-fast/references/cms/app/wix/cms/items-core.ts +177 -0
  61. package/skills/wix-headless-fast/references/cms/app/wix/cms/items.ts +13 -41
  62. package/skills/wix-headless-fast/references/cms/rest/items.ts +125 -0
  63. package/skills/wix-headless-fast/references/cms/seed/SEED.md +9 -0
  64. package/skills/wix-headless-fast/references/events/INSTRUCTIONS.md +239 -83
  65. package/skills/wix-headless-fast/references/events/app/components/events/EventConfirmationView.tsx +1 -1
  66. package/skills/wix-headless-fast/references/events/app/components/events/EventRegistrationView.tsx +7 -5
  67. package/skills/wix-headless-fast/references/events/app/components/events/EventsView.tsx +2 -2
  68. package/skills/wix-headless-fast/references/events/app/hooks/events/useEventRegistration.ts +28 -110
  69. package/skills/wix-headless-fast/references/events/app/hooks/events/useEvents.ts +19 -54
  70. package/skills/wix-headless-fast/references/events/app/wix/events/events-core.ts +130 -0
  71. package/skills/wix-headless-fast/references/events/app/wix/events/events-store.ts +97 -0
  72. package/skills/wix-headless-fast/references/events/app/wix/events/events.ts +13 -94
  73. package/skills/wix-headless-fast/references/events/app/wix/events/registration-core.ts +113 -0
  74. package/skills/wix-headless-fast/references/events/app/wix/events/registration-store.ts +156 -0
  75. package/skills/wix-headless-fast/references/events/app/wix/events/registration.ts +38 -69
  76. package/skills/wix-headless-fast/references/events/rest/events.ts +57 -0
  77. package/skills/wix-headless-fast/references/events/rest/registration.ts +83 -0
  78. package/skills/wix-headless-fast/references/events/seed/SEED.md +9 -0
  79. package/skills/wix-headless-fast/references/forms/INSTRUCTIONS.md +214 -26
  80. package/skills/wix-headless-fast/references/forms/app/hooks/forms/useWixForm.ts +35 -267
  81. package/skills/wix-headless-fast/references/forms/app/wix/forms/form-store.ts +332 -0
  82. package/skills/wix-headless-fast/references/forms/app/wix/forms/forms-core.ts +238 -0
  83. package/skills/wix-headless-fast/references/forms/app/wix/forms/forms.ts +28 -243
  84. package/skills/wix-headless-fast/references/forms/app/wix/forms/submissions-core.ts +216 -0
  85. package/skills/wix-headless-fast/references/forms/app/wix/forms/submissions.ts +32 -204
  86. package/skills/wix-headless-fast/references/forms/rest/forms.ts +34 -0
  87. package/skills/wix-headless-fast/references/forms/rest/submissions.ts +56 -0
  88. package/skills/wix-headless-fast/references/forms/seed/SEED.md +8 -0
  89. package/skills/wix-headless-fast/references/forms/seed/seed-forms.mjs +15 -8
  90. package/skills/wix-headless-fast/references/members/INSTRUCTIONS.md +314 -63
  91. package/skills/wix-headless-fast/references/members/app/components/members/LoginForm.tsx +1 -1
  92. package/skills/wix-headless-fast/references/members/app/wix/members/auth-core.ts +105 -0
  93. package/skills/wix-headless-fast/references/members/app/wix/members/auth.ts +36 -65
  94. package/skills/wix-headless-fast/references/members/app/wix/members/client.ts +1 -1
  95. package/skills/wix-headless-fast/references/members/app/wix/members/members-core.ts +43 -0
  96. package/skills/wix-headless-fast/references/members/app/wix/members/members.ts +11 -32
  97. package/skills/wix-headless-fast/references/members/rest/auth.ts +215 -0
  98. package/skills/wix-headless-fast/references/members/rest/members.ts +26 -0
  99. package/skills/wix-headless-fast/references/portfolio/INSTRUCTIONS.md +238 -59
  100. package/skills/wix-headless-fast/references/portfolio/app/components/portfolio/CollectionProjectsView.tsx +2 -2
  101. package/skills/wix-headless-fast/references/portfolio/app/components/portfolio/CollectionsView.tsx +2 -2
  102. package/skills/wix-headless-fast/references/portfolio/app/components/portfolio/GalleryMedia.tsx +35 -0
  103. package/skills/wix-headless-fast/references/portfolio/app/components/portfolio/ProjectDetailView.tsx +8 -38
  104. package/skills/wix-headless-fast/references/portfolio/app/hooks/portfolio/useCollectionProjects.ts +23 -50
  105. package/skills/wix-headless-fast/references/portfolio/app/hooks/portfolio/useCollections.ts +16 -34
  106. package/skills/wix-headless-fast/references/portfolio/app/hooks/portfolio/useProjectDetail.ts +22 -49
  107. package/skills/wix-headless-fast/references/portfolio/app/wix/portfolio/collection-projects-store.ts +82 -0
  108. package/skills/wix-headless-fast/references/portfolio/app/wix/portfolio/collections-store.ts +58 -0
  109. package/skills/wix-headless-fast/references/portfolio/app/wix/portfolio/portfolio-core.ts +177 -0
  110. package/skills/wix-headless-fast/references/portfolio/app/wix/portfolio/portfolio.ts +31 -118
  111. package/skills/wix-headless-fast/references/portfolio/app/wix/portfolio/project-detail-store.ts +81 -0
  112. package/skills/wix-headless-fast/references/portfolio/rest/portfolio.ts +75 -0
  113. package/skills/wix-headless-fast/references/portfolio/seed/SEED.md +8 -0
  114. package/skills/wix-headless-fast/references/pricing-plans/INSTRUCTIONS.md +212 -51
  115. package/skills/wix-headless-fast/references/pricing-plans/app/components/pricing-plans/PlanDetailView.tsx +9 -20
  116. package/skills/wix-headless-fast/references/pricing-plans/app/components/pricing-plans/PlansView.tsx +7 -32
  117. package/skills/wix-headless-fast/references/pricing-plans/app/components/pricing-plans/SubscribeButton.tsx +41 -0
  118. package/skills/wix-headless-fast/references/pricing-plans/app/hooks/pricing-plans/usePlanPurchase.ts +12 -33
  119. package/skills/wix-headless-fast/references/pricing-plans/app/hooks/pricing-plans/usePlans.ts +17 -34
  120. package/skills/wix-headless-fast/references/pricing-plans/app/wix/pricing-plans/plan-purchase-store.ts +54 -0
  121. package/skills/wix-headless-fast/references/pricing-plans/app/wix/pricing-plans/plans-core.ts +106 -0
  122. package/skills/wix-headless-fast/references/pricing-plans/app/wix/pricing-plans/plans-store.ts +64 -0
  123. package/skills/wix-headless-fast/references/pricing-plans/app/wix/pricing-plans/plans.ts +7 -55
  124. package/skills/wix-headless-fast/references/pricing-plans/app/wix/pricing-plans/purchase-core.ts +43 -0
  125. package/skills/wix-headless-fast/references/pricing-plans/app/wix/pricing-plans/purchase.ts +11 -34
  126. package/skills/wix-headless-fast/references/pricing-plans/rest/plans.ts +31 -0
  127. package/skills/wix-headless-fast/references/pricing-plans/rest/purchase.ts +20 -0
  128. package/skills/wix-headless-fast/references/pricing-plans/seed/SEED.md +8 -0
  129. package/skills/wix-headless-fast/references/restaurants/INSTRUCTIONS.md +240 -47
  130. package/skills/wix-headless-fast/references/restaurants/app/components/restaurants/MenuView.tsx +2 -2
  131. package/skills/wix-headless-fast/references/restaurants/app/components/restaurants/OrderCartDrawer.tsx +2 -2
  132. package/skills/wix-headless-fast/references/restaurants/app/hooks/restaurants/useMenus.ts +14 -35
  133. package/skills/wix-headless-fast/references/restaurants/app/hooks/restaurants/useReservation.ts +28 -171
  134. package/skills/wix-headless-fast/references/restaurants/app/wix/restaurants/menu-core.ts +155 -0
  135. package/skills/wix-headless-fast/references/restaurants/app/wix/restaurants/menu-store.ts +89 -0
  136. package/skills/wix-headless-fast/references/restaurants/app/wix/restaurants/menu.ts +23 -117
  137. package/skills/wix-headless-fast/references/restaurants/app/wix/restaurants/ordering-core.ts +124 -0
  138. package/skills/wix-headless-fast/references/restaurants/app/wix/restaurants/ordering.ts +45 -114
  139. package/skills/wix-headless-fast/references/restaurants/app/wix/restaurants/reservation-store.ts +193 -0
  140. package/skills/wix-headless-fast/references/restaurants/app/wix/restaurants/reservations-core.ts +94 -0
  141. package/skills/wix-headless-fast/references/restaurants/app/wix/restaurants/reservations.ts +15 -87
  142. package/skills/wix-headless-fast/references/restaurants/rest/menu.ts +60 -0
  143. package/skills/wix-headless-fast/references/restaurants/rest/ordering.ts +169 -0
  144. package/skills/wix-headless-fast/references/restaurants/rest/reservations.ts +68 -0
  145. package/skills/wix-headless-fast/references/restaurants/seed/SEED.md +8 -0
  146. package/skills/wix-headless-fast/references/shared/SUPPLIED-CONTENT.md +23 -0
  147. package/skills/wix-headless-fast/references/shared/app/wix/media.ts +55 -1
  148. package/skills/wix-headless-fast/references/shared/app/wix/sdk.ts +13 -0
  149. package/skills/wix-headless-fast/references/shared/rest/client.ts +155 -0
  150. package/skills/wix-headless-fast/references/shared/rest/config.ts +3 -0
  151. package/skills/wix-headless-fast/references/shared/rest/media.ts +65 -0
  152. package/skills/wix-headless-fast/references/storefront/INSTRUCTIONS.md +371 -81
  153. package/skills/wix-headless-fast/references/storefront/app/components/storefront/CartDrawer.tsx +37 -3
  154. package/skills/wix-headless-fast/references/storefront/app/components/storefront/FilterPanel.tsx +266 -0
  155. package/skills/wix-headless-fast/references/storefront/app/components/storefront/OptionPicker.tsx +95 -0
  156. package/skills/wix-headless-fast/references/storefront/app/components/storefront/QuickAdd.tsx +136 -0
  157. package/skills/wix-headless-fast/references/storefront/app/hooks/storefront/useProductDetail.ts +29 -130
  158. package/skills/wix-headless-fast/references/storefront/app/hooks/storefront/useShop.ts +26 -182
  159. package/skills/wix-headless-fast/references/storefront/app/wix/storefront/cart-core.ts +121 -0
  160. package/skills/wix-headless-fast/references/storefront/app/wix/storefront/cart.ts +53 -136
  161. package/skills/wix-headless-fast/references/storefront/app/wix/storefront/catalog-core.ts +309 -0
  162. package/skills/wix-headless-fast/references/storefront/app/wix/storefront/catalog.ts +73 -230
  163. package/skills/wix-headless-fast/references/storefront/app/wix/storefront/product-detail-store.ts +147 -0
  164. package/skills/wix-headless-fast/references/storefront/app/wix/storefront/shop-store.ts +289 -0
  165. package/skills/wix-headless-fast/references/storefront/app/wix/storefront/types.ts +62 -4
  166. package/skills/wix-headless-fast/references/storefront/app-astro/layouts/SiteLayout.astro +21 -2
  167. package/skills/wix-headless-fast/references/storefront/rest/cart.ts +132 -0
  168. package/skills/wix-headless-fast/references/storefront/rest/catalog.ts +123 -0
  169. package/skills/wix-headless-fast/references/storefront/seed/SEED.md +25 -5
  170. package/skills/wix-headless-fast/references/storefront/seed/seed-store.mjs +24 -0
  171. package/skills/wix-manage/SKILL.md +4 -1
  172. package/skills/wix-manage/references/ecommerce/ecom-shipping.md +1 -1
  173. package/skills/wix-manage/references/events/create-wix-event.md +46 -0
  174. package/skills/wix-manage/references/events/manage-wix-events.md +51 -1
  175. package/skills/wix-manage/references/google-ads/manage-campaign-lifecycle.md +6 -6
  176. package/skills/wix-manage/references/seo/manage-seo-suggestions.md +351 -0
  177. package/skills/wix-vibe-headless/install/deploy.cjs +33 -2
  178. package/skills/wix-vibe-headless/platforms/base44-ecom-light-seed-with-install.md +1 -1
  179. package/skills/wix-vibe-headless/platforms/base44-ecom-light-seed.md +13 -4
  180. package/skills/wix-vibe-headless/platforms/base44-ecom-light.md +1 -1
  181. package/skills/wix-vibe-headless/platforms/base44.md +19 -4
  182. package/skills/wix-vibe-headless/platforms/generic.md +6 -0
  183. package/skills/wix-vibe-headless/references/_shared/nav/nav.tanstack.js +30 -0
  184. package/skills/wix-vibe-headless/references/_shared/routing.md +86 -0
  185. package/skills/wix-vibe-headless/references/blog/INSTRUCTIONS.md +44 -0
  186. package/skills/wix-vibe-headless/references/blog/app/components/PostCard.jsx +1 -1
  187. package/skills/wix-vibe-headless/references/blog/app/components/PostChips.jsx +1 -1
  188. package/skills/wix-vibe-headless/references/blog/app/pages/CategoryPage.jsx +1 -1
  189. package/skills/wix-vibe-headless/references/blog/app/pages/PostDetail.jsx +1 -1
  190. package/skills/wix-vibe-headless/references/blog/app/pages/TagPage.jsx +1 -1
  191. package/skills/wix-vibe-headless/references/bookings/INSTRUCTIONS.md +42 -0
  192. package/skills/wix-vibe-headless/references/bookings/app/components/ServiceCard.jsx +1 -1
  193. package/skills/wix-vibe-headless/references/bookings/app/pages/ServiceDetail.jsx +1 -1
  194. package/skills/wix-vibe-headless/references/events/INSTRUCTIONS.md +42 -0
  195. package/skills/wix-vibe-headless/references/events/app/components/EventCard.jsx +1 -1
  196. package/skills/wix-vibe-headless/references/events/app/pages/EventDetail.jsx +1 -1
  197. package/skills/wix-vibe-headless/references/members/INSTRUCTIONS.md +42 -0
  198. package/skills/wix-vibe-headless/references/members/app/components/MemberMenu.jsx +1 -1
  199. package/skills/wix-vibe-headless/references/members/app/components/RequireAuth.jsx +1 -1
  200. package/skills/wix-vibe-headless/references/members/app/pages/Login.jsx +1 -1
  201. package/skills/wix-vibe-headless/references/portfolio/INSTRUCTIONS.md +43 -0
  202. package/skills/wix-vibe-headless/references/portfolio/app/components/CollectionCard.jsx +1 -1
  203. package/skills/wix-vibe-headless/references/portfolio/app/components/ProjectCard.jsx +1 -1
  204. package/skills/wix-vibe-headless/references/portfolio/app/pages/CollectionPage.jsx +1 -1
  205. package/skills/wix-vibe-headless/references/portfolio/app/pages/ProjectDetail.jsx +1 -1
  206. package/skills/wix-vibe-headless/references/pricing-plans/INSTRUCTIONS.md +43 -0
  207. package/skills/wix-vibe-headless/references/pricing-plans/app/components/PlanCard.jsx +1 -1
  208. package/skills/wix-vibe-headless/references/pricing-plans/app/pages/PlanDetail.jsx +1 -1
  209. package/skills/wix-vibe-headless/references/restaurants/INSTRUCTIONS.md +36 -0
  210. package/skills/wix-vibe-headless/references/shared/app/lib/nav.js +9 -0
  211. package/skills/wix-vibe-headless/references/storefront/INSTRUCTIONS.md +42 -41
  212. package/skills/wix-vibe-headless/references/storefront/app/hooks/useProductCard.js +7 -1
  213. package/skills/wix-vibe-headless/references/storefront/seed/SEED.md +3 -0
  214. package/skills/wix-vibe-headless/references/storefront/seed/seed-store.cjs +6 -0
  215. package/skills/wix-headless-fast/install/pin-agents-md.mjs +0 -57
@@ -1,63 +1,314 @@
1
- # Members — custom in-app login
2
-
3
- The Members vertical ships a **custom credential login**, not the Wix-hosted
4
- login-page redirect. Members sign up and sign in on `/login` with email and
5
- password; the shipped client exchanges a direct-login session into member
6
- tokens into the managed `wixSession` cookie. That makes the member identity
7
- available to both the custom client and Astro's ambient SDK calls after the
8
- next navigation. Do not replace the auth implementation or add a second client.
9
-
10
- ## Shipped files
11
-
12
- | File | Purpose |
13
- | ------------------------------------------------------------------------- | ------------------------------------------------------------------------ |
14
- | `wix/members/client.ts` | Explicit `OAuthStrategy` client that syncs direct-login tokens to Astro. |
15
- | `wix/members/auth.ts` | Direct `register`, `login`, verification, and logout state machine. |
16
- | `wix/members/member-store.ts` + `hooks/members/useMember.ts` | Module-scoped session state shared by Astro islands. |
17
- | `components/members/LoginForm.tsx` | Branded in-app sign-in/sign-up and verification UI. |
18
- | `components/members/MemberMenu.tsx`, `RequireAuth.tsx`, `AccountView.tsx` | Header control, client gate, and account surface references. |
19
- | `pages/login.astro`, `pages/account.astro` | Custom-login and gated-account routes. |
20
-
21
- ## Wire it
22
-
23
- 1. Keep `<MemberMenu client:only="react" />` in the winning site header.
24
- 2. Keep the shipped `/login` route. It is the only login surface; never link to
25
- `/api/auth/login`, build an OAuth callback page, or redirect to Wix login.
26
- 3. Keep `/account` client-gated with `<RequireAuth>`. A visitor sees a link to
27
- `/login`; a member sees their actual profile.
28
- 4. Build your own visual chrome around these shipped components using the site
29
- tokens. Do not mock a signed-in member or infer identity from local UI state.
30
-
31
- ## Direct-login contract
32
-
33
- - `login(email, password)` and `register(email, password, profile)` return all
34
- Wix states: `SUCCESS`, `EMAIL_VERIFICATION_REQUIRED`,
35
- `OWNER_APPROVAL_REQUIRED`, or `FAILURE`. The shipped form handles each one.
36
- - A successful state calls `getMemberTokensForDirectLogin` then `setTokens` on
37
- the same client. It writes Astro's `wixSession` cookie, so the next page
38
- request and browser islands run later SDK calls as that member.
39
- - No login redirect URI is required for credential login. Password-reset and
40
- logout return URLs remain the only optional redirect surfaces.
41
- - The public OAuth client ID is written as `WIX_MEMBERS_CLIENT_ID` by deploy,
42
- even for managed Astro. It is public; never add an OAuth secret to the app.
43
- - Identity needs no Members Area app. Profile data and custom profile fields do;
44
- the member seed installs the Members Area app.
45
-
46
- ## Rules
47
-
48
- - No Wix-hosted login flow, `/api/auth/login`, OAuth callback, or callback URI
49
- requirement for credential login.
50
- - Keep one explicit custom-members client. Do not instantiate one per component.
51
- - Do not use `auth.elevate()` for a member reading their own records.
52
- - Surface login failure and the verification/approval states; never silently
53
- fall back to anonymous UI.
54
-
55
- ## Verify
56
-
57
- - [ ] `/login` renders an in-app email/password sign-in and sign-up form.
58
- - [ ] A successful sign-in changes the header and unlocks `/account` without a
59
- Wix-hosted login redirect.
60
- - [ ] Email verification and owner approval are rendered as states, not errors.
61
- - [ ] Reload preserves the member session; the next server render also sees it;
62
- logout clears it.
63
- - [ ] No mocked member data, redirect-based login, or extra auth client exists.
1
+ # Members — playbook
2
+
3
+ The account machinery ships as files — the custom credential login (sign in, sign up, email
4
+ verification, owner approval, logout), the session store, the current-member read, typed
5
+ end-to-end. Members sign up and sign in **on your site**, never on a Wix-hosted login page: the
6
+ shipped client exchanges a credential login into member tokens, and on managed Astro writes them
7
+ into the `wixSession` cookie so the next server render and every island run as that member.
8
+ **The presentation doesn't ship — you build it** on the shipped hook/DTOs: the login page around
9
+ the shipped form, the account page, the header control, and whatever the brief gates behind a
10
+ login. You never write auth code; you never skip designing the surfaces.
11
+
12
+ ## The file map (deployed into `src/`)
13
+
14
+ **On Astro and React the shipped files are tested and work as they are** — this table and the
15
+ contracts below are everything you need to use them, so don't spend the run reading their source;
16
+ wire them and build your surfaces. Reading them is the right move when something is off (a runtime
17
+ error, a field this playbook doesn't cover) or when the brief wants a behaviour they don't offer —
18
+ then read the file that owns it and change or extend it. On `lib`, `static`, and a port the
19
+ components don't deploy at all, and each wiring section below opens with the files to read before
20
+ writing their equivalents. Files you edit: `SiteLayout.astro` and `styles/global.css`.
21
+ Files you **create**: your home page, any gated page the brief asks for, and your own account
22
+ surface if the reference one doesn't fit the brand.
23
+
24
+ | file | what it is |
25
+ |---|---|
26
+ | `wix/config.ts` · `wix/sdk.ts` | shared auth seam (deploy configures it, `WIX_MEMBERS_CLIENT_ID` included — nothing to set by hand) |
27
+ | `wix/media.ts` | `imgAttrs(url, sizes)` / `imgSrc()` — the member photo is already an https URL in the DTO |
28
+ | `wix/members/types.ts` | the DTO (`CurrentMember`) — contract inlined below |
29
+ | `wix/members/client.ts` | the one explicit `OAuthStrategy` client the credential flow needs; on Astro it stores member tokens in the `wixSession` cookie so ambient SDK calls run as the member |
30
+ | `wix/members/auth.ts` | `loginMember`, `registerMember`, `verifyMemberEmail`, `logoutMember`, `loggedInHint` — the transport; what a response means (the four states, the error-code names) is in `auth-core.ts` beside it (shared with the REST layer) |
31
+ | `wix/members/members.ts` | `fetchCurrentMember` — the transport; the DTO mapper is in `members-core.ts` beside it (shared with the REST layer) |
32
+ | `wix/members/member-store.ts` | the session state machine, framework-free: one per visitor (a module singleton — it spans Astro islands, which a React context can't); `getMemberState`/`subscribeMember`, `login`, `register`, `verifyEmail`, `logout`, `refreshMember`, `hydrateMember`; the hook below binds it to React, every other stack uses it directly |
33
+ | `hooks/members/useMember.ts` | React binding of `member-store.ts`: session state + the credential actions — contract below |
34
+ | `components/members/LoginForm.tsx` | the credential form — sign in / sign up toggle, the verification-code step, the pending-approval notice, the inline error, `returnTo` — **wire as-is** on your login page |
35
+ | `components/members/MemberMenu.tsx` | header control reference on the tokens: skeleton while loading, "Log in" for a visitor, name/avatar + "Log out" for a member — wire as-is or design your own on `useMember` |
36
+ | `components/members/RequireAuth.tsx` | the gate for member-only surfaces: waits for the first session read, then children for a member, a login prompt with `returnTo` for a visitor — **wire as-is** around gated content |
37
+ | `components/members/AccountView.tsx` | account surface reference: profile card + log out; design your own on `useMember` when the brand asks |
38
+ | `styles/global.css` | **the design system**: Tailwind v4 + the `@theme` token block (colors, radii, fonts — same token family as the official Wix templates). Everything, shipped and yours, styles from these tokens |
39
+
40
+ Astro stack additionally gets:
41
+
42
+ | file | what it is |
43
+ |---|---|
44
+ | `layouts/SiteLayout.astro` | the site chrome — **yours to brand**: header, footer, nav. Keep the `<slot name="seo-tags" />`, the global.css import, and one `<MemberMenu client:only="react" />` in the header (if another vertical's layout won, mount `MemberMenu` in that header instead) |
45
+ | `pages/login.astro` · `pages/account.astro` | the login and account routes — thin shells mounting `LoginForm` and `RequireAuth` + `AccountView` `client:only="react"`; brand the chrome around them, keep the mounts |
46
+
47
+ ## What you build — this is the design job, not optional polish
48
+
49
+ You implement the surfaces yourself, styled with Tailwind utilities on the `@theme` tokens,
50
+ designed to fit the brief (a members-only club and a course platform should not get the same
51
+ account area):
52
+
53
+ 1. **The login page** — the chrome around the shipped `LoginForm` (`pages/login.astro`): heading,
54
+ what membership gives, the brand. The form's four states already render; you own the page.
55
+ 2. **The account page** — `pages/account.astro` mounts `RequireAuth` around `AccountView`; keep the
56
+ gate, and replace `AccountView` with your own surface on `useMember` when the brief wants more
57
+ than the profile card (orders, bookings, saved items — each from its own vertical's data layer).
58
+ 3. **The header control** — the shipped `MemberMenu` or your own on `useMember`: it is the one
59
+ surface every page shows, so it carries the brand.
60
+ 4. **Gated content** the brief asks for — a page inside `RequireAuth`, or a member-only section on a
61
+ public page rendered from `loggedIn`.
62
+ 5. **The home page** — on `SiteLayout`, with the way in (log in / join) visible.
63
+
64
+ Plus the **theme** (edit the `@theme` block in `styles/global.css` — one edit) and the **chrome**
65
+ (header/footer in `SiteLayout.astro`, one edit pass).
66
+
67
+ ### What a complete members site shows (recommended defaults)
68
+
69
+ Defaults for a brief that says nothing about them; the prompt wins when it asks for something
70
+ else. Then, by default:
71
+
72
+ - **Header:** a skeleton while the session read settles, "Log in" for a visitor, the member's
73
+ name or avatar plus "Log out" for a member — never a flash of "Log in" for someone who is in.
74
+ - **Login page:** sign in and sign up on one page; email verification and owner approval rendered
75
+ as states (a code field, a "pending approval" notice), a failed login as an inline message next
76
+ to the form; `?returnTo=` honoured after success (the shipped form does all of this).
77
+ - **Account page:** gated — a visitor sees the login prompt in place, a member their real profile
78
+ (`displayName`, `loginEmail`, `memberSince`, photo when there is one); a logged-in member with
79
+ `member === null` gets the one honest line ("profile details unavailable") — the Members Area app
80
+ isn't installed, which the seed does.
81
+ - **Logout:** returns to the page that offered it, or the home page.
82
+ - **Copy:** nothing the owner didn't supply — no invented perks, member counts, or testimonials;
83
+ no Wix IDs or technical words in visible text.
84
+
85
+ ### The contracts your components consume (everything you need — don't read the source)
86
+
87
+ ```ts
88
+ // CurrentMember — display-ready:
89
+ // { id, loginEmail /* "" when hidden */, displayName /* nickname → "first last" → email local part → "Member" */,
90
+ // firstName, lastName, nickname, photoUrl /* https or "" */, contactId /* the key for member-owned content */,
91
+ // memberSince /* "YYYY-MM-DD" or "" */ }
92
+
93
+ // useMember({ initialMember? /* SSR-resolved member or null; omit to resolve client-side */ }) →
94
+ // { member: CurrentMember|null, loggedIn, loading /* true until the first session read settles — skeletons, not the logged-out state */,
95
+ // error /* last failed operation's message; a new operation clears it */,
96
+ // login(email, password), register(email, password, { firstName?, lastName? }?), verifyEmail(code),
97
+ // logout(returnTo?) /* navigates away */, refresh() }
98
+ // loggedIn can be true with member === null: the caller is a member but the site has no Members Area app (profile layer).
99
+ // Several islands on one page share one session — the store is a module singleton.
100
+
101
+ // login / register / verifyEmail resolve to LoginResult:
102
+ // { state: "SUCCESS" | "EMAIL_VERIFICATION_REQUIRED" | "OWNER_APPROVAL_REQUIRED" | "FAILURE",
103
+ // errorCode? /* invalidPassword | invalidEmail | emailAlreadyExists | resetPassword | missingCaptchaToken | invalidCaptchaToken */,
104
+ // error? /* Wix's message — render it */ }
105
+ // SUCCESS has already refreshed the session: member and loggedIn are set when the promise resolves.
106
+ // EMAIL_VERIFICATION_REQUIRED → show a code field and call verifyEmail(code); the state token is kept for you.
107
+ // OWNER_APPROVAL_REQUIRED → a pending notice; the member logs in once the owner approves (dashboard).
108
+ // Which of the three a sign-up ends in is the site's signup policy (dashboard), not your code.
109
+ ```
110
+
111
+ ### The pages — the shipped shells and a gated page
112
+
113
+ Hooks first, branches after (an early return above a hook changes hook order between renders and
114
+ React throws). Session-reading islands mount `client:only="react"` — they read browser state and
115
+ must not server-render; a `client:load` gate would flash the logged-out state.
116
+
117
+ ```astro
118
+ ---
119
+ // src/pages/login.astro — ships; brand the chrome, keep the mount.
120
+ import SiteLayout from "../layouts/SiteLayout.astro";
121
+ import LoginForm from "../components/members/LoginForm";
122
+ ---
123
+ <SiteLayout title="Log in">
124
+ <section class="mx-auto max-w-md"> {/* one narrow column: the form is the page */}
125
+ <h1 class="mb-6 text-2xl font-semibold">Welcome</h1>
126
+ <LoginForm client:only="react" />
127
+ </section>
128
+ </SiteLayout>
129
+ ```
130
+
131
+ ```astro
132
+ ---
133
+ // src/pages/account.astro — ships; the gate stays, the surface inside is yours to replace.
134
+ import SiteLayout from "../layouts/SiteLayout.astro";
135
+ import AccountView from "../components/members/AccountView";
136
+ import RequireAuth from "../components/members/RequireAuth";
137
+ ---
138
+ <SiteLayout title="My account">
139
+ <h1 class="mb-8 text-2xl font-semibold tracking-tight">My account</h1>
140
+ <RequireAuth client:only="react"><AccountView /></RequireAuth>
141
+ </SiteLayout>
142
+ ```
143
+
144
+ ```tsx
145
+ // src/components/members/MembersOnly.tsx — YOU create it when the brief gates content: a view over
146
+ // useMember inside RequireAuth. The gate decides; the view renders the member's things.
147
+ import RequireAuth from "./RequireAuth";
148
+ import { useMember } from "../../hooks/members/useMember";
149
+
150
+ function Inner() {
151
+ const { member } = useMember();
152
+ return <section>{/* your gated content; member?.displayName, member?.contactId for member-owned lookups */}</section>;
153
+ }
154
+ export default function MembersOnly() {
155
+ return <RequireAuth><Inner /></RequireAuth>;
156
+ }
157
+ ```
158
+
159
+ ### The reference files for stacks where the components don't deploy
160
+
161
+ On `lib`, `static`, and a port, nothing under `components/` or `hooks/` arrives. The state machine
162
+ behind the hook does arrive — `wix/members/member-store.ts` — so you never rewrite it: `subscribe`,
163
+ render from `getMemberState()`, call its actions; `MemberState` is the render contract. What you
164
+ write is the rendering — the form, the gate, the header control — and for that read these first;
165
+ they are tested code for exactly that behaviour, and rewriting them from the prose above is where
166
+ the bugs come from:
167
+
168
+ 1. `components/members/LoginForm.tsx` — the four states as working code: the sign-in/sign-up
169
+ toggle, the name fields only on sign-up, the verification-code step, the pending notice, the
170
+ inline error, the button disabled while busy, `returnTo` after success (only a same-site path).
171
+ 2. `components/members/RequireAuth.tsx` — wait for `loading` to settle before deciding (deciding
172
+ early bounces a member on first paint); the visitor's prompt links to the login page with the
173
+ current path as `returnTo`.
174
+ 3. `components/members/MemberMenu.tsx` — the three renders (skeleton, "Log in", name/avatar +
175
+ "Log out") and the avatar fallback (first letter of `displayName`).
176
+
177
+ All under `references/members/app/`.
178
+
179
+ ### Wiring — Astro (default)
180
+
181
+ 1. Set the `@theme` tokens (one edit); brand `SiteLayout.astro` (one pass), keeping one
182
+ `<MemberMenu client:only="react" />` in the header.
183
+ 2. Keep `/login` and `/account` as shipped — the only login surface is `/login`; never link to
184
+ `/api/auth/login`, build an OAuth callback page, or redirect to a Wix login page. Brand the
185
+ chrome around the mounts; replace `AccountView` with your own surface on `useMember` when the
186
+ brief wants more.
187
+ 3. Gated content: `RequireAuth` around it, `client:only="react"`.
188
+ 4. Write `pages/index.astro` (home) on `SiteLayout`.
189
+
190
+ ### Wiring — another JS framework (`--stack lib`: Vue, Svelte, Solid, plain Vite)
191
+
192
+ Read the reference files listed above before writing any surface.
193
+
194
+ `deploy.mjs members --stack lib` put the data layer in `src/wix/` and nothing else: `sdk.ts`,
195
+ `config.ts` (deploy wrote the public client id into both `WIX_CLIENT_ID` and
196
+ `WIX_MEMBERS_CLIENT_ID`), `media.ts`, and `wix/members/` — `client.ts`, `auth.ts`, `members.ts`,
197
+ `types.ts`, the `*-core.ts` rules, and `member-store.ts`. None of it is React. The hook and the
198
+ components don't ship on this stack; the store replaces the hook, and you write the components in
199
+ your framework to the contracts on this page:
200
+
201
+ - bind the store with your framework's external-store primitive (Vue: `shallowRef` updated in
202
+ `subscribeMember`; Svelte: `readable(getMemberState(), (set) => subscribeMember(() => set(getMemberState())))`;
203
+ Solid: a signal set in `subscribeMember`). One store for the whole app (module-level); the first
204
+ subscriber triggers the session read. State in, actions out — exactly `useMember`'s contract;
205
+ - your login form, gate, and header control to the defaults above — `LoginForm.tsx`,
206
+ `RequireAuth.tsx`, `MemberMenu.tsx` are readable as behaviour specs.
207
+
208
+ Routes `/login`, `/account` (gated in the component, not the router — the session is browser
209
+ state); dev server on 4321; a static build goes through `npx @wix/cli@latest release` with
210
+ `site.outputDirectory` pointing at the build folder, an SSR build is hosted by you.
211
+
212
+ ### Wiring — static site (`--stack static`, no bundler)
213
+
214
+ Read the reference files listed above before writing any surface.
215
+
216
+ `deploy.mjs members --stack static --out site` put the REST layer in `site/js/wix/` (browser ESM,
217
+ the `.ts` beside each `.js` for reading). Everything the visitor loads lives under `site/` — pages,
218
+ styles, `js/` — and `wix.config.json`'s `site.outputDirectory` is `"./site"`; the project root
219
+ (config, seed output) is never the upload. Same function names and DTOs as the table above, so the
220
+ contracts on this page hold unchanged: `loginMember`, `registerMember`, `verifyMemberEmail`,
221
+ `logoutMember`, `loggedInHint` from `./js/wix/auth.js`; `fetchCurrentMember` from
222
+ `./js/wix/members.js`. The state machine ships too: `./js/wix/member-store.js`
223
+ (`subscribeMember` — the first subscriber triggers the session read — `getMemberState`, `login`,
224
+ `register`, `verifyEmail`, `logout`, `refreshMember`). No components ship — you write the rendering
225
+ in plain JS: one render function per surface that reads `getMemberState()`, called from
226
+ `subscribeMember`, with the form's submit calling the store's actions and rendering the
227
+ `LoginResult` state it resolves to. Pages are `login.html` (`?returnTo=` a same-site path) and
228
+ `account.html`, gated in the page: `loading` → a skeleton, anonymous → a link to
229
+ `login.html?returnTo=account.html`, a member → the profile. The header control is the same store
230
+ on every page.
231
+
232
+ How the session works here: the login runs over the IAM authentication API with the visitor token
233
+ and exchanges the result into member tokens, which replace the visitor token in `localStorage`
234
+ (`role: "member"`) — every later call runs as the member and the refresh keeps the member; never
235
+ mint per page. The exchange completes in a hidden iframe on the page's own origin, so **the page's
236
+ origin must be one of the OAuth app's allowed domains** (`localhost:4321` and the Wix-hosted origin
237
+ already are; a custom domain is added in the dashboard's Headless Settings) — otherwise the login
238
+ resolves nothing and times out with "Login timed out". Logout navigates to Wix and returns to the
239
+ URL you pass (`logout("account.html")` resolves against the page). Gated pages carry no SEO — there
240
+ is nothing to index. `npx @wix/cli@latest release` uploads `site/`.
241
+
242
+ ### Wiring — server-rendered, another language (Flask, Laravel, Rails, …)
243
+
244
+ Read the reference files listed above before writing any surface.
245
+
246
+ Run `deploy.mjs members --stack static` in the project folder anyway: `js/wix/` is both the
247
+ browser-side code and the readable spec. This vertical has no public reads — everything is the
248
+ visitor's own state — so the whole flow runs **in the browser** from `./js/wix/` exactly as the
249
+ static wiring above: the login form, the gate, the header control on `member-store.js`; the
250
+ browser owns the member token, so the server handles no per-visitor tokens, and a member-only page
251
+ is a page whose content renders once `getMemberState().loggedIn` is true. Add your public https
252
+ origin to the OAuth app's allowed domains before the login can complete (the iframe exchange) and
253
+ before logout can return.
254
+
255
+ If the server itself must know the member (server-rendered member-only pages, member-owned data
256
+ joined server-side), port `js/wix/auth.ts` and `auth-core.ts`: the same three calls — login with a
257
+ visitor token, the redirect session, `POST /oauth2/token` with `grantType: "authorization_code"` —
258
+ and the no-DOM branch of the exchange (fetch the authorize page, read `code` and `state` from it) is
259
+ the server's path; or use the docs' full-page variant (`responseMode: "query"` plus a `redirectUri`
260
+ on the allowed list). Then `client.ts`'s header applies: one token set per visitor in the visitor's
261
+ session, never one process-wide token, and `GET /members/v1/members/my?fieldsets=FULL` with that
262
+ token on each request (`members.ts` + `members-core.ts` as the port).
263
+
264
+ ### Wiring — React SPA (Vite etc.)
265
+
266
+ Import `./styles/global.css` once at the app entry (needs `@tailwindcss/vite` in the vite config
267
+ plugins — deploy already added the dep). Write route wrappers in the project's router: `/login` →
268
+ a page mounting `LoginForm` (pass `onSuccess` to navigate with your router, or let it use
269
+ `?returnTo=`); `/account` → `RequireAuth` around your account surface; gated routes → the same.
270
+ Mount `MemberMenu` in the header (pass `LinkComponent` for router links). Deploy wrote the public
271
+ client id into `wix/config.ts` (`WIX_CLIENT_ID` and `WIX_MEMBERS_CLIENT_ID`); nothing else to
272
+ configure.
273
+
274
+ ## Hard rules
275
+
276
+ - **No Wix-hosted login flow** — no `/api/auth/login`, no OAuth callback page, no callback URI for
277
+ credential login. Password-reset emails and logout are the only redirect surfaces, and both
278
+ return to a URL you pass.
279
+ - **Auth only through the shipped exports** — `useMember` / the store's actions; never call the
280
+ IAM API or the OAuth client yourself, never rewrite the exchange. Extend by adding a function in
281
+ `wix/members/` for what they don't cover (API contracts: the `wix-docs` skill).
282
+ - **One explicit members client** (`wix/members/client.ts`) — never instantiate another, never one
283
+ per component.
284
+ - **Session state only through the store** — no React context, no copy of `loggedIn` in component
285
+ state, no identity inferred from local UI state.
286
+ - **Every state is rendered**: a failed login shows `error` next to the form; verification and
287
+ owner approval are states, not errors; `loading` is a skeleton, never the logged-out UI.
288
+ - **Identity vs profile**: `loggedIn` needs no app install; `member` (profile data) needs the Wix
289
+ Members Area app — the seed installs it. A member with `member === null` gets the honest line,
290
+ not a fake profile.
291
+ - **Gate only what the brief gates.** Public pages stay public; browsing never needs a login.
292
+ - Don't use `auth.elevate()` for a member reading their own records — the member token is the
293
+ right identity.
294
+ - **Live data or an honest empty state** — never mock a member, a name, or a member count.
295
+ - **The token is the session** — it persists on its own (cookie on Astro, `localStorage`
296
+ elsewhere); never mint per page, never store credentials.
297
+ - Where the shipped components deploy (Astro, React): theme via the `@theme` tokens, and your
298
+ markup uses Tailwind utilities on the same tokens — one design system across shipped and written
299
+ code. Where they don't (`lib`, `static`, a port): style with whatever your stack does well, on one
300
+ token set of your own; the rule that survives is the token set, not Tailwind.
301
+ - **Call every hook before any conditional return.** Hooks first, branches after.
302
+
303
+ ## Point the user to their dashboard
304
+
305
+ Give the owner the dashboard link — **the deploy step's JSON output already printed it**
306
+ (`dashboardUrl`); copy, don't re-derive. Members are managed under Contacts → Site Members there,
307
+ and the signup policy — email verification, owner approval, reCAPTCHA — is set under Settings →
308
+ Member signup; it decides which state a sign-up ends in.
309
+
310
+ ## Seeding
311
+
312
+ Per `seed/SEED.md` — `seed-members.mjs`, run from the project root. It installs the Wix Members
313
+ Area app (the profile layer) and nothing else: members self-register at runtime, never at build
314
+ time. Independent of the frontend work.
@@ -1,6 +1,6 @@
1
1
  // Shipped custom login form. The member stays on this site: credential calls exchange
2
2
  // directly into member tokens; only logout leaves the app.
3
- import { FormEvent, useState } from "react";
3
+ import { type FormEvent, useState } from "react";
4
4
  import { useMember } from "../../hooks/members/useMember";
5
5
 
6
6
  export interface LoginFormProps {
@@ -0,0 +1,105 @@
1
+ // Authentication rules — transport-agnostic, imported by BOTH transports: ./auth.ts (the SDK's
2
+ // OAuthStrategy) and the REST twin in references/members/rest/auth.ts (the IAM authentication API
3
+ // over fetch). What a login/registration response MEANS — the four states, when a session token is
4
+ // expected, which Wix error code is which failure — lives HERE, once. No imports: a strip to JS
5
+ // emits a plain module.
6
+
7
+ /** The four outcomes every credential operation resolves to; the shipped LoginForm renders each. */
8
+ export type LoginState = "SUCCESS" | "EMAIL_VERIFICATION_REQUIRED" | "OWNER_APPROVAL_REQUIRED" | "FAILURE";
9
+
10
+ export interface LoginResult {
11
+ state: LoginState;
12
+ /** Continues an EMAIL_VERIFICATION_REQUIRED flow (the transport keeps it too — verifyMemberEmail needs no argument). */
13
+ stateToken?: string;
14
+ /** A stable name for a FAILURE: invalidPassword, invalidEmail, emailAlreadyExists, resetPassword, missingCaptchaToken, invalidCaptchaToken. */
15
+ errorCode?: string;
16
+ /** Wix's message for a FAILURE — render it. */
17
+ error?: string;
18
+ }
19
+
20
+ /** A raw login/register/verify response as either transport returns it. */
21
+ export type RawAuth = Record<string, any>;
22
+
23
+ /** A LoginResult plus the one-shot session token a SUCCESS carries (5-minute life; exchanged, never shown). */
24
+ export interface AuthOutcome extends LoginResult {
25
+ sessionToken: string | null;
26
+ }
27
+
28
+ // REST spells the states differently from the SDK; both map onto LoginState.
29
+ const REST_STATES: Record<string, LoginState> = {
30
+ SUCCESS: "SUCCESS",
31
+ REQUIRE_EMAIL_VERIFICATION: "EMAIL_VERIFICATION_REQUIRED",
32
+ REQUIRE_OWNER_APPROVAL: "OWNER_APPROVAL_REQUIRED",
33
+ };
34
+
35
+ /**
36
+ * Normalize either transport's response — SDK `{ loginState, data: { sessionToken | stateToken },
37
+ * error?, errorCode? }` or REST `{ state, sessionToken?, stateToken? }`. Anything else is a FAILURE.
38
+ */
39
+ export function authOutcome(raw: RawAuth | null | undefined): AuthOutcome {
40
+ const state: LoginState = raw?.loginState ?? REST_STATES[raw?.state ?? ""] ?? "FAILURE";
41
+ const stateToken: string | undefined = raw?.stateToken ?? raw?.data?.stateToken;
42
+ return {
43
+ state,
44
+ sessionToken: raw?.data?.sessionToken ?? raw?.sessionToken ?? null,
45
+ ...(stateToken ? { stateToken } : {}),
46
+ ...(raw?.errorCode ? { errorCode: raw.errorCode } : {}),
47
+ ...(raw?.error ? { error: raw.error } : {}),
48
+ };
49
+ }
50
+
51
+ /** The outcome as callers see it — without the session token, which the transport has consumed. */
52
+ export function toLoginResult({ sessionToken: _consumed, ...result }: AuthOutcome): LoginResult {
53
+ return result;
54
+ }
55
+
56
+ export function failure(error: string, errorCode?: string): LoginResult {
57
+ return { state: "FAILURE", error, ...(errorCode ? { errorCode } : {}) };
58
+ }
59
+
60
+ /** A SUCCESS without a session token — the exchange can't run; surfaced as a FAILURE with this text. */
61
+ export const NO_SESSION_ERROR = "Wix did not return a member session.";
62
+
63
+ // Wix IAM application-error codes, named as the SDK names them.
64
+ export const AUTH_ERROR_CODES = {
65
+ MISSING_CAPTCHA: "-19971",
66
+ INVALID_CAPTCHA: "-19970",
67
+ EMAIL_EXISTS: "-19995",
68
+ INVALID_PASSWORD: "-19976",
69
+ RESET_PASSWORD: "-19973",
70
+ } as const;
71
+
72
+ /** A failed login's applicationError code → the SDK's errorCode name (anything unrecognized is `invalidEmail`, as the SDK does). */
73
+ export function loginErrorCode(code: string | undefined): string {
74
+ switch (code) {
75
+ case AUTH_ERROR_CODES.MISSING_CAPTCHA:
76
+ return "missingCaptchaToken";
77
+ case AUTH_ERROR_CODES.INVALID_CAPTCHA:
78
+ return "invalidCaptchaToken";
79
+ case AUTH_ERROR_CODES.INVALID_PASSWORD:
80
+ return "invalidPassword";
81
+ case AUTH_ERROR_CODES.RESET_PASSWORD:
82
+ return "resetPassword";
83
+ default:
84
+ return "invalidEmail";
85
+ }
86
+ }
87
+
88
+ /**
89
+ * A failed registration's applicationError code (+ the response `details`) → the SDK's errorCode
90
+ * name; undefined when the SDK would name none. A validation error on the EMAIL field is `invalidEmail`.
91
+ */
92
+ export function registerErrorCode(code: string | undefined, details?: RawAuth): string | undefined {
93
+ const violations: RawAuth[] = details?.validationError?.fieldViolations ?? [];
94
+ if (violations.some((v) => v?.data?.type === "EMAIL")) return "invalidEmail";
95
+ switch (code) {
96
+ case AUTH_ERROR_CODES.MISSING_CAPTCHA:
97
+ return "missingCaptchaToken";
98
+ case AUTH_ERROR_CODES.EMAIL_EXISTS:
99
+ return "emailAlreadyExists";
100
+ case AUTH_ERROR_CODES.INVALID_CAPTCHA:
101
+ return "invalidCaptchaToken";
102
+ default:
103
+ return undefined;
104
+ }
105
+ }
@@ -1,59 +1,42 @@
1
- // Custom, in-app member authentication. Credentials are submitted from the branded
2
- // LoginForm; there is no Wix-hosted login-page redirect or callback route.
1
+ // Custom, in-app member authentication over the SDK — the transport only. Credentials are
2
+ // submitted from the branded LoginForm; there is no Wix-hosted login-page redirect or callback
3
+ // route. What a response means lives in ./auth-core (shared with the REST twin in
4
+ // references/members/rest/auth.ts); this file makes the OAuthStrategy calls and delegates.
5
+ // docs: https://dev.wix.com/docs/go-headless/authentication/members/custom-login-page/build-a-custom-login-page-js-sdk.md
3
6
  import { membersAuth } from "./client";
4
-
5
- export type LoginState =
6
- | "SUCCESS"
7
- | "EMAIL_VERIFICATION_REQUIRED"
8
- | "OWNER_APPROVAL_REQUIRED"
9
- | "FAILURE";
10
-
11
- export interface LoginResult {
12
- state: LoginState;
13
- stateToken?: string;
14
- errorCode?: string;
15
- error?: string;
16
- }
17
-
18
- type AuthResponse = {
19
- loginState?: LoginState;
20
- data?: { sessionToken?: string };
21
- stateToken?: string;
22
- errorCode?: string;
23
- error?: string;
24
- };
25
-
7
+ import {
8
+ NO_SESSION_ERROR,
9
+ authOutcome,
10
+ failure,
11
+ toLoginResult,
12
+ type LoginResult,
13
+ type LoginState,
14
+ type RawAuth,
15
+ } from "./auth-core";
16
+
17
+ export type { LoginResult, LoginState };
18
+
19
+ /** True when the explicit members client holds member tokens (no network). */
26
20
  export function loggedInHint(): boolean {
27
21
  return membersAuth.loggedIn();
28
22
  }
29
23
 
30
- async function finish(response: AuthResponse): Promise<LoginResult> {
31
- const state = response.loginState ?? "FAILURE";
32
- if (state === "SUCCESS") {
33
- const sessionToken = response.data?.sessionToken;
34
- if (!sessionToken)
35
- return {
36
- state: "FAILURE",
37
- error: "Wix did not return a member session.",
38
- };
39
- const tokens =
40
- await membersAuth.getMemberTokensForDirectLogin(sessionToken);
24
+ // A SUCCESS carries a one-shot session token; the strategy exchanges it for member tokens
25
+ // (getMemberTokensForDirectLogin) and setTokens writes them into Astro's wixSession cookie, so the
26
+ // next server render and every island run as the member. Other states pass through.
27
+ async function finish(raw: RawAuth): Promise<LoginResult> {
28
+ const outcome = authOutcome(raw);
29
+ if (outcome.state === "SUCCESS") {
30
+ if (!outcome.sessionToken) return failure(NO_SESSION_ERROR);
31
+ const tokens = await membersAuth.getMemberTokensForDirectLogin(outcome.sessionToken);
41
32
  membersAuth.setTokens(tokens);
42
- return { state };
33
+ return { state: "SUCCESS" };
43
34
  }
44
- return {
45
- state,
46
- ...(response.stateToken ? { stateToken: response.stateToken } : {}),
47
- ...(response.errorCode ? { errorCode: response.errorCode } : {}),
48
- ...(response.error ? { error: response.error } : {}),
49
- };
35
+ return toLoginResult(outcome);
50
36
  }
51
37
 
52
- export async function loginMember(
53
- email: string,
54
- password: string,
55
- ): Promise<LoginResult> {
56
- return finish((await membersAuth.login({ email, password })) as AuthResponse);
38
+ export async function loginMember(email: string, password: string): Promise<LoginResult> {
39
+ return finish((await membersAuth.login({ email, password })) as RawAuth);
57
40
  }
58
41
 
59
42
  export async function registerMember(
@@ -61,28 +44,16 @@ export async function registerMember(
61
44
  password: string,
62
45
  profile?: { firstName?: string; lastName?: string },
63
46
  ): Promise<LoginResult> {
64
- return finish(
65
- (await membersAuth.register({
66
- email,
67
- password,
68
- ...(profile ? { profile } : {}),
69
- })) as AuthResponse,
70
- );
47
+ return finish((await membersAuth.register({ email, password, ...(profile ? { profile } : {}) })) as RawAuth);
71
48
  }
72
49
 
73
- export async function verifyMemberEmail(
74
- verificationCode: string,
75
- ): Promise<LoginResult> {
76
- return finish(
77
- (await membersAuth.processVerification({
78
- verificationCode,
79
- })) as AuthResponse,
80
- );
50
+ /** Continue an EMAIL_VERIFICATION_REQUIRED flow with the code from the email; the strategy holds the state token. */
51
+ export async function verifyMemberEmail(verificationCode: string): Promise<LoginResult> {
52
+ return finish((await membersAuth.processVerification({ verificationCode })) as RawAuth);
81
53
  }
82
54
 
55
+ /** Log out through Wix (clears the session cookie) and land on `returnTo` — navigates away. */
83
56
  export async function logoutMember(returnTo = "/"): Promise<void> {
84
- const { logoutUrl } = await membersAuth.logout(
85
- new URL(returnTo, window.location.origin).href,
86
- );
57
+ const { logoutUrl } = await membersAuth.logout(new URL(returnTo, window.location.origin).href);
87
58
  window.location.assign(logoutUrl);
88
59
  }
@@ -4,7 +4,7 @@
4
4
  import { createClient, EMPTY_TOKENS, OAuthStrategy } from "@wix/sdk";
5
5
  import type { TokenStorage, Tokens } from "@wix/sdk";
6
6
  import { members } from "@wix/members";
7
- import { WIX_MEMBERS_CLIENT_ID } from "../../config";
7
+ import { WIX_MEMBERS_CLIENT_ID } from "../config";
8
8
 
9
9
  // `@wix/astro` uses this cookie as the session source for both browser islands
10
10
  // and the next server render. Direct login must write the exact same contract,