Implement DockPilot application stack#1
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| export async function requireAuth(req: FastifyRequest, reply: FastifyReply) { | ||
| const user = await resolveSessionUser(req); | ||
| if (!user) { | ||
| reply.code(401); | ||
| throw new Error('Unauthorized'); | ||
| } | ||
| return user; | ||
| } | ||
|
|
||
| export async function requireOwner(req: FastifyRequest, reply: FastifyReply) { | ||
| const user = await requireAuth(req, reply); | ||
| if (!user.is_owner) { | ||
| reply.code(403); | ||
| throw new Error('Forbidden'); | ||
| } |
There was a problem hiding this comment.
Return 401/403 from auth guard instead of 500
requireAuth and requireOwner set the reply status before throwing a plain Error. Fastify’s default error handler ignores reply.code() when an error is thrown and uses the error’s statusCode, so unauthenticated or non‑owner requests will respond with HTTP 500 instead of the intended 401/403. This breaks client side control flow and leaks stack traces on simple auth failures. Throw an error with an explicit statusCode (e.g. fastify.httpErrors.unauthorized()/forbidden()) or send the response directly rather than throwing.
Useful? React with 👍 / 👎.
Summary
Testing
Codex Task