index.js
2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var express = require('express');
var router = express.Router();
const fs = require('fs');
const readline = require('readline');
const {google} = require('googleapis');
const bodyParser = require('body-parser');
const KakaoStrategy = require("passport-kakao").Strategy;
var passport = require('passport');
var GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
var gcal = require('google-calendar');
passport.use(new GoogleStrategy({
clientID:CLIENTID,
clientSecret:CLIENTSECRET,
callbackURL:'http://localhost:3000/auth/google/callback',
scope:['openid','email','https://www.googleapis.com/auth/calendar.readonly',
'https://www.googleapis.com/auth/calendar',
'https://www.googleapis.com/auth/calendar.events']
},
function(accessToken,refreshToken,params,profile,done){
profile.accessToken = accessToken;
return done(null,profile);
}));
router.get('/auth/google',passport.authenticate('google',{ session:false}));
router.get('/auth/google/callback',passport.authenticate('google',{
failureRedirect:'/'
}),function(req, res) {
req.session.access_token = req.user.accessToken;
res.redirect('/calendar');
});
const kakaoKey = {
clientID: KAKAO_API_KEY,
callbackURL: "/oauth/callback"
};
passport.use(
"kakao-login",
new KakaoStrategy(kakaoKey, (accessToken, refreshToken, profile, done) => {
console.log(profile);
return done(null,profile);
})
);
router.get("/kakao", passport.authenticate("kakao-login"));
router.get(
"/oauth/callback",
passport.authenticate("kakao-login",{failureRedirect:'/'}),function(req, res) {
req.session.access_token = req.user.accessToken;
res.redirect('/');
});
calList = new Array();
Calendars = new Array();
router.get('/',function(req,res,next){
res.render('index',{title:'Reminder-Talk'});
});
router.get('/logout', function(req, res) {
req.logout();
req.session = null;
res.redirect('/');
});
module.exports = router;
//db에 id 별 이벤트 저장하고 calendar page 에서 출력해주자!
//문제점 : 비동기식 진행이어서 getAllcalendarID 함수 실행 후 바로 list 출력 안됨. console.log 먼저 출력됨