per-user-store
Give each signed-in user their own private data (notes, entries, history) isolated from every other user
Plane: data_pattern
Steps:
1. useCollection — Pass { layer: 'user' } — each user's documents live in a physically isolated per-user DB; no user_id filtering needed.
2. useCollection — Use insert/update/remove from the same hook for direct CRUD; the agent is not involved.
Examples
End-to-end example
import { useState } from 'react';
import { useCollection } from '@flowstack/sdk';
export function Notes() {
const [draft, setDraft] = useState('');
const { documents: notes, insert, remove } = useCollection('notes', {
layer: 'user',
sort: { created_at: -1 },
});
return (
<>
<input value={draft} onChange={e => setDraft(e.target.value)} />
<button
onClick={async () => {
await insert({ text: draft, created_at: new Date().toISOString() });
setDraft('');
}}
>
Add note
</button>
<ul>
{notes.map(n => (
<li key={n._id}>
{n.text} <button onClick={() => remove({ _id: n._id })}>×</button>
</li>
))}
</ul>
</>
);
}
Warninglayer 'user' is PHYSICAL isolation — do not also filter by user_id; there is no cross-user leakage to defend against.
WarningPer-user data is invisible to other users AND to the shared pool; use layer 'shared' for anything communal.
WarningDirect CRUD via useCollection needs no agent and no capabilities — don't route simple writes through useAgent.
See also
shared-pool · form-write-direct · reason-write-read · useCollection
Source: sync-recipes.mjs ← https://sage-api.flowstack.fun/recipes.json · Also available in llms-full.txt and registry.json.