From e0854903fa0999c6951447f39a2c0c29e5f4a819 Mon Sep 17 00:00:00 2001 From: KGFCH2 Date: Tue, 2 Jun 2026 14:01:58 +0530 Subject: [PATCH 1/2] fix: use configurable frontend URL for Google OAuth callback redirect --- server/routes/authRoutes.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/server/routes/authRoutes.js b/server/routes/authRoutes.js index fe66617..cd45b46 100644 --- a/server/routes/authRoutes.js +++ b/server/routes/authRoutes.js @@ -7,6 +7,8 @@ import jwt from "jsonwebtoken"; import { register, login } from "../controllers/authController.js"; +const CLIENT_URL = process.env.CLIENT_URL || "http://localhost:5173"; + const router = express.Router(); // Shared rate-limit handler that preserves CORS headers already set by @@ -53,16 +55,18 @@ router.post('/refresh', async (req, res) => { }); router.get("/google", passport.authenticate("google",{ scope: ["profile", "email"] })) -router.get("/google/callback", - passport.authenticate("google", {failureRedirect: "http://localhost:5000/auth" }), - (req, res) => { - - const token = jwt.sign({ id: req.user._id }, process.env.JWT_SECRET, { - expiresIn: process.env.JWT_EXPIRES_IN || "7d", - }) - // redirect back to frontend with token in query - res.redirect(`http://localhost:5173/app?token=${token}`) - } -) +router.get( + "/google/callback", + passport.authenticate("google", { + failureRedirect: `${CLIENT_URL}/auth?error=google_auth_failed`, + }), + (req, res) => { + const token = jwt.sign({ id: req.user._id }, process.env.JWT_SECRET, { + expiresIn: process.env.JWT_EXPIRES_IN || "7d", + }); + // Redirect back to the frontend with token in query params. + res.redirect(`${CLIENT_URL}/app?token=${encodeURIComponent(token)}`); + }, +); export default router; From 4f7ea16f8b888aeb57e3a9e4eeb2aadc17875748 Mon Sep 17 00:00:00 2001 From: KGFCH2 Date: Tue, 2 Jun 2026 14:04:52 +0530 Subject: [PATCH 2/2] fix: align OAuth redirect env var with FRONTEND_URL --- server/routes/authRoutes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/routes/authRoutes.js b/server/routes/authRoutes.js index cd45b46..daecf06 100644 --- a/server/routes/authRoutes.js +++ b/server/routes/authRoutes.js @@ -7,7 +7,7 @@ import jwt from "jsonwebtoken"; import { register, login } from "../controllers/authController.js"; -const CLIENT_URL = process.env.CLIENT_URL || "http://localhost:5173"; +const CLIENT_URL = process.env.FRONTEND_URL || "http://localhost:5173"; const router = express.Router();