401 Unauthorized and 403 Forbidden: How to Fix It | SheCodes

Not logged in or not allowed · Usually quick to fix

401 Unauthorized and 403 Forbidden

You need to be authenticated or don’t have permission to access this resource.

What the error looks like

GET /api/profile 401 (Unauthorized)

Why it happens

The server requires authentication (a login token or API key) and either you didn’t provide one or it’s expired/invalid.

How to fix it

  1. Check that you’re sending the right API key or auth token
  2. Make sure your token hasn’t expired
  3. If it’s a protected page, make sure the user is logged in first

Ask your AI coding tool to fix it

Paste this prompt into Claude Code, Cursor, Bolt or Lovable, with your own error in place of the example.

I'm getting this error and I need help understanding and fixing it:

```
GET /api/profile 401 (Unauthorized)
```

Please:
1. Explain what this error means in plain English
2. Tell me the most likely cause
3. Give me the exact code changes or commands I need to fix it
4. Show me how to prevent this error in the future

Got a different error?

Paste any error into the free Error Decoder and get it explained in plain English, with a fix prompt.

Decode my error

More common errors explained