refactor(connect): improve type safety in connect.ts and remove remaining any usage#596
Open
hariom888 wants to merge 1 commit into
Open
refactor(connect): improve type safety in connect.ts and remove remaining any usage#596hariom888 wants to merge 1 commit into
hariom888 wants to merge 1 commit into
Conversation
|
@hariom888 is attempting to deploy a commit to the Prashantkumar Khatri's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Hi @hariom888, Thanks for opening this pull request. This PR has been automatically classified based on the files modified. Applied Labels
Primary Review Area
Reviewer@Harxhit has been identified as the primary reviewer for this pull request. If you have any questions regarding the affected area or implementation details, feel free to reach out to the assigned reviewer. Thank you for your contribution! |
CI — All Checks PassedBackend — PASS
Mobile — SKIP
Web — SKIP
Last updated: |
…response Collapses the 4 boilerplate preauth blocks (GET /status, GET /github, GET /github/autodiscover, DELETE /:platform) down to preHandler: [app.authenticate], matching the pattern already used in auth.ts's /me and DELETE /logout routes. The FastifyJWT augmentation in types/fastify.d.ts already types request.user as AuthenticatedUser, so the (request.user as any).id casts are no longer needed. Also types the GitHub token-exchange response in github/callback using GitHubTokenResponse/GitHubTokenErrorResponse and isGitHubTokenError from utils/error.util.ts, reusing the same types auth.ts already defines for the equivalent login-flow exchange instead of �s any.
5f02f64 to
7bec51c
Compare
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.
Summary
Closes #548.
Removes the 13 remaining
anyusages inconnect.ts— 4 duplicated preauth boilerplate blocks (GET /status,GET /github,GET /github/autodiscover,DELETE /:platform), the 4(request.user as any).idcasts those blocks fed into, and the(await tokenRes.json()) as anyingithub/callback.Root cause
Each authenticated route in this file carried its own copy of:
bypassing the
FastifyInstance.authenticatedecorator type already declared intypes/fastify.d.ts, and theFastifyJWT.useraugmentation that already typesrequest.userasAuthenticatedUser.auth.ts's/meandDELETE /logoutroutes already use the cleanpreHandler: [app.authenticate]form — this PR bringsconnect.tsin line with that existing pattern rather than introducing a new one.Separately,
github/callback's token-exchange response was untyped (as any), even thoughauth.tsalready definesGitHubTokenResponse/GitHubTokenErrorResponseandisGitHubTokenErrorfor the exact same GitHub token endpoint in the login flow. This PR reuses those exports fromutils/error.util.tsinstead of duplicating or leaving it untyped.Fix
Collapse each preauth block:
Type the GitHub token exchange:
Files changed
apps/backend/src/routes/connect.tsanyusage; reuse shared auth/JWT types and GitHub token types fromerror.util.tsNo changes needed in
types/fastify.d.tsorutils/error.util.ts— both already export everything this PR reuses.Tests
No new tests — existing
__tests__/connect.test.tsalready covers both the GitHub token-exchange success and error paths, and both still pass againstisGitHubTokenError. This is a pure typing refactor with no behavior change.Checklist
anyusages remain inconnect.tstypes/fastify.d.ts) and GitHub token types (utils/error.util.ts) — no duplicate definitions introducedtsc --noEmitpasseseslintclean on the changed fileconnect.test.tssuite passes unchanged