From 28fdca86a613e720206838d26f14e3f8f35ee4d2 Mon Sep 17 00:00:00 2001 From: Mehtab Singh Date: Thu, 21 May 2026 15:50:48 +0530 Subject: [PATCH] fix(connect): add missing randomBytes import and rename parseGoogleState MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit randomBytes was used in generateState() without being imported from crypto, causing a ReferenceError crash on any GET /connect/github request. Also renamed parseGoogleState to parseOAuthState since the function is exclusively used in the GitHub connect flow — Google connect does not exist in this file. Closes #178 --- apps/backend/src/routes/connect.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/backend/src/routes/connect.ts b/apps/backend/src/routes/connect.ts index 68f8671..55dcd76 100644 --- a/apps/backend/src/routes/connect.ts +++ b/apps/backend/src/routes/connect.ts @@ -1,4 +1,5 @@ import type { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify'; +import { randomBytes } from 'crypto'; const GITHUB_AUTH_URL = 'https://github.com/login/oauth/authorize'; const GITHUB_TOKEN_URL = 'https://github.com/login/oauth/access_token'; @@ -61,7 +62,7 @@ export async function connectRoutes(app: FastifyInstance) { try { // Decode state to find which user requested the connect - const decodedState = parseGoogleState(state); + const decodedState = parseOAuthState(state); if (!decodedState) { return reply.redirect(`${process.env.PUBLIC_APP_URL}/settings?error=connect_failed`); @@ -155,7 +156,7 @@ export async function connectRoutes(app: FastifyInstance) { }); } -function parseGoogleState(state: string): ParsedOAuthState | null { +function parseOAuthState(state: string): ParsedOAuthState | null { try { const decoded = JSON.parse(Buffer.from(state, 'base64').toString('utf-8'));