All files / features/pairing usePairing.ts

100% Statements 4/4
100% Branches 0/0
100% Functions 3/3
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21                              1x   2x 4x    
import { create } from "zustand";
 
import { type PairingSnapshot, UNPAIRED } from "@/features/auth/hydrate";
 
/**
 * Pairing state derived from the `couples` document — `members: [uidA, uidB]`, no
 * gendered roles (decision record §4). The auth bootstrap is the single writer:
 * it subscribes to the couple doc and pushes snapshots in via `hydrate`. Pairing
 * itself is server-authoritative (the `pairWithCode` Cloud Function).
 */
type PairingState = PairingSnapshot & {
  hydrate: (snapshot: PairingSnapshot) => void;
  reset: () => void;
};
 
export const usePairing = create<PairingState>((set) => ({
  ...UNPAIRED,
  hydrate: (snapshot) => set(snapshot),
  reset: () => set(UNPAIRED),
}));