执行回调并将数据保存到mysql数据库中的问题

问题描述

我正在尝试使用Google Plus API进行身份验证,并尝试将Google用户详细信息保存在Google Plus API的回调函数中,但是由于某些原因,我无法将Google Plus API响应的值传递给回调请求。 Router.js的代码

df['hour'] = pd.to_datetime(df['Timestamp'],format='%H:%M:%s').dt.hour

User.controller.js中的代码

'...
shift_line = 3

With month_lines
    Do
        If .Cells(shift_line,1).Value <> "" Then
            For shifts = shift_line To .Cells(shift_line,1).CurrentRegion.Rows.Count + shift_line
                .Cells(shift_line + .Cells(shifts,9).Value,12 + .Cells(shifts,8).Value) = .Cells(shifts,7).Value
            Next shifts
        End If
        shift_line = .Cells(shift_line,1).End(xlDown).Row
    Loop Until shift_line > last_row
End With

Passport.js

router.get("/auth/google",passport.authenticate('google',{ scope: ['profile','email'] }));
router.get("/auth/google/callback",passport.authenticate('google'),googleInsert);

我遇到的问题是我不确定如何从Google身份验证中获取要在回调请求中使用的值,并且不确定回调是否有效。在我从google plus api客户端屏幕中选择电子邮件ID后,它进入无限循环,并且没有数据插入数据库

   const {
  getGoogleUserByEmail,createGoogleUser,} = require("./user.service.js");

module.exports = {
  googleInsert: (req,res) => {
    body = req.body;
    body.googleId = req.body.profile.id;
    body.firstName = req.body.profile.name.givenname;
    body.lastName = req.body.profile.name.familyName;
    body.email = req.body.profile.emails[0].value;
    body.photoUrl = req.body.profile.photos[0].value;
    //const salt = genSaltSync(10);
    //body.password = hashSync(body.password,salt);
    //verify if email id exists
    getGoogleUserByEmail(body.email,(err,results) => {
      if (err) {
        console.log(err);
      }
      //Email id already registered and exists in db
      if (results) {
        console.log("Google Email already exists");
        return res.status(409).json({
          success: 0,data: "Google Email already exist",});
      }
      console.log(
        "Google Email id is not registered,proceed with Google User Insert"
      );
      if (!results) {
        createGoogleUser(body,createResults) => {
          console.log(body);
          if (err) {
            console.log(err);
            return res.status(500).json({
              success: 0,message: "Database connection error",});
          }
          if (createResults.affectedRows == 1) {
            console.log("inside succcess is 1");
            //Insert into UserRole Table
            createuserRole(
              createResults.insertId,(body.role_id = 2),results) => {
                console.log(results);
                if (err) {
                  console.log(err);
                  return res.status(500).json({
                    success: 0,message: "DB error",});
                }
                if (!err) {
                  console.log("Google User created successfully");
                  return res.status(200).json({
                    success: 1,data: createResults,});
                }
              }
            );
          }
        });
      }
    });
  },};

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)