최정민

FIX : 오타수정

session file store정의부분 ; 제거

-
var express = require("express");
var router = express.Router();
var request = require("request");
//var request = require("request");
var bodyParser = require("body-parser");
var { OAuth2Client } = require("google-auth-library");
var querystring = require("querystring");
//var querystring = require("querystring");
var CLIENT_ID =
"94679084723-s5f0686p2porp9mkakrp1p89a48n24nj.apps.googleusercontent.com";
......@@ -21,8 +21,7 @@ router.use(
resave: false,
saveUninitialized: true,
store: new FileStore(),
})
);
}))
var connection = mysql.createConnection({
host: "localhost",
user: "root",
......@@ -49,6 +48,8 @@ router.post("/index", (req, res) => {
idToken: token,
audience: CLIENT_ID, // Specify the CLIENT_ID of the app that accesses the backend
});
const payload = ticket.getPayload();
const userid = payload['sub']
}
verify()
.then(() => {
......@@ -59,6 +60,8 @@ router.post("/index", (req, res) => {
});
router.get("/login", checkAuthenticated, (req, res) => {
let user = req.user;
req.session.user=user;
var sql = "SELECT * FROM USER WHERE EMAIL=?";
var parameter = [req.session.user.email];
connection.query(sql, parameter, function (err, row) {
......@@ -124,7 +127,6 @@ module.exports = router;
function checkAuthenticated(req, res, next) {
let token = req.cookies["session-token"];
let user = {};
async function verify() {
const ticket = await client.verifyIdToken({
......@@ -137,8 +139,7 @@ function checkAuthenticated(req, res, next) {
}
verify()
.then(() => {
req.session.user.name = user.name;
req.session.user.email = user.email;
req.user = user;
next();
})
.catch((err) => {
......
{"cookie":{"originalMaxAge":null,"expires":null,"httpOnly":true,"path":"/"},"__lastAccess":1621534089028,"user":{"name":"‍최정민[학생](소프트웨어융합대학 컴퓨터공학과)","email":"cjm2021401@khu.ac.kr"}}
\ No newline at end of file
{"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
......@@ -3,9 +3,9 @@
<head>
<meta charset="UTF-8">
<script src="https://apis.google.com/js/platform.js" async defer></script>
<meta name="google-signin-client_id" content=<%=d%>>
<meta name="google-signin-client_id" content="94679084723-s5f0686p2porp9mkakrp1p89a48n24nj.apps.googleusercontent.com">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%= d%></title>
<title>first</title>
<link rel='stylesheet' href='/stylesheets/style.css' />
</head>
......@@ -19,7 +19,7 @@
<script>
function onSignIn(googleUser) {
var id_token = googleUser.getAuthResponse().id_token;
//console.log(id_token);
console.log(id_token);
var xhr = new XMLHttpRequest();
xhr.open('POST', '/index');
xhr.setRequestHeader('Content-Type', 'application/json');
......