StoicBuilder

HandbookIII the CastraLogin vs permissions

IIIthe Castra, Stay in control

Login vs permissions

1 min readUpdated 28 November

In plain words

Logging in (authentication) proves who someone is; permissions (authorisation) decide what they may see or change, and your server must check both.

Where you see it

Maya is logged in to Quill and opens /notes/42. The note loads, but it belongs to someone else: the app checked that she was logged in, never that the note was hers.

app/api/notes/[id]/route.tsserver
const { data: { user } } = await supabase.auth.getUser();if (!user) return new Response("Log in first", { status: 401 }); const note = await getNote(noteId);if (note.user_id !== user.id) { return new Response("Not your note", { status: 403 });}
Two separate checks: 401 when nobody is logged in, 403 when the note isn't theirs.

What goes wrong

  1. Hiding the admin button and calling it security

    The button is gone, but the admin API route still answers anyone who calls it. Every route needs its own check on the server.

  2. Checking login but not ownership

    Change 42 to 43 in the URL and someone else's note appears. Being logged in says nothing about whose data it is.

  3. Taking the user ID from the request

    If the server reads userId from what the browser sends, anyone can claim to be anyone. Get the user from the session, on the server.

    const userId = body.userId;

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
For every API route and server action, check on the server that the user is logged in and is allowed to read or change that specific record. Take the user ID from the session, never from the request, and list any route that skips either check.

Quick check

Sign in to earn +10 XP for it

A Guildhall member changes /members/12/edit to /members/13/edit and can now edit someone else's profile. What's missing?

Got a prompt that touches login vs permissions?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.