diff --git a/routes/auth.js b/routes/auth.js index 6234891c859b246a006a85ae6e2976c1a8f40c50..9e2c4c36ef6a693db7525cd39157a3a694adb43b 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); } );