refactor(connect): improve type safety in connect.ts and remove remaining any usage - #596
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
|
Congratulations @hariom888 on getting PR #596 merged! Thank you for your contribution to the project. To receive the appropriate GSSoC labels and recognition, please mention @Harxhit in the #get-labels channel on our Discord server and share your merged PR link. |
…response (Dev-Card#596) 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. Co-authored-by: Hari Om <hariom888@users.noreply.github.com>
…response (Dev-Card#596) 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. Co-authored-by: Hari Om <hariom888@users.noreply.github.com>
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