Tôi đang cố gắng xác thực người dùng bằng passportjs bằng express.Vượt qua thông tin người dùng trong các tuyến đường từ các chiến lược Hộ chiếu
Passport.js trông giống như thế này.
var USER_INFO = {};
var FB_CALLBACK = 'http://localhost:3000/auth/facebook/callback';
module.exports = function(passport) {
\t passport.use(new FacebookStrategy({
\t \t clientID: FB_CLIENT_ID,
\t \t clientSecret: FB_CLIENT_SECRET,
\t \t callbackURL: FB_CALLBACK
\t },
\t function(accessToken, refreshToken, profile, done) {
\t \t process.nextTick(function() {
\t \t \t USER_INFO.id = profile.id;
\t \t });
\t }));
}
var express = require('express'); // call express
var app = express(); // define our app using express
var router = express.Router(); // get an instance of the express Route
var passport = require('passport');
USER_INFO = {};
require('./config/passport')(passport);
app.get('/auth/facebook', passport.authenticate('facebook'));
app.get('/auth/facebook/callback', passport.authenticate('facebook', {
successRedirect : '/fb',
failureRedirect : '/error'
}));
app.get('/fb', function (req, res) {
res.json(USER_INFO);
});
Tôi muốn tất cả các thông tin chiết xuất trong res.json (user_info). Nhưng nó đang trống rỗng. Những gì tôi đang thiếu ở đây. Phương pháp tốt nhất để lưu thông tin cơ bản của người dùng là gì để giữ anh ấy đăng nhập.
nopes ... nó không bắt biến. –