OverviewHistoryStatsSecurity
npx skills add ...
Documentation
SKILL.md
npx skills add encoredev/skills --skill encore-auth
Protect Encore.ts endpoints with authentication and authorize callers. Covers `authHandler`, `Gateway`, `getAuthData`, and `auth: true`.
npx skills add encoredev/skills --skill encore-auth
Encore.ts provides a built-in authentication system for identifying API callers and protecting endpoints.
| Scenario | Handler Returns | Result |
|---|---|---|
| Valid credentials | AuthData object | Request authenticated |
| Invalid credentials | Throws APIError.unauthenticated() | Treated as no auth |
| Other error | Throws other error | Request aborted |
| Endpoint Config | Request Has Auth | Result |
|---|---|---|
auth: true | Yes | Proceeds with auth data |
auth: true | No | 401 Unauthenticated |
auth: false or omitted | Yes | Proceeds (auth data available) |
auth: false or omitted | No | Proceeds (no auth data) |
Auth data automatically propagates to internal service calls:
You can explicitly override auth data when making service-to-service calls:
Mock authentication in tests using Vitest:
getAuthData() from ~encore/auth to access auth datagetAuthData() returns null in unauthenticated requestsAPIError.unauthenticated() for invalid credentials