Skip to content

Commit

Permalink
[Server] / #8 / google oAuth
Browse files Browse the repository at this point in the history
[Server] / #8 / google oAuth
  • Loading branch information
Dev-SeungcheolLee authored Nov 17, 2020
2 parents 63f6f9a + 9120268 commit 86f2b11
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 19 deletions.
3 changes: 2 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ app.use(
'http://localhost:3000',
'http://localhost:3001',
'http://to-go-list-client.s3-website.ap-northeast-2.amazonaws.com',
'http://13.209.21.127:3001'
'http://13.209.99.91:3001',
'https://api.unsplash.com'
],
methods: ['GET', 'POST', 'PATCH'],
credentials: true
Expand Down
25 changes: 12 additions & 13 deletions controller/users/google.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {
token: token
}, {
where: {
googleId: sub
email: email
}
}).catch(err => console.log(err));

Expand All @@ -33,8 +33,6 @@ module.exports = {
email
}, 'testSecret');

console.log(sub);

user.create({
googleId: sub,
email: email,
Expand All @@ -50,29 +48,30 @@ module.exports = {
idToken: req.body.tokenId
});
const payload = ticket.getPayload();
const googleId = payload['sub'];
const email = payload['email'];

user.findOne({
attributes: ['token']
}, {
attributes: ['token', 'id'],
hooks: false,
where: {
googleId: googleId
email: email
}
}).then(result => {
let token = '';
console.log(result);
if (result.length > 0) {
console.log('DB에 있는 유저');

if (result !== null) {
// console.log('DB에 있는 유저');
token = updateToken(payload);
} else {
console.log('DB에 없는 유저');
// console.log('DB에 없는 유저');
token = insertUserIntoDB(payload);
}
res.send({ token });
req.session.userid = result.id;
res.status(200).json({ token, id: req.session.userid });
}).catch(err => console.log(err));
};

verify().then(() => { }).catch(console.error);
verify().then(() => { }).catch(err => res.status(500).send(err));
}
};

2 changes: 1 addition & 1 deletion controller/users/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {

if (userid) {
user.findByPk(userid)
.then(result => res.status(200).send(result))
.then(result => res.status(200).json(result))
.catch(err => res.status(500).send(err));
} else {
res.status(401).send('로그인 정보가 없습니다.');
Expand Down
4 changes: 2 additions & 2 deletions controller/users/signin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ module.exports = {
res.status(401).send('Invalid user');
} else {
req.session.userid = result.id;
res.status(200).send('success');
res.status(200).json({ id: req.session.userid });
}
}).catch(err => res.status(500).send(err));
}

}
};
};
1 change: 0 additions & 1 deletion models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ module.exports = (sequelize, DataTypes) => {
}
},
beforeFind: data => {
// if (Object.keys(data).indexOf('where') !== -1) {
if (data.where.password) {
let shasum = crypto.createHmac('sha512', 'to-go-SecRet!$');
shasum.update(data.where.password);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
"nodemon": "^2.0.6",
"sequelize-cli": "^6.2.0"
}
}
}

0 comments on commit 86f2b11

Please sign in to comment.