Passport: Promises

Created on 7 Apr 2014  Â·  5Comments  Â·  Source: jaredhanson/passport

I have the following code:

    user.save()
        .then(function () {
            req.login(user, function (err) {
                if (err) {
                    next(err);
                } else {
                    auth.login(req, res);
                }
            });
        })
        .error(function (err) {
            winston.err(err);
        });

It would be nicer as:

    user.save()
        .then(function () {
            return req.login(user);
        })
        .then(function () {
            auth.login(req, res);
        })
        .error(function (err) {
            winston.err(err);
        });

If I added support for promises to passport, would you merge it?

Most helpful comment

See issue #536 for adding promise support now that a lot of time has passed since this issue was created.

All 5 comments

Would this only impact req.login?

Sent from my iPhone

On Apr 7, 2014, at 1:20 AM, Callum Macrae [email protected] wrote:

I have the following code:

user.save()
    .then(function () {
        req.login(user, function (err) {
            if (err) {
                next(err);
            } else {
                auth.login(req, res);
            }
        });
    })
    .error(function (err) {
        winston.err(err);
    });

It would be nicer as:

user.save()
    .then(function () {
        return req.login(user);
    })
    .then(function () {
        auth.login(req, res);
    })
    .error(function (err) {
        winston.err(err);
    });

If I added support for promises to passport, would you merge it?

—
Reply to this email directly or view it on GitHub.

I think so; do any other functions accept callbacks?

On 7 Apr 2014, at 15:20, Jared Hanson [email protected] wrote:

Would this only impact req.login?

Sent from my iPhone

On Apr 7, 2014, at 1:20 AM, Callum Macrae [email protected] wrote:

I have the following code:

user.save()
.then(function () {
req.login(user, function (err) {
if (err) {
next(err);
} else {
auth.login(req, res);
}
});
})
.error(function (err) {
winston.err(err);
});
It would be nicer as:

user.save()
.then(function () {
return req.login(user);
})
.then(function () {
auth.login(req, res);
})
.error(function (err) {
winston.err(err);
});
If I added support for promises to passport, would you merge it?

—
Reply to this email directly or view it on GitHub.
—
Reply to this email directly or view it on GitHub.

No, that should be it. I'm not opposed. If you need to pull in a promise library, I'd prefer promise since that seems the most lightweight.

Closing. See comment for rationale.

See issue #536 for adding promise support now that a lot of time has passed since this issue was created.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AdityaAnand1 picture AdityaAnand1  Â·  4Comments

prakhar897 picture prakhar897  Â·  6Comments

puradox picture puradox  Â·  4Comments

JSteunou picture JSteunou  Â·  7Comments

angel1st picture angel1st  Â·  5Comments