Guard / foldkit-guard

Who the client is: Me

Use Guards.me to expose the current visitor's sign-in state and global capabilities (such as "Show the Admin link") as a single-row Entity me, served by GuardServer.me:

ts
const OpenAdmin = Interaction.make('OpenAdmin')

// Shared domain code, beside the other Entities.
export const Me = Guards.me(G, {
  interactions: { [OpenAdmin.key]: [G.isAdmin] },
})

// The server: one Source among the others.
const MeSource = GuardServer.me(Me, Policy)
  • Select { signedIn: true, key: true, may: true } through Remote like any row, and call Remote.forget on sign-in or sign-out so Me updates.
  • Me uses Guards.anyone for Read and denies all writes; key exposes G.key(user) to that user, so keep it to a public ID rather than a token.