Skip to content
← All posts
·3 min read

Authentication vs Authorization: What's the Difference?

AuthenticationAuthorizationSecurityWeb Dev

Authentication answers who are you? Authorization answers what are you allowed to do?

They sound similar, they're often shortened to the same word ("auth"), and mixing them up is one of the most common sources of security bugs in web apps. Here's how I think about them, with examples from apps I've built.

Authentication: proving identity

Authentication is the login step. The user proves they are who they claim to be, usually with one of:

  • Email and password
  • Magic link or one-time code sent to email or phone
  • Social sign-in (Google, Apple, GitHub) via OAuth / OpenID Connect
  • Passkeys, which are increasingly the best option

The result is a session or token that says, in effect, "this request comes from user 42." Every request after login carries that proof, usually in a secure, HTTP-only cookie.

Authentication on its own says nothing about what user 42 may do. It only establishes who they are.

Authorization: deciding permissions

Once you know who is making the request, authorization decides whether they may do this specific thing.

On the NWPM church platform I built, every visitor can read sermons and see events, but only staff can publish them from the admin dashboard. A simple role check covers that:

type Role = "member" | "staff" | "admin";
 
function canPublishSermon(user: { role: Role }) {
  return user.role === "staff" || user.role === "admin";
}

Roles aren't always enough, though. In a two-sided marketplace like Stable, which connects poultry farmers with buyers, a farmer should be able to edit listings, but only their own. That's ownership, not role:

function canEditListing(user: { id: string }, listing: { farmerId: string }) {
  return listing.farmerId === user.id;
}

Most real apps need both: role-based checks ("is this person staff?") and resource-based checks ("does this person own this record?").

Side by side

AuthenticationAuthorization
QuestionWho are you?What can you do?
WhenOnce, at login (then via session)On every request
Fails with401 Unauthorized403 Forbidden
ExampleSigning in with GoogleOnly staff can publish sermons

(Yes, the HTTP status names are confusingly swapped: 401 really means "not authenticated.")

The mistakes I see most

1. Hiding the button and calling it security

Hiding the "Delete" button from non-admins is good UX, but it isn't authorization. Anyone can send the request directly with curl or the browser dev tools. The server must check permissions on every request.

2. Checking login but not ownership

if (!session) return 401 stops anonymous users. It doesn't stop user 42 from editing user 43's order by changing an ID in the URL. This bug class, insecure direct object references (IDOR), is one of the most common in real apps. Always check that the record belongs to the user.

3. Trusting the client to say who it is

Never accept userId or role from the request body. Read them from the verified session on the server.

4. Scattering checks everywhere

When permission logic is copy-pasted across routes, one route eventually forgets it. Put checks in one place: a helper, middleware, or database row-level security (Supabase's RLS policies work well for this).

The rule of thumb

Authenticate once per session. Authorize on every request, on the server, against the specific resource. If you remember only one line from this post, make it that one.

Need help reviewing the auth setup in your app? Get in touch.

Available for work