jaredhanson / passport-google-openidconnect

Google authentication strategy for Passport and Node.js.
https://www.passportjs.org/packages/passport-google-oidc/?utm_source=github&utm_medium=referral&utm_campaign=passport-google-oidc&utm_content=about
MIT License
14 stars 1 forks source link

ReferenceError: db is not defined #7

Open AbhayLodhi24 opened 1 year ago

AbhayLodhi24 commented 1 year ago

passport.use(new GoogleStrategy({ clientID: process.env['CLIENT_ID'], clientSecret: process.env['CLIENT_SECRET'], callbackURL: 'http://localhost:3000/auth/google/secrets' }, function(issuer, profile, cb) { console.log(profile); db.get('SELECT * FROM federated_credentials WHERE provider = ? AND subject = ?', [ issuer, profile.id ], function(err, cred) { if (err) { return cb(err); } if (!cred) { // The Google account has not logged in to this app before. Create a // newdb record and link it to the Google account. db.run('INSERT INTO users (name) VALUES (?)', [ profile.displayName ], function(err) { if (err) { return cb(err); }

      var id = this.lastID;
     db.run('INSERT INTO federated_credentials (user_id, provider, subject) VALUES (?, ?, ?)', [
        id,
        issuer,
        profile.id
      ], function(err) {
        if (err) { return cb(err); }
        var user = {
          id: id.toString(),
          name: profile.displayName
        };
        return cb(null, user);
      });
    });
  } else {
    // The Google account has previously logged in to the app.  Get the
    // user record linked to the Google account and log the user in.
   db.get('SELECT * FROM users WHERE id = ?', [ cred.user_id ], function(err, user) {
      if (err) { return cb(err); }
      if (!user) { return cb(null, false); }
      return cb(null, user);
    });
  }
});

} ));

Help me to fix it .

ebenali commented 11 months ago

post on stackexchange