91일차 Dev-log #20

0. 끝이 보인다.

  • 기술영상을 찍어야된다고해서 주제를 좀 생각해봐야겠다.. 내가 뭘 잘 설명할 수 있을까 ?

1. 기능 최종 배포

  • 세세한 css 를 제외하고 일단 기능이 되는지 확인하기 위해서 배포를 진행했다.
  • 구글 로그인 기능중에서 구글로그인을 누르면 구글 회원가입 및 로그인이 한꺼번에 진행이 되고 로그아웃 한다음에 다시 로그인하면 로그인이 안되는 오류가 발생했다.
  • 아래는 코드 전문

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')
        }
    },
    
  • ⭐️ 이부분! 이미 googleInfo는 선언 되어있는데 왜 또 선언해도 되는걸까?
  • 이렇게저렇게 여러 방법을 시도하다가 된거라..알다가도

Updated: