From e67e1bf4bb529c2f3bc266507844b0ab66cf615b Mon Sep 17 00:00:00 2001
From: tpgus2603 <kakaneymar2424@gmail.com>
Date: Tue, 3 Dec 2024 15:12:34 +0900
Subject: [PATCH] =?UTF-8?q?refactor:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?=
 =?UTF-8?q?=EC=98=A4=EB=A5=98=EC=88=98=EC=A0=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 routes/auth.js | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/routes/auth.js b/routes/auth.js
index 16247d5..6234891 100644
--- a/routes/auth.js
+++ b/routes/auth.js
@@ -1,4 +1,3 @@
-// routes/auth.js
 const express = require('express');
 const passport = require('passport');
 
@@ -15,17 +14,20 @@ router.get('/logout', (req, res) => {
     if (err) {
       return res.status(500).json({ error: 'Failed to logout' });
     }
-    res.redirect(process.env.FRONTEND_URL);
+    res.redirect(process.env.FRONTEND_URL || 'http://localhost:3000'); // 湲곕낯媛� �ㅼ젙
   });
 });
 
 // GET /auth/google
 router.get('/google', (req, res, next) => {
-  const redirectUrl = req.query.redirectUrl || process.env.FRONTEND_URL;
+  // 湲곕낯 redirectUrl �ㅼ젙
+  const redirectUrl = req.query.redirectUrl || process.env.FRONTEND_URL || 'http://localhost:3000';
 
-  // 由щ떎�대젆�� URL 寃�利�
-  const allowedDomains = [process.env.FRONTEND_URL];
-  if (!allowedDomains.some((domain) => redirectUrl.startsWith(domain))) {
+  // allowedDomains 諛곗뿴 �뺤씤 諛� 湲곕낯媛� �ㅼ젙
+  const allowedDomains = [process.env.FRONTEND_URL || 'http://localhost:3000'];
+
+  // redirectUrl 寃�利�
+  if (!allowedDomains.some((domain) => redirectUrl && redirectUrl.startsWith(domain))) {
     return res.status(400).json({ error: 'Invalid redirect URL' });
   }
 
@@ -41,10 +43,12 @@ router.get(
   passport.authenticate('google', { failureRedirect: '/auth/login' }),
   (req, res) => {
     // �몄뀡�먯꽌 redirectUrl 媛��몄삤湲�
-    const redirectUrl = req.session.redirectUrl || process.env.FRONTEND_URL;
+    const redirectUrl = req.session.redirectUrl || process.env.FRONTEND_URL || 'http://localhost:3000';
 
     // �몄뀡�먯꽌 redirectUrl �쒓굅
     req.session.redirectUrl = null;
+
+    // �꾨줎�몄뿏�쒕줈 由щ떎�대젆��
     res.redirect(redirectUrl);
   }
 );
-- 
GitLab