passport.authenticate() using a Promise instead of a Custom Callbackpassport.js authenticate popup window using sails.jsHow do I convert an existing callback API to promises?Aren't promises just callbacks?Calling and Saving User Account Custom DataPassport Local Strategy with Custom Callback Never WorksWhat is the difference between Promises and Observables?Handle rejection of passport.authenticate() functionPassport Js documentation Custom Callback syntaxPassport creating custom callbackPassport-local times out on create user (Node, Express, Postgres, Knex)

If I had a daughter who (is/were/was) cute, I would be very happy

Why is long-term living in Almost-Earth causing severe health problems?

Do empty drive bays need to be filled?

The origin of the Russian proverb about two hares

A Salute to Poetry

Difference between prepositions in "...killed during/in the war"

Grep Match and extract

Trying to get (more) accurate readings from thermistor (electronics, math, and code inside)

Strange outlet behavior

How to destroy a galactic level civilization and still leave behind primitive survivors?

Zig-zag function - coded solution

Is there a DSLR/mirorless camera with minimal options like a classic, simple SLR?

Do you have to have figures when playing D&D?

How can one's career as a reviewer be ended?

Can you make an identity from this product?

Increase speed altering column on large table to NON NULL

Diatonic chords of a pentatonic vs blues scale?

Housemarks (superimposed & combined letters, heraldry)

Was Self-modifying-code possible just using BASIC?

Command of files and size

That's not my X, its Y is too Z

Is it safe to remove python 2.7.15rc1 from Ubuntu 18.04?

Transfer custom ringtones to iPhone using a computer running Linux

Why is the length of the Kelvin unit of temperature equal to that of the Celsius unit?



passport.authenticate() using a Promise instead of a Custom Callback


passport.js authenticate popup window using sails.jsHow do I convert an existing callback API to promises?Aren't promises just callbacks?Calling and Saving User Account Custom DataPassport Local Strategy with Custom Callback Never WorksWhat is the difference between Promises and Observables?Handle rejection of passport.authenticate() functionPassport Js documentation Custom Callback syntaxPassport creating custom callbackPassport-local times out on create user (Node, Express, Postgres, Knex)






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















passport.authenticate(), how can I define a Promise instead of using a Custom Ballback?



How to used passport.authenticate() is referenced within here:
http://www.passportjs.org/docs/authenticate/



Within this page, there is a section Custom Ballback:




If the built-in options are not sufficient for handling an authentication request, a custom callback can be provided to allow the application to handle success or failure.




app.get('/login', function(req, res, next) 
passport.authenticate('local', function(err, user, info)
if (err) return next(err);
if (!user) return res.redirect('/login');
req.logIn(user, function(err)
if (err) return next(err);
return res.redirect('/users/' + user.username);
);
)(req, res, next);
);


The Custom Callback is defined as:



function(err, user, info)...


What I wish to do is replace this Custom Callback with a Promise.



[Promise](resolve, reject)
.then(res =>
)
.catch(err =>
)


How can I do this? Thank you.










share|improve this question



















  • 1





    Can't your custom callback just return a promise?

    – Sterling Archer
    Mar 24 at 21:41











  • Thank you for your response, I could give that a try.

    – Jeff Tanner
    Mar 24 at 22:15

















0















passport.authenticate(), how can I define a Promise instead of using a Custom Ballback?



How to used passport.authenticate() is referenced within here:
http://www.passportjs.org/docs/authenticate/



Within this page, there is a section Custom Ballback:




If the built-in options are not sufficient for handling an authentication request, a custom callback can be provided to allow the application to handle success or failure.




app.get('/login', function(req, res, next) 
passport.authenticate('local', function(err, user, info)
if (err) return next(err);
if (!user) return res.redirect('/login');
req.logIn(user, function(err)
if (err) return next(err);
return res.redirect('/users/' + user.username);
);
)(req, res, next);
);


The Custom Callback is defined as:



function(err, user, info)...


What I wish to do is replace this Custom Callback with a Promise.



[Promise](resolve, reject)
.then(res =>
)
.catch(err =>
)


How can I do this? Thank you.










share|improve this question



















  • 1





    Can't your custom callback just return a promise?

    – Sterling Archer
    Mar 24 at 21:41











  • Thank you for your response, I could give that a try.

    – Jeff Tanner
    Mar 24 at 22:15













0












0








0








passport.authenticate(), how can I define a Promise instead of using a Custom Ballback?



How to used passport.authenticate() is referenced within here:
http://www.passportjs.org/docs/authenticate/



Within this page, there is a section Custom Ballback:




If the built-in options are not sufficient for handling an authentication request, a custom callback can be provided to allow the application to handle success or failure.




app.get('/login', function(req, res, next) 
passport.authenticate('local', function(err, user, info)
if (err) return next(err);
if (!user) return res.redirect('/login');
req.logIn(user, function(err)
if (err) return next(err);
return res.redirect('/users/' + user.username);
);
)(req, res, next);
);


The Custom Callback is defined as:



function(err, user, info)...


What I wish to do is replace this Custom Callback with a Promise.



[Promise](resolve, reject)
.then(res =>
)
.catch(err =>
)


How can I do this? Thank you.










share|improve this question
















passport.authenticate(), how can I define a Promise instead of using a Custom Ballback?



How to used passport.authenticate() is referenced within here:
http://www.passportjs.org/docs/authenticate/



Within this page, there is a section Custom Ballback:




If the built-in options are not sufficient for handling an authentication request, a custom callback can be provided to allow the application to handle success or failure.




app.get('/login', function(req, res, next) 
passport.authenticate('local', function(err, user, info)
if (err) return next(err);
if (!user) return res.redirect('/login');
req.logIn(user, function(err)
if (err) return next(err);
return res.redirect('/users/' + user.username);
);
)(req, res, next);
);


The Custom Callback is defined as:



function(err, user, info)...


What I wish to do is replace this Custom Callback with a Promise.



[Promise](resolve, reject)
.then(res =>
)
.catch(err =>
)


How can I do this? Thank you.







node.js authentication promise passport.js






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 21:41







Jeff Tanner

















asked Mar 24 at 21:39









Jeff TannerJeff Tanner

79112




79112







  • 1





    Can't your custom callback just return a promise?

    – Sterling Archer
    Mar 24 at 21:41











  • Thank you for your response, I could give that a try.

    – Jeff Tanner
    Mar 24 at 22:15












  • 1





    Can't your custom callback just return a promise?

    – Sterling Archer
    Mar 24 at 21:41











  • Thank you for your response, I could give that a try.

    – Jeff Tanner
    Mar 24 at 22:15







1




1





Can't your custom callback just return a promise?

– Sterling Archer
Mar 24 at 21:41





Can't your custom callback just return a promise?

– Sterling Archer
Mar 24 at 21:41













Thank you for your response, I could give that a try.

– Jeff Tanner
Mar 24 at 22:15





Thank you for your response, I could give that a try.

– Jeff Tanner
Mar 24 at 22:15












2 Answers
2






active

oldest

votes


















3














You can use the es6-promisify package. It is very easy to use, here is an example:



const promisify = require("es6-promisify");

// Convert the stat function
const fs = require("fs");
const stat = promisify(fs.stat);

// Now usable as a promise!
stat("example.txt").then(function (stats)
console.log("Got stats", stats);
).catch(function (err)
console.error("Yikes!", err);
);





share|improve this answer























  • I trying out the following: "Using node's promisify with passport": github.com/jaredhanson/passport/issues/605

    – Jeff Tanner
    Mar 24 at 23:46



















0














Thanks all for your helpful responses @sterling-archer and @el-finito



I had found a related issue within Passport.js Github repository helpful for using Passport to handle passport.authenticate() callback:
"Using node's promisify with passport"



export const authenticate = (req, res) =>
new Promise((resolve, reject) =>
passport.authenticate(
[passport strategy],
session: false ,
(err, user) =>
if (err) reject(new Error(err))
else if (!user) reject(new Error('Not authenticated'))
resolve(user)
)(req, res)
)





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55328833%2fpassport-authenticate-using-a-promise-instead-of-a-custom-callback%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    You can use the es6-promisify package. It is very easy to use, here is an example:



    const promisify = require("es6-promisify");

    // Convert the stat function
    const fs = require("fs");
    const stat = promisify(fs.stat);

    // Now usable as a promise!
    stat("example.txt").then(function (stats)
    console.log("Got stats", stats);
    ).catch(function (err)
    console.error("Yikes!", err);
    );





    share|improve this answer























    • I trying out the following: "Using node's promisify with passport": github.com/jaredhanson/passport/issues/605

      – Jeff Tanner
      Mar 24 at 23:46
















    3














    You can use the es6-promisify package. It is very easy to use, here is an example:



    const promisify = require("es6-promisify");

    // Convert the stat function
    const fs = require("fs");
    const stat = promisify(fs.stat);

    // Now usable as a promise!
    stat("example.txt").then(function (stats)
    console.log("Got stats", stats);
    ).catch(function (err)
    console.error("Yikes!", err);
    );





    share|improve this answer























    • I trying out the following: "Using node's promisify with passport": github.com/jaredhanson/passport/issues/605

      – Jeff Tanner
      Mar 24 at 23:46














    3












    3








    3







    You can use the es6-promisify package. It is very easy to use, here is an example:



    const promisify = require("es6-promisify");

    // Convert the stat function
    const fs = require("fs");
    const stat = promisify(fs.stat);

    // Now usable as a promise!
    stat("example.txt").then(function (stats)
    console.log("Got stats", stats);
    ).catch(function (err)
    console.error("Yikes!", err);
    );





    share|improve this answer













    You can use the es6-promisify package. It is very easy to use, here is an example:



    const promisify = require("es6-promisify");

    // Convert the stat function
    const fs = require("fs");
    const stat = promisify(fs.stat);

    // Now usable as a promise!
    stat("example.txt").then(function (stats)
    console.log("Got stats", stats);
    ).catch(function (err)
    console.error("Yikes!", err);
    );






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 24 at 21:44









    eL_FinitoeL_Finito

    285110




    285110












    • I trying out the following: "Using node's promisify with passport": github.com/jaredhanson/passport/issues/605

      – Jeff Tanner
      Mar 24 at 23:46


















    • I trying out the following: "Using node's promisify with passport": github.com/jaredhanson/passport/issues/605

      – Jeff Tanner
      Mar 24 at 23:46

















    I trying out the following: "Using node's promisify with passport": github.com/jaredhanson/passport/issues/605

    – Jeff Tanner
    Mar 24 at 23:46






    I trying out the following: "Using node's promisify with passport": github.com/jaredhanson/passport/issues/605

    – Jeff Tanner
    Mar 24 at 23:46














    0














    Thanks all for your helpful responses @sterling-archer and @el-finito



    I had found a related issue within Passport.js Github repository helpful for using Passport to handle passport.authenticate() callback:
    "Using node's promisify with passport"



    export const authenticate = (req, res) =>
    new Promise((resolve, reject) =>
    passport.authenticate(
    [passport strategy],
    session: false ,
    (err, user) =>
    if (err) reject(new Error(err))
    else if (!user) reject(new Error('Not authenticated'))
    resolve(user)
    )(req, res)
    )





    share|improve this answer



























      0














      Thanks all for your helpful responses @sterling-archer and @el-finito



      I had found a related issue within Passport.js Github repository helpful for using Passport to handle passport.authenticate() callback:
      "Using node's promisify with passport"



      export const authenticate = (req, res) =>
      new Promise((resolve, reject) =>
      passport.authenticate(
      [passport strategy],
      session: false ,
      (err, user) =>
      if (err) reject(new Error(err))
      else if (!user) reject(new Error('Not authenticated'))
      resolve(user)
      )(req, res)
      )





      share|improve this answer

























        0












        0








        0







        Thanks all for your helpful responses @sterling-archer and @el-finito



        I had found a related issue within Passport.js Github repository helpful for using Passport to handle passport.authenticate() callback:
        "Using node's promisify with passport"



        export const authenticate = (req, res) =>
        new Promise((resolve, reject) =>
        passport.authenticate(
        [passport strategy],
        session: false ,
        (err, user) =>
        if (err) reject(new Error(err))
        else if (!user) reject(new Error('Not authenticated'))
        resolve(user)
        )(req, res)
        )





        share|improve this answer













        Thanks all for your helpful responses @sterling-archer and @el-finito



        I had found a related issue within Passport.js Github repository helpful for using Passport to handle passport.authenticate() callback:
        "Using node's promisify with passport"



        export const authenticate = (req, res) =>
        new Promise((resolve, reject) =>
        passport.authenticate(
        [passport strategy],
        session: false ,
        (err, user) =>
        if (err) reject(new Error(err))
        else if (!user) reject(new Error('Not authenticated'))
        resolve(user)
        )(req, res)
        )






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 2 at 20:09









        Jeff TannerJeff Tanner

        79112




        79112



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55328833%2fpassport-authenticate-using-a-promise-instead-of-a-custom-callback%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해