Struggling with async function

Hi

My node.js skills when it comes to async functions, leaves much to be desired. Below is a copy paste exercise from some code, but I can just not figure out how to return the result from this function call:

function authenticateRequest(req, res, next) {
        var request = new Request(req);
        var response = new Response(res);

       return  oauth.authenticate(request, response)
                .then(function(token) {
                        next();
                }).catch(function(err) {
                        msg.res.status(err.code || 500).json(err);
                });
}

I know the return inside the function should not be there, that is about all. I would appreciate some assistance.

Regards
Morne

Figured it out:

function authenticateRequest(req, res, next) {
        var request = new Request(req);
        var response = new Response(res);

        oauth.authenticate(request, response)
                .then(function(token) {

                        msg.statusCode=200
                        msg.payload="Congratulations, you are in a secret area!"
                        node.send(msg)
                }).catch(function(err) {
                        
                        msg.statusCode=err.statusCode
                        msg.payload=JSON.stringify(err.message)
                        node.send(msg)
                })
}

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.