문제

How would I add a variable to the request.user property?

Most of my routes involve checking for the authenticated user via "req.userusername".

How could I add another field for location. I ask this because I want to add a location field. to the req.user object.

도움이 되었습니까?

해결책

Either in the deserialization function, before returning the user

passport.deserializeUser(function(id, done) {
    getUser(id).then(function(user) {
        user.whatever = 'you like';
        return done(null, user);
    });
});

or in an express middleware (before the router).

app.use(function(req, res, next) {
    if(req.user) req.user.whatever = 'you like';
    next();
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top