0

Express 2.* で動作する例がありますが、現在はバージョン 3.* に移行しています。問題は、いくつかの問題を引き起こす facebook での認証です。everyauth が Facebook に GET リクエストを送信し、エラーを返すまで、すべてが機能します。

500 Error: WARNING: You are trying to access the attribute/method configured by `findUserById`, which you did not configure. Time to configure it.

ここにapp.jsコードがあります

/**
 * Module dependencies.
 */

var express = require('express')
  , routes = require('./routes')
  , config = require('./conf/config.js')
  , user = require('./routes/user')
  , file = require('./routes/file')
  , http = require('http')
  , path = require('path')
  , everyauth = require('everyauth');

var UserService = require(__dirname + '/db/mongodb/UserService').UserService;

everyauth.facebook
  .appId(config.fb.appId)
  .scope('email')
  .fields('id,name,email')
  .appSecret(config.fb.appSecret)
  .findOrCreateUser(function(session, accessToken, accessToExtra, fbUserMetadata) {
    var promise = this.Promise();
    UserService.findOne({ email: fbUserMetadata.email }, function(err, user) {
      if (!user) {
        // Try to register user
        fbUserMetadata['accessToken'] = accessToken;
        UserService.save(fbUserMetadata);
        user = fbUserMetadata;
      }
      return promise.fulfill(user);
    });
    console.log(fbUserMetadata);
    return promise;
  })
  .findUserById(function(userId, cb) {
    console.log('findByUserId called');
    UserService.findOne({ id: userId }, function(err, user) {
      return cb(err, user);
    });
  })
  .redirectPath('/');

var app = express();

app.configure(function(){
  app.set('port', process.env.PORT || 3000);
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.favicon());
  app.use(express.logger('dev'));
  app.use(express.compress());
  app.use(express.json());
  app.use(express.urlencoded());
  app.use(express.methodOverride());
  app.use(express.cookieParser('your secret here'));
  app.use(express.session());
  app.use(everyauth.middleware(app));
  app.use(app.router);
  app.use(require('less-middleware')({ src: __dirname + '/public' }));
  app.use(express.static(path.join(__dirname, 'public')));
});

everyauth.debug = true;
//everyauth.helpExpress(app);

app.configure('development', function(){
  app.use(express.errorHandler());
});

//console.log(everyauth.facebook);

app.get('/', routes.index);
app.get('/users', user.list);

app.get('/file', file.index);
app.post('/upload', file.upload);

http.createServer(app).listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});

これを修正するには、次の行を追加します。

everyauth.everymodule.findUserById(function(userId, cb) {
    console.log('findByUserId called');
    UserService.findOne({ id: userId }, function(err, user) {
      return cb(err, user);
    });
  });
4

1 に答える 1

1

findUserByIdoneveryauth.everymoduleの代わりに on を呼び出しますeveryauth.facebook

everyauth.everymodule.findUserById(function(userId, cb) {
    console.log('findByUserId called');
    UserService.findOne({ id: userId }, function(err, user) {
        return cb(err, user);
    });
});
于 2012-12-08T21:49:28.353 に答える