'i cannot sign in to my app using existing google account

i cannot sign in to my app using existing google account. it loads when i clicked and asked me to wait a moment but then nothing happened.

my script.js

function onSignIn(googleUser) {
   $.ajax({
        url: `${baseUrl}/users/googlelogin`,
        method: "POST",
        data: {
            access_token: googleUser.getAuthResponse().id_token,
            googleToken: id_token
        }
    })
        .done((response) => {
            console.log(response, "ini response dr client")
            localStorage.setItem("access_token", response.access_token)
            authentication()
        })
        .fail((err) => {
            console.log(err);
            swal(
            "Oops!", xhr.responseJSON.error[0], "error")
            console.log(xhr.responseJSON.error[0])
        })
        


}

my controller file:

static async googleLogin(req, res, next) {
      try {
      console.log("masuk google login")

        const { id_token } = req.body
        const client = new OAuth2Client(process.env.GOOGLE_CLIENT_ID)
        const ticket = await client.verifyIdToken({
            idToken: id_token,
            audience: process.env.GOOGLE_CLIENT_ID
        });

        const payload = ticket.getPayload()
        const email = payload.email
        let password = email.toString().split('@')
        password = password[0]
        let user = await User.findOne({ where: { email } })
        if (!user) {
            let newUser = { email, password }
            let createUser = await User.create(newUser)
            const payload = {
                id: createUser.id,
                email: createUser.email
            }
            const access_token = generateToken(payload)
            return res.status(201).json({ access_token })
        } else {
            const payload = {
                id: user.id,
                email: user.email
            }
            const access_token = generateToken(payload)
            return res.status(200).json({ access_token })
        }

      } catch (err) {
          console.log(err)
          return next(err)
      }
    }

here are the error on console:

  • GET http://localhost:3000/todos 500 (Internal Server Error)
  • Uncaught {error: 'idpiframe_initialization_failed', details: 'You have created a new client application that use…i/web/guides/gis-migration) for more information.'}

i run my app on http://localhost:8080/client/



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source