create-pyric 0.1.0-alpha.14 → 0.1.0-alpha.15

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": "create-pyric",
3
- "version": "0.1.0-alpha.14",
3
+ "version": "0.1.0-alpha.15",
4
4
  "license": "Apache-2.0",
5
5
  "homepage": "https://pyric.dev",
6
6
  "repository": {
@@ -1,4 +1,4 @@
1
- import { onValue, ref, serverTimestamp, set } from 'firebase/database';
1
+ import { onDisconnect, onValue, ref, serverTimestamp, set } from 'firebase/database';
2
2
  import { auth, rtdb } from '../firebase/app';
3
3
  import { asUserId, type AuthUser, type PresenceEntry, type PresenceRecord, ServiceError } from '../firebase/types';
4
4
  import { requireUid } from './firestore-helpers';
@@ -24,19 +24,15 @@ export class PresenceService {
24
24
  * `/presence/{uid}` the first time a user comes online, which is what
25
25
  * fires the `onPresenceOnline` Cloud Function.
26
26
  *
27
- * In a production build we also register a real `onDisconnect` so the node
28
- * flips to offline when the socket drops. `onDisconnect` is not part of the
29
- * sandbox's Realtime Database surface yet (RTDB support is incomplete), so
30
- * under `vite dev` we rely on the explicit `goOffline` writes below.
27
+ * Register `onDisconnect` before publishing the online state so production
28
+ * and the local sandbox both flip the node to offline on a clean lifecycle
29
+ * boundary. The explicit `goOffline` method remains the user-driven path.
31
30
  */
32
31
  async goOnline(user: AuthUser): Promise<void> {
33
32
  const uid = requireUid(user.uid);
34
33
  try {
35
34
  const reference = presenceRef(uid);
36
- if (import.meta.env.PROD) {
37
- const { onDisconnect } = await import('firebase/database');
38
- await onDisconnect(reference).set({ state: 'offline', displayName: user.displayName, at: serverTimestamp() });
39
- }
35
+ await onDisconnect(reference).set({ state: 'offline', displayName: user.displayName, at: serverTimestamp() });
40
36
  await set(reference, { state: 'online', displayName: user.displayName, at: serverTimestamp() });
41
37
  } catch (error) {
42
38
  throw mapRtdbError(error);