From 1e9d919264f1d44ab75316d22582d521929c5765 Mon Sep 17 00:00:00 2001 From: tpgus2603 <kakaneymar2424@gmail.com> Date: Tue, 3 Dec 2024 15:39:31 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/auth.js | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/routes/auth.js b/routes/auth.js index 6234891..9e2c4c3 100644 --- a/routes/auth.js +++ b/routes/auth.js @@ -4,36 +4,20 @@ const passport = require('passport'); const router = express.Router(); // GET /auth/login -router.get('/login', (req, res) => { - res.send('<a href="/auth/google">Log in with Google</a>'); -}); - -// GET /auth/logout -router.get('/logout', (req, res) => { - req.logout((err) => { - if (err) { - return res.status(500).json({ error: 'Failed to logout' }); - } - res.redirect(process.env.FRONTEND_URL || 'http://localhost:3000'); // 湲곕낯媛� �ㅼ젙 - }); -}); - -// GET /auth/google -router.get('/google', (req, res, next) => { - // 湲곕낯 redirectUrl �ㅼ젙 +router.get('/login', (req, res, next) => { + // �꾨줎�몄뿏�쒖뿉�� �꾨떖�� redirectUrl 媛��몄삤湲� const redirectUrl = req.query.redirectUrl || process.env.FRONTEND_URL || 'http://localhost:3000'; - // allowedDomains 諛곗뿴 �뺤씤 諛� 湲곕낯媛� �ㅼ젙 + // redirectUrl �좏슚�� 寃�利� const allowedDomains = [process.env.FRONTEND_URL || 'http://localhost:3000']; - - // redirectUrl 寃�利� - if (!allowedDomains.some((domain) => redirectUrl && redirectUrl.startsWith(domain))) { + if (!allowedDomains.some((domain) => redirectUrl.startsWith(domain))) { return res.status(400).json({ error: 'Invalid redirect URL' }); } - // �몄뀡�� redirectUrl ���� + // redirectUrl �몄뀡�� ���� req.session.redirectUrl = redirectUrl; + // Google OAuth �몄쬆 �쒖옉 passport.authenticate('google', { scope: ['profile', 'email'] })(req, res, next); }); @@ -48,7 +32,7 @@ router.get( // �몄뀡�먯꽌 redirectUrl �쒓굅 req.session.redirectUrl = null; - // �꾨줎�몄뿏�쒕줈 由щ떎�대젆�� + // �몄쬆 �꾨즺 �� �꾨줎�몄뿏�쒕줈 由щ떎�대젆�� res.redirect(redirectUrl); } ); -- GitLab