googleloginController: async (req, res) => {
//클라이언트에서 response.profileObject의 내용 중 해당하는 부분만 주면
const { email, username, profileImage } = req.body // username은 email의 앞부분
const googleToken = req.headers.authorization //const googleToken = req.headers.authorization
// db에 저장되어 있는지 조회
const googleInfo = await user.findOne({
where: {
email: email,
},
})
if (googleInfo) {
const accessToken = jwt.sign(
{ id: googleInfo.id, email: googleInfo.email },
process.env.ACCESS_SECRET,
{
expiresIn: '1h',
},
)
const refreshToken = jwt.sign(
{ id: googleInfo.id, email: googleInfo.email },
process.env.REFRESH_SECRET,
{
expiresIn: '30d',
},
)
res.status(200).send({
accessToken,
refreshToken,
googleInfo,
})
} else if (!googleInfo) {
await user.create({
username: username,
email: email,
password: `${email}+${username}`,
profileImage: profileImage,
})
const googleInfo = await user.findOne({ //⭐️ 이부분!
where: {
email: email,
},
})
const accessToken = jwt.sign(
{ id: googleInfo.id, email: googleInfo.email },
process.env.ACCESS_SECRET,
{
expiresIn: '1h',
},
)
const refreshToken = jwt.sign(
{ id: googleInfo.id, email: googleInfo.email },
process.env.REFRESH_SECRET,
{
expiresIn: '30d',
},
)
return res.status(200).send({
googleInfo,
accessToken: accessToken,
refreshToken: refreshToken,
message: '구글로그인 되었습니다.',
})
} else {
res.status(500).send('err')
}
},