Does the compijs passport specify that the user should be stored in the database after authentication?

I am developing a simple custom crud module using compjs, a composite passport and a facebook passport. He used the default approach to generate crud, and it works fine if I want to save it to the database, but I want to save it in the session here and save the user at a later stage, the only problem is that I do not receive the request or session in the model.

Here is my user.js model

module.exports = function (compound, User) { // define User here User.findOrCreate = function (data, done) { console.log(data.profile.emails[0].value); /* FACEBOOK OPENID */ if (data.profile.provider == "facebook") { User.all({ where: { email_id: data.profile.emails[0].value }, limit: 1 }, function (err, user) { if(data.profile.gender != '' && data.profile.gender != undefined) var givenGender = (data.profile.gender == 'male')?'M':'F' else var givenGender = ''; if (user[0]) return done(err, user[0]); var userDet = { firstname: data.profile.name.givenName, lastname: data.profile.name.familyName, email_id: data.profile.emails[0].value, gender:givenGender, dob: new Date(data.profile._json.birthday), registered_from:"facebook", created_at:new Date(), updated_at:new Date() }; req.session.userdet = userDet;//This does not work done(); //req.session.userdet = userDet; // User.create({ // displayName: data.profile.displayName, // email: data.profile.emails[0].value, // facebookID: data.openId, // provider:"facebook", // createDate:new Date(), // lastLogin:new Date() // }, done); }); } else /* SOMETHING NOT KNOWN YET */ { console.log("DONT NOW HOW TO HANDLE THIS USER.") console.log(data.profile); } }; }; 

Req.session.userdet = userDet; above does not work, as I do not have a request object in the model.

Here is my facebook.js that implements facebook strategy

 var passport = require('passport'); exports.callback = function(token, tokenSecret, profile, done) { exports.User.findOrCreate({ facebookId: profile.id, profile: profile }, function (err, user) { return done(err, user); }); }; exports.init = function (conf, app) { var Strategy = require('passport-facebook').Strategy; passport.use(new Strategy({ clientID: conf.facebook.apiKey, clientSecret: conf.facebook.secret, callbackURL: conf.baseURL + 'users/signupnew' }, exports.callback)); passport.serializeUser(function(user, done) { console.log("I am here"); console.log(user); done(null, user); }); passport.deserializeUser(function(id, done) { exports.User.findById(id, function(err, user) { done(err, user); }); }); // app.get('/auth/facebook', // passport.authenticate('facebook', { scope: [ 'email,user_likes,user_birthday' ] })); // app.get('/auth/facebook/callback', // passport.authenticate('facebook', { // failureRedirect: conf.failureRedirect || '/' // }), exports.redirectOnSuccess); app.get('/users/signupnew',passport.authenticate('facebook', { failureRedirect: conf.failureRedirect || '/' }),function(req,res){ req.session.redirect = '/users/signup'; exports.redirectOnSuccess(req,res); }); }; 

Basically, I want to implement multi-stage registration, so I collect all the data in the session, and then register the user. I apologize if my understanding of the flow is wrong, as I am a new user for node and composite.

+4
source share

Source: https://habr.com/ru/post/1480062/


All Articles