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;
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
add a comment |
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
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
add a comment |
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
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
node.js authentication promise passport.js
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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);
);
I trying out the following: "Using node's promisify with passport": github.com/jaredhanson/passport/issues/605
– Jeff Tanner
Mar 24 at 23:46
add a comment |
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)
)
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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);
);
I trying out the following: "Using node's promisify with passport": github.com/jaredhanson/passport/issues/605
– Jeff Tanner
Mar 24 at 23:46
add a comment |
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);
);
I trying out the following: "Using node's promisify with passport": github.com/jaredhanson/passport/issues/605
– Jeff Tanner
Mar 24 at 23:46
add a comment |
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);
);
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);
);
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
add a comment |
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
add a comment |
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)
)
add a comment |
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)
)
add a comment |
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)
)
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)
)
answered Apr 2 at 20:09
Jeff TannerJeff Tanner
79112
79112
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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