0/24
14. User Identity

Lesson 14: User Identity

Every RPC receives ctx as its first argument. One of the most useful properties on it is ctx.user - the identity of the connected user.

export const addNote = live((ctx, text) => {
  const author = ctx.user.id;  // who called this?
});

This is set during the WebSocket upgrade and is available in every RPC and stream init function. You can use it to tag data with ownership, filter results per user, or build permission logic.

Try it

  1. Update addNote to include an author field set to ctx.user.id
  2. Create a myNotes RPC that returns only notes where author matches ctx.user.id
WebSocket
0
No messages yet
/