Guestbook Example
This capsule shows a shared feed where every signed entry stores author metadata from Lakebed auth.
What It Shows
- An
entriestable withbody,authorId,authorName, andauthorPicture. - A shared
entriesquery ordered by newest first. - A
signmutation that trims and bounds user input. - Server-side authorship from
ctx.auth, not from client-submitted fields. - A Preact UI using
useAuth,useQuery,useMutation, and<SignInWithGoogle />.
Server Pattern
Use shared feeds when every user can read the same rows:
queries: {
entries: query((ctx) => ctx.db.entries.orderBy("createdAt", "desc").limit(50).all())
}
Still keep writes server-authoritative:
ctx.db.entries.insert({
body: trimmed,
authorId: ctx.auth.userId,
authorName: ctx.auth.displayName,
authorPicture: ctx.auth.picture ?? ""
});
Do not accept authorId, authorName, authorPicture, or other trusted metadata from the client.
Run It
Run the checked-in example:
npx lakebed auth as alice
npx lakebed dev examples/guestbook
Open:
http://localhost:3000
To see shared updates from multiple identities, open:
http://localhost:3000/?lakebed_guest=alice
http://localhost:3000/?lakebed_guest=bob
Then inspect state:
npx lakebed db dump --port 3000
npx lakebed logs --port 3000