Conversation
🦋 Changeset detectedLatest commit: 248f022 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Copilot
AI
changed the title
[WIP] Add authentication rule for Fastify plugin
Add authentication rule for Fastify with @fastify/jwt and @fastify/auth
Feb 20, 2026
38bc51d to
215d6fd
Compare
…th patterns Co-authored-by: Puppo <2527849+Puppo@users.noreply.github.com>
…ing rules Co-authored-by: Puppo <2527849+Puppo@users.noreply.github.com>
215d6fd to
4a450f2
Compare
Puppo
reviewed
Feb 23, 2026
Comment on lines
168
to
196
| async function authRoutes(fastify) { | ||
| fastify.post("/login", async (request, reply) => { | ||
| const { email, password } = request.body; | ||
| const user = await verifyCredentials(email, password); | ||
| if (!user) { | ||
| reply.status(401); | ||
| return { error: "Invalid credentials" }; | ||
| } | ||
|
|
||
| const token = fastify.jwt.sign( | ||
| { id: user.id, role: user.role }, | ||
| { expiresIn: "1h" }, | ||
| ); | ||
| return { token }; | ||
| }); | ||
|
|
||
| fastify.post("/refresh", async (request, reply) => { | ||
| const { token: oldToken } = request.body; | ||
| try { | ||
| const payload = fastify.jwt.verify(oldToken); | ||
| const newToken = fastify.jwt.sign( | ||
| { id: payload.id, role: payload.role }, | ||
| { expiresIn: "1h" }, | ||
| ); | ||
| return { token: newToken }; | ||
| } catch { | ||
| reply.status(401); | ||
| return { error: "Invalid or expired token" }; | ||
| } |
Contributor
There was a problem hiding this comment.
Can you add the Zod schema to the body of the requests and responses?
Contributor
Author
There was a problem hiding this comment.
Added Zod schemas for request bodies and responses in the login/refresh endpoints. The section now uses FastifyPluginAsyncZod with separate schema.ts file defining loginBodySchema, refreshBodySchema, tokenResponseSchema, and errorResponseSchema. See commit 248f022.
…ngeset Co-authored-by: Puppo <2527849+Puppo@users.noreply.github.com>
Contributor
Author
Puppo
approved these changes
Feb 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
New
authentication.mdrule added to thefastify-best-practiseskill covering JWT-based auth and multi-strategy composition.New rule:
rules/authentication.md(HIGH impact)@fastify/jwtplugin setup — shared plugin withauthenticatedecorator vs. inline token parsingpreHandlerhook pattern, scoped auth via_hooks.tswith autoloadFastifyPluginAsyncZod@fastify/authcomposing JWT + API key strategiesFastifyJWTpayload typesserver.jwt.sign()+inject()Documentation updates
SKILL.md,README.md, andAGENTS.mdSKILL.mdto referenceauthentication.mdREADME.mdandAGENTS.mdrules tablesCore pattern
Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.