How to use the passport.disconnect function in passport

To help you get started, we’ve selected a few passport examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kpi-wdc / dj / api / services / passport.js View on Github external
// defaults can be overriden, but I don't see a reason why you'd want to
      // do that.
      _.extend(options, strategies[key].options);

      self.use(new Strategy(options, self.protocols[protocol]));
    }
  });
};

/**
 * Disconnect a passport from a user
 *
 * @param  {Object} req
 * @param  {Object} res
 */
passport.disconnect = function (req, res, next) {
  var user     = req.user
    , provider = req.param('provider');

  Passport.findOne({
      provider : provider,
      user     : user.id
    }, function (err, passport) {
      if (err) {
        return next(err);
      }

      Passport.destroy(passport.id, function (error) {
        if (err) {
          return next(err);
        }
github trailsjs / sails-auth / api / services / passport.js View on Github external
// defaults can be overriden, but I don't see a reason why you'd want to
        // do that.
        _.extend(options, strategies[key].options);

        passport.use(new Strategy(options, this.protocols[protocol]));
      }
    }, passport));
  };

  /**
   * Disconnect a passport from a user
   *
   * @param  {Object} req
   * @param  {Object} res
   */
  passport.disconnect = function (req, res, next) {
    var user = req.user;
    var provider = req.param('provider');

    return sails.models.passport.findOne({
        provider: provider,
        user: user.id
      })
      .then(function (passport) {
        return sails.models.passport.destroy(passport.id);
      })
      .then(function (error) {
        next(null, user);
        return user;
      })
      .catch(next);
  };
github tilomitra / bedrock / api / services / passport.js View on Github external
// defaults can be overriden, but I don't see a reason why you'd want to
      // do that.
      _.extend(options, strategies[key].options);

      self.use(new Strategy(options, self.protocols[protocol]));
    }
  });
};

/**
 * Disconnect a passport from a user
 *
 * @param  {Object} req
 * @param  {Object} res
 */
passport.disconnect = function (req, res, next) {
  var user     = req.user
    , provider = req.param('provider', 'local')
    , query    = {};

  query.user = user.id;
  query[provider === 'local' ? 'protocol' : 'provider'] = provider;

  Passport.findOne(query, function (err, passport) {
    if (err) {
      return next(err);
    }

    Passport.destroy(passport.id, function (error) {
      if (err) {
          return next(err);
      }
github kasperisager / sails-generate-auth / templates / api / services / passport.js View on Github external
// defaults can be overriden, but I don't see a reason why you'd want to
      // do that.
      _.extend(options, strategies[key].options);

      self.use(new Strategy(options, self.protocols[protocol]));
    }
  });
};

/**
 * Disconnect a passport from a user
 *
 * @param  {Object} req
 * @param  {Object} res
 */
passport.disconnect = function (req, res, next) {
  var user     = req.user
    , provider = req.param('provider', 'local')
    , query    = {};

  query.user = user.id;
  query[provider === 'local' ? 'protocol' : 'provider'] = provider;

  Passport.findOne(query, function (err, passport) {
    if (err) {
      return next(err);
    }

    Passport.destroy(passport.id, function (error) {
      if (err) {
          return next(err);
      }
github porybox / porybox / api / services / passport.js View on Github external
// defaults can be overriden, but I don't see a reason why you'd want to
      // do that.
      _.extend(options, strategies[key].options);

      self.use(new Strategy(options, self.protocols[protocol]));
    }
  });
};

/**
 * Disconnect a passport from a user
 *
 * @param  {Object} req
 * @param  {Object} res
 */
passport.disconnect = function (req, res, next) {
  const user     = req.user,
    provider = req.param('provider', 'local'),
    query    = {};

  query.user = user.name;
  query[provider === 'local' ? 'protocol' : 'provider'] = provider;

  Passport.findOne(query, function (err, passport) {
    if (err) {
      return next(err);
    }

    Passport.destroy(passport.id, function (error) {
      if (error) {
        return next(error);
      }
github ryancp / sailng / api / services / passport.js View on Github external
// defaults can be overriden, but I don't see a reason why you'd want to
      // do that.
      _.extend(options, strategies[key].options);

      self.use(new Strategy(options, self.protocols[protocol]));
    }
  });
};

/**
 * Disconnect a passport from a user
 *
 * @param  {Object} req
 * @param  {Object} res
 */
passport.disconnect = function (req, res, next) {
  var user     = req.user
    , provider = req.param('provider');

  Passport.findOne({
      provider : provider,
      user     : user.id
    }, function (err, passport) {
      if (err) {
        return next(err);
      }

      Passport.destroy(passport.id, function (error) {
        if (err) {
          return next(err);
        }