diff --git a/app.js b/app.js index bf2bd1d18a586f558a2a40416c2804c7592595c0..d504b5f84ae22dd04a2a08ab665c6b0163ec7d1b 100644 --- a/app.js +++ b/app.js @@ -17,9 +17,18 @@ const app = express(); app.use(morgan('dev')); //濡쒓퉭�� // CORS �ㅼ젙 +<<<<<<< HEAD app.use( cors({ origin: process.env.FRONTEND_URL, +======= + + +// CORS �ㅼ젙 +app.use( + cors({ + origin: 'https://yanawa.shop', +>>>>>>> 64c26d78b38c309501ec96a24f94617332a4adb4 methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], allowedHeaders: ['Content-Type', 'Authorization'], credentials: true, @@ -41,7 +50,6 @@ app.use( }) ); - // 誘몃뱾�⑥뼱 �ㅼ젙 app.use(express.json()); app.use(express.urlencoded({ extended: false })); @@ -52,6 +60,9 @@ app.use(passport.session()); app.use(flash()); + + +app.set('trust proxy', 1); console.log('MongoDB URI:', process.env.MONGO_URI); //�쇱슦�� �깅줉 const authRoutes = require('./routes/auth'); diff --git a/output.log b/output.log index 14b3255d00c51a2da75cd7010b220d1d3178280c..859d37e565baa26a03bda9b9b146163865aac083 100644 --- a/output.log +++ b/output.log @@ -1,14 +1,9 @@ MongoDB URI: mongodb+srv://admin:lim1234!!@goodmeeting.vkniz.mongodb.net/ -(node:4550) [MONGODB DRIVER] Warning: useNewUrlParser is a deprecated option: useNewUrlParser has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version +(node:17474) [MONGODB DRIVER] Warning: useNewUrlParser is a deprecated option: useNewUrlParser has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version (Use `node --trace-warnings ...` to show where the warning was created) -(node:4550) [MONGODB DRIVER] Warning: useUnifiedTopology is a deprecated option: useUnifiedTopology has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version +(node:17474) [MONGODB DRIVER] Warning: useUnifiedTopology is a deprecated option: useUnifiedTopology has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version �� MongoDB �곌껐 �깃났 Rdb�곗씠�곕쿋�댁뒪 �곌껐 �깃났. 紐⑤뱺 紐⑤뜽�� �깃났�곸쑝濡� �숆린�붾릺�덉뒿�덈떎. Server is running on 8080 -CORS Origin: undefined -[0mGET /api/auth/login [36m302[0m 7.628 ms - 0[0m -CORS Origin: undefined -[0mGET /api/schedule/all [33m401[0m 3.639 ms - 44[0m -CORS Origin: undefined -[0mGET /api/schedule/all [33m401[0m 1.347 ms - 44[0m +[0mGET /api/ [33m404[0m 6.385 ms - 143[0m diff --git a/passport/googleStrategy.js b/passport/googleStrategy.js index ada1aef6fa1cdeea29147c2e039625cae2b22424..6926deeb8ef2f6809d99e1f11b264a2ba08d9959 100644 --- a/passport/googleStrategy.js +++ b/passport/googleStrategy.js @@ -7,7 +7,6 @@ module.exports = new GoogleStrategy( clientID: process.env.GOOGLE_CLIENT_ID, clientSecret: process.env.GOOGLE_CLIENT_SECRET, callbackURL: process.env.CALLBACK_URL, - passReqToCallback: true, // req 媛앹껜瑜� 肄쒕갚�� �꾨떖 }, async (req, accessToken, refreshToken, profile, done) => { try { diff --git a/routes/auth.js b/routes/auth.js index fcf2d3ef8adf83432ddf812fe402ce1c83e0a9b2..576d37640e0fb0dd39183af4cd9c9a4b5ae7c8c5 100644 --- a/routes/auth.js +++ b/routes/auth.js @@ -6,13 +6,8 @@ const router = express.Router(); // GET api/auth/login router.get('/login', (req, res, next) => { // �꾨줎�몄뿏�쒖뿉�� �꾨떖�� redirectUrl 媛��몄삤湲� - const redirectUrl = req.query.redirectUrl || process.env.FRONTEND_URL || 'http://localhost:3000'; - - // redirectUrl �좏슚�� 寃�利� - const allowedDomains = [process.env.FRONTEND_URL || 'http://localhost:3000']; - if (!allowedDomains.some((domain) => redirectUrl.startsWith(domain))) { - return res.status(400).json({ error: 'Invalid redirect URL' }); - } + const redirectUrl = req.query.redirectUrl || process.env.FRONTEND_URL || 'https://yanawa.shop'; + // redirectUrl �좏슚�� 寃�利� // redirectUrl �몄뀡�� ���� req.session.redirectUrl = redirectUrl; @@ -20,20 +15,23 @@ router.get('/login', (req, res, next) => { // Google OAuth �몄쬆 �쒖옉 passport.authenticate('google', { scope: ['profile', 'email'] })(req, res, next); }); - -// GET /auth/google/callback router.get( '/google/callback', passport.authenticate('google', { failureRedirect: '/auth/login' }), (req, res) => { - // �몄뀡�먯꽌 redirectUrl 媛��몄삤湲� - const redirectUrl = req.session.redirectUrl || process.env.FRONTEND_URL || 'http://localhost:3000'; + const redirectUrl = req.session.redirectUrl || 'https://yanawa.shop'; + - // �몄뀡�먯꽌 redirectUrl �쒓굅 req.session.redirectUrl = null; - // �몄쬆 �꾨즺 �� �꾨줎�몄뿏�쒕줈 由щ떎�대젆�� - res.redirect(redirectUrl); + req.session.save((err) => { + if (err) { + console.error('�몄뀡 ���� �ㅻ쪟:', err); + return res.status(500).json({ error: '�쒕쾭 �ㅻ쪟' }); + } + + res.redirect(redirectUrl); + }); } ); diff --git a/weblog.log b/weblog.log index 20d81735058d1cf5007c4aad0ea514fac26e7149..b8fb89dce61a53b6ca067d18677726b612c22ac1 100644 --- a/weblog.log +++ b/weblog.log @@ -1,6 +1,6 @@ -(node:4551) [MONGODB DRIVER] Warning: useNewUrlParser is a deprecated option: useNewUrlParser has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version +(node:17475) [MONGODB DRIVER] Warning: useNewUrlParser is a deprecated option: useNewUrlParser has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version (Use `node --trace-warnings ...` to show where the warning was created) -(node:4551) [MONGODB DRIVER] Warning: useUnifiedTopology is a deprecated option: useUnifiedTopology has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version +(node:17475) [MONGODB DRIVER] Warning: useUnifiedTopology is a deprecated option: useUnifiedTopology has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version MongoDB �곌껐 �ㅽ뙣: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017 at _handleConnectionErrors (/home/ubuntu/webback/node_modules/mongoose/lib/connection.js:909:11) at NativeConnection.openUri (/home/ubuntu/webback/node_modules/mongoose/lib/connection.js:860:11)