@pylonsync/create-pylon 0.3.303 → 0.3.305

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pylonsync/create-pylon",
3
- "version": "0.3.303",
3
+ "version": "0.3.305",
4
4
  "description": "Scaffold a new Pylon app — realtime backend + web/mobile/expo frontends in one command. Run via `npm create @pylonsync/pylon@latest`.",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -3,7 +3,7 @@
3
3
  // Shared client-side glue for Pylon Market: types, display helpers, and the
4
4
  // email/password auth bootstrap. Same-origin under native SSR, so no baseUrl —
5
5
  // init() resolves window.location.origin.
6
- import { init, configureClient, callFn, storageKey } from "@pylonsync/react";
6
+ import { init, configureClient, callFn, setSessionToken, storageKey } from "@pylonsync/react";
7
7
 
8
8
  export const APP_NAME = "market";
9
9
 
@@ -183,19 +183,28 @@ export async function ensureReadSession(): Promise<void> {
183
183
  const res = await fetch("/api/auth/guest", { method: "POST" });
184
184
  if (res.ok) {
185
185
  const body = (await res.json()) as { token?: string };
186
- if (body.token) localStorage.setItem(TOKEN(), body.token);
187
- configureClient({ appName: APP_NAME });
186
+ if (body.token) {
187
+ localStorage.setItem(TOKEN(), body.token);
188
+ configureClient({ appName: APP_NAME });
189
+ // Re-snapshot the replica under the (new) guest identity. Also resets
190
+ // the user→guest flip on sign-out.
191
+ await setSessionToken(body.token);
192
+ }
188
193
  }
189
194
  } catch {
190
195
  // Server not reachable yet — the engine retries on connect.
191
196
  }
192
197
  }
193
198
 
194
- function applySession(token: string, userId: string, name: string): void {
199
+ async function applySession(token: string, userId: string, name: string): Promise<void> {
195
200
  localStorage.setItem(TOKEN(), token);
196
201
  localStorage.setItem(USER_ID(), userId);
197
202
  localStorage.setItem(DISPLAY_NAME, name);
198
203
  configureClient({ appName: APP_NAME });
204
+ // Identity flipped (guest→user): wipe the replica + re-snapshot under the new
205
+ // identity so the user's own rows load and writes persist. Without this the
206
+ // engine keeps the guest replica and freshly-written rows vanish on refresh.
207
+ await setSessionToken(token);
199
208
  // Notify in-tab + cross-tab listeners (MarketProvider) to re-read identity.
200
209
  window.dispatchEvent(new Event("pylon-auth-changed"));
201
210
  }
@@ -213,7 +222,7 @@ export async function signIn(email: string, password: string): Promise<void> {
213
222
  const { token, user_id } = json as AuthResponse;
214
223
  // Login doesn't return displayName; default to the email handle and let
215
224
  // MarketProvider's live User query upgrade it.
216
- applySession(token, user_id, email.split("@")[0] ?? "you");
225
+ await applySession(token, user_id, email.split("@")[0] ?? "you");
217
226
  }
218
227
 
219
228
  export async function signUp(
@@ -233,7 +242,7 @@ export async function signUp(
233
242
  const json = await res.json();
234
243
  if (!res.ok) throw new Error(json.error?.message ?? "Sign-up failed");
235
244
  const { token, user_id } = json as AuthResponse;
236
- applySession(token, user_id, name || email.split("@")[0] || "you");
245
+ await applySession(token, user_id, name || email.split("@")[0] || "you");
237
246
  }
238
247
 
239
248
  export async function signOut(): Promise<void> {