Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I force a refresh of req.user?

I am using passport.js with local authentication strategy for my node.js/express app.

The user returned by LocalStrategy includes things like email and username.

I want to give users the ability to update their email or username within the app. When this happens, I'd like to tell passport to reload the user (similar to as if they had just logged in) so that req.user reflects the updated changes the remainder of the session. Simply setting it doesn't seem to last past that one request.

Simplified example:

app.get('/changeEmail', function(req, res, next) {

    var userId = req.user.id;
    var origEmail = req.user.email;
    var newEmail = req.param('email');

    userDao.updateEmail(userId, newEmail, function(err) {
        if (!err) {
            // user's email has changed, need change reflected in req.user from this point on
            req.user.email = newEmail;
        }
        next();
    });

});
like image 235
Aaron Silverman Avatar asked Feb 21 '14 22:02

Aaron Silverman


People also ask

How to refresh the dataset manually?

If the user have the access to dataset, he can refresh manually by Refresh now action. However, the limitation of refresh now is that datasets on shared capacity to eight daily refreshes and on a Premium capacity, you can schedule up to 48 refreshes per day in the dataset settings.

How do I force a refresh of all Group Policy settings?

First obtain the list of computers in the Computers container by using the Get-ADComputer cmdlet. Then supply the name of each computer that is returned to the Invoke-GPUpdate cmdlet. For example, to force a refresh of all Group Policy settings for all computers in the Computers container for the Contoso.com domain, use the following script:

How do you refresh PowerApps?

Instead they have to slide the 3 buttons on the left side of the screen and hit the powerapps refresh button and then relaunch the application. Most users arent aware of the 3 buttons on the left, and this "workflow" is not very intuitative.

How can I improve the user experience of the report?

Make sure that every time a user tries to open the report, he is presented with the latest data in the database ( not the pre-saved/ outdated data).


Video Answer


1 Answers

You should be able to call the logIn method on the request. This will call the serializeUser method to update the session.

userDao.updateEmail(userId, newEmail, function(err) {
    if (!err) {
        // user's email has changed, need change reflected in req.user from this point on
        var user = req.user;
        user.email = newEmail;
        req.logIn(user, function(error) {
            if (!error) {
                // successfully serialized user to session
            }
        });
    }
    next();
});
like image 152
codelark Avatar answered Sep 19 '22 09:09

codelark