최정민

FIX : 오타수정

session file store정의부분 ; 제거

-
1 var express = require("express"); 1 var express = require("express");
2 var router = express.Router(); 2 var router = express.Router();
3 3
4 -var request = require("request"); 4 +//var request = require("request");
5 var bodyParser = require("body-parser"); 5 var bodyParser = require("body-parser");
6 6
7 var { OAuth2Client } = require("google-auth-library"); 7 var { OAuth2Client } = require("google-auth-library");
8 -var querystring = require("querystring"); 8 +//var querystring = require("querystring");
9 9
10 var CLIENT_ID = 10 var CLIENT_ID =
11 "94679084723-s5f0686p2porp9mkakrp1p89a48n24nj.apps.googleusercontent.com"; 11 "94679084723-s5f0686p2porp9mkakrp1p89a48n24nj.apps.googleusercontent.com";
...@@ -21,8 +21,7 @@ router.use( ...@@ -21,8 +21,7 @@ router.use(
21 resave: false, 21 resave: false,
22 saveUninitialized: true, 22 saveUninitialized: true,
23 store: new FileStore(), 23 store: new FileStore(),
24 - }) 24 + }))
25 -);
26 var connection = mysql.createConnection({ 25 var connection = mysql.createConnection({
27 host: "localhost", 26 host: "localhost",
28 user: "root", 27 user: "root",
...@@ -49,6 +48,8 @@ router.post("/index", (req, res) => { ...@@ -49,6 +48,8 @@ router.post("/index", (req, res) => {
49 idToken: token, 48 idToken: token,
50 audience: CLIENT_ID, // Specify the CLIENT_ID of the app that accesses the backend 49 audience: CLIENT_ID, // Specify the CLIENT_ID of the app that accesses the backend
51 }); 50 });
51 + const payload = ticket.getPayload();
52 + const userid = payload['sub']
52 } 53 }
53 verify() 54 verify()
54 .then(() => { 55 .then(() => {
...@@ -59,6 +60,8 @@ router.post("/index", (req, res) => { ...@@ -59,6 +60,8 @@ router.post("/index", (req, res) => {
59 }); 60 });
60 61
61 router.get("/login", checkAuthenticated, (req, res) => { 62 router.get("/login", checkAuthenticated, (req, res) => {
63 + let user = req.user;
64 + req.session.user=user;
62 var sql = "SELECT * FROM USER WHERE EMAIL=?"; 65 var sql = "SELECT * FROM USER WHERE EMAIL=?";
63 var parameter = [req.session.user.email]; 66 var parameter = [req.session.user.email];
64 connection.query(sql, parameter, function (err, row) { 67 connection.query(sql, parameter, function (err, row) {
...@@ -124,7 +127,6 @@ module.exports = router; ...@@ -124,7 +127,6 @@ module.exports = router;
124 127
125 function checkAuthenticated(req, res, next) { 128 function checkAuthenticated(req, res, next) {
126 let token = req.cookies["session-token"]; 129 let token = req.cookies["session-token"];
127 -
128 let user = {}; 130 let user = {};
129 async function verify() { 131 async function verify() {
130 const ticket = await client.verifyIdToken({ 132 const ticket = await client.verifyIdToken({
...@@ -137,8 +139,7 @@ function checkAuthenticated(req, res, next) { ...@@ -137,8 +139,7 @@ function checkAuthenticated(req, res, next) {
137 } 139 }
138 verify() 140 verify()
139 .then(() => { 141 .then(() => {
140 - req.session.user.name = user.name; 142 + req.user = user;
141 - req.session.user.email = user.email;
142 next(); 143 next();
143 }) 144 })
144 .catch((err) => { 145 .catch((err) => {
......
1 +{"cookie":{"originalMaxAge":null,"expires":null,"httpOnly":true,"path":"/"},"__lastAccess":1621534089028,"user":{"name":"‍최정민[학생](소프트웨어융합대학 컴퓨터공학과)","email":"cjm2021401@khu.ac.kr"}}
...\ No newline at end of file ...\ No newline at end of file
1 +{"cookie":{"originalMaxAge":null,"expires":null,"httpOnly":true,"path":"/"},"__lastAccess":1621592914035,"user":{"name":"‍최정민[학생](소프트웨어융합대학 컴퓨터공학과)","email":"cjm2021401@khu.ac.kr","nickname":"MickeyMouse","age":"19","gender":"male"}}
...\ No newline at end of file ...\ No newline at end of file
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
3 <head> 3 <head>
4 <meta charset="UTF-8"> 4 <meta charset="UTF-8">
5 <script src="https://apis.google.com/js/platform.js" async defer></script> 5 <script src="https://apis.google.com/js/platform.js" async defer></script>
6 - <meta name="google-signin-client_id" content=<%=d%>> 6 + <meta name="google-signin-client_id" content="94679084723-s5f0686p2porp9mkakrp1p89a48n24nj.apps.googleusercontent.com">
7 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 7 <meta name="viewport" content="width=device-width, initial-scale=1.0">
8 - <title><%= d%></title> 8 + <title>first</title>
9 <link rel='stylesheet' href='/stylesheets/style.css' /> 9 <link rel='stylesheet' href='/stylesheets/style.css' />
10 </head> 10 </head>
11 11
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
19 <script> 19 <script>
20 function onSignIn(googleUser) { 20 function onSignIn(googleUser) {
21 var id_token = googleUser.getAuthResponse().id_token; 21 var id_token = googleUser.getAuthResponse().id_token;
22 - //console.log(id_token); 22 + console.log(id_token);
23 var xhr = new XMLHttpRequest(); 23 var xhr = new XMLHttpRequest();
24 xhr.open('POST', '/index'); 24 xhr.open('POST', '/index');
25 xhr.setRequestHeader('Content-Type', 'application/json'); 25 xhr.setRequestHeader('Content-Type', 'application/json');
......