(Passport.js) req.isAuthenticated() always show falsePassportJS in Nodejs never call the callback functionpassport.js authenticate popup window using sails.jsreq.session.passport and req.user blank , and req.isAuthenticated returns false after initial successful login using passport-facebookpassport req.isAuthenticated() always returns faslePassport Facebook authentication for AngularI can't get the email scope from facebook login on my website to workMessenger Chatbot - account linking and Facebook login with PassportExpress req.body not WorkingHow to send github OAuth data to client?Passport-local times out on create user (Node, Express, Postgres, Knex)

Company threw a surprise party for the CEO, 3 weeks later management says we have to pay for it, do I have to?

Two researchers want to work on the same extension to my paper. Who to help?

Has there been evidence of any other gods?

Why should password hash verification be time consistent?

Would encrypting a database protect against a compromised admin account?

What is wrong with my code? RGB potentiometer

Is it a good idea to copy a trader when investing?

Passport stamps art, can it be done?

Pre-1993 comic in which Wolverine's claws were turned to rubber?

What's the difference between const array and static const array in C/C++

Is ‘despite that’ right?

Hexagonal Grid Filling

Is this state of Earth possible, after humans left for a million years?

Is there an application which does HTTP PUT?

Which other programming languages apart from Python and predecessor are out there using indentation to define code blocks?

Extending Kan fibrations, without using minimal fibrations

How to compare d20+x with advantage to d20+y without advantage (x < y)

How can a demonic viral infection spread throughout the body without being noticed?

Why did they go to Dragonstone?

Is a vertical stabiliser needed for straight line flight in a glider?

Why do the Avengers care about returning these items in Endgame?

Can 'sudo apt-get remove [write]' destroy my Ubuntu?

What does formal training in a field mean?

What's the "magic similar to the Knock spell" referenced in the Dungeon of the Mad Mage adventure?



(Passport.js) req.isAuthenticated() always show false


PassportJS in Nodejs never call the callback functionpassport.js authenticate popup window using sails.jsreq.session.passport and req.user blank , and req.isAuthenticated returns false after initial successful login using passport-facebookpassport req.isAuthenticated() always returns faslePassport Facebook authentication for AngularI can't get the email scope from facebook login on my website to workMessenger Chatbot - account linking and Facebook login with PassportExpress req.body not WorkingHow to send github OAuth data to client?Passport-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















I am user Passport.js to loggin via Facebook
I am have a route called private, where user have to login first, if they are logged in, it will allow user to enter, otherwise it will redirect to the login page.
However everytime i try it always redirect me to the login page and req.isAuthenticate always show false.
Hope you can check it out for me, tks a lot



Here is my code



server.get('/private',(req,res)=>
console.log(req.isAuthenticated())
if (req.isAuthenticated())
res.send('welcome to private page')
else
res.redirect('/login')

)


My server.js






const next = require('next');
const routes = require('./routes');
const app = next( dev: process.env.NODE_ENV !== 'production' );
const handler = routes.getRequestHandler(app);
const port = 3000 || process.env.port
// passport
const Passport = require('passport')
const passportface = require('passport-facebook').Strategy
const db = require('./db.js')
const bodyParser = require('body-parser')
const session = require('express-session')

// With express
const express = require('express');
app.prepare().then(() =>
const server = express()
server.use(bodyParser.urlencoded(extended: true))
server.use(session(secret: 'mysecret'))
server.use(Passport.initialize())
server.use(Passport.session())
server.get('/auth/fb', Passport.authenticate('facebook', scope: ['email']))
server.get('/auth/fb/cb', Passport.authenticate('facebook',
failureRedirect:'/login',successRedirect:'/'
))
server.get('/private',(req,res)=>
console.log(req.isAuthenticated())
if (req.isAuthenticated())
res.send('welcome to private page')
else
res.redirect('/login')

)
server.use(handler).listen(3000)
console.log(`Sever is running on port $port`);
);

// Passport authenticate
Passport.use(new passportface(

clientID:'284388439125701',
clientSecret:'843d03a61b1f4b78e4efcf729b72c83d',
callbackURL:'http://localhost:3000/auth/fb/cb',
profileFields: ['email','displayName']
,
(accessToken, refreshToken, profile,done)=>
console.log(profile)
db.findOne(id: profile._json.id,(err,user)=>
if(err) return done(err)
if (user) return done(null,user)
const newUser = new db(
id: profile._json.id,
name: profile._json.name,
email: profile._json.email
)
newUser.save((err)=>
return done(null,newUser)
)
)

))

Passport.serializeUser((user,done)=>
done(null,user.id)
)

Passport.deserializeUser((id,done)=>
db.findOne(id:id,(err,user)=>
done(err, user)
)
)





My database






const mongoose = require('mongoose')
mongoose.Promise = global.Promise

mongoose.connect("mongodb://localhost/test")

const userSchema = new mongoose.Schema(
id: String,
name: String,
email: String
)

const user = mongoose.model('user', userSchema, 'user')

module.exports = user












share|improve this question






















  • I have the same issue, did you fix this?

    – Kevin Toet
    Apr 17 at 11:52

















0















I am user Passport.js to loggin via Facebook
I am have a route called private, where user have to login first, if they are logged in, it will allow user to enter, otherwise it will redirect to the login page.
However everytime i try it always redirect me to the login page and req.isAuthenticate always show false.
Hope you can check it out for me, tks a lot



Here is my code



server.get('/private',(req,res)=>
console.log(req.isAuthenticated())
if (req.isAuthenticated())
res.send('welcome to private page')
else
res.redirect('/login')

)


My server.js






const next = require('next');
const routes = require('./routes');
const app = next( dev: process.env.NODE_ENV !== 'production' );
const handler = routes.getRequestHandler(app);
const port = 3000 || process.env.port
// passport
const Passport = require('passport')
const passportface = require('passport-facebook').Strategy
const db = require('./db.js')
const bodyParser = require('body-parser')
const session = require('express-session')

// With express
const express = require('express');
app.prepare().then(() =>
const server = express()
server.use(bodyParser.urlencoded(extended: true))
server.use(session(secret: 'mysecret'))
server.use(Passport.initialize())
server.use(Passport.session())
server.get('/auth/fb', Passport.authenticate('facebook', scope: ['email']))
server.get('/auth/fb/cb', Passport.authenticate('facebook',
failureRedirect:'/login',successRedirect:'/'
))
server.get('/private',(req,res)=>
console.log(req.isAuthenticated())
if (req.isAuthenticated())
res.send('welcome to private page')
else
res.redirect('/login')

)
server.use(handler).listen(3000)
console.log(`Sever is running on port $port`);
);

// Passport authenticate
Passport.use(new passportface(

clientID:'284388439125701',
clientSecret:'843d03a61b1f4b78e4efcf729b72c83d',
callbackURL:'http://localhost:3000/auth/fb/cb',
profileFields: ['email','displayName']
,
(accessToken, refreshToken, profile,done)=>
console.log(profile)
db.findOne(id: profile._json.id,(err,user)=>
if(err) return done(err)
if (user) return done(null,user)
const newUser = new db(
id: profile._json.id,
name: profile._json.name,
email: profile._json.email
)
newUser.save((err)=>
return done(null,newUser)
)
)

))

Passport.serializeUser((user,done)=>
done(null,user.id)
)

Passport.deserializeUser((id,done)=>
db.findOne(id:id,(err,user)=>
done(err, user)
)
)





My database






const mongoose = require('mongoose')
mongoose.Promise = global.Promise

mongoose.connect("mongodb://localhost/test")

const userSchema = new mongoose.Schema(
id: String,
name: String,
email: String
)

const user = mongoose.model('user', userSchema, 'user')

module.exports = user












share|improve this question






















  • I have the same issue, did you fix this?

    – Kevin Toet
    Apr 17 at 11:52













0












0








0








I am user Passport.js to loggin via Facebook
I am have a route called private, where user have to login first, if they are logged in, it will allow user to enter, otherwise it will redirect to the login page.
However everytime i try it always redirect me to the login page and req.isAuthenticate always show false.
Hope you can check it out for me, tks a lot



Here is my code



server.get('/private',(req,res)=>
console.log(req.isAuthenticated())
if (req.isAuthenticated())
res.send('welcome to private page')
else
res.redirect('/login')

)


My server.js






const next = require('next');
const routes = require('./routes');
const app = next( dev: process.env.NODE_ENV !== 'production' );
const handler = routes.getRequestHandler(app);
const port = 3000 || process.env.port
// passport
const Passport = require('passport')
const passportface = require('passport-facebook').Strategy
const db = require('./db.js')
const bodyParser = require('body-parser')
const session = require('express-session')

// With express
const express = require('express');
app.prepare().then(() =>
const server = express()
server.use(bodyParser.urlencoded(extended: true))
server.use(session(secret: 'mysecret'))
server.use(Passport.initialize())
server.use(Passport.session())
server.get('/auth/fb', Passport.authenticate('facebook', scope: ['email']))
server.get('/auth/fb/cb', Passport.authenticate('facebook',
failureRedirect:'/login',successRedirect:'/'
))
server.get('/private',(req,res)=>
console.log(req.isAuthenticated())
if (req.isAuthenticated())
res.send('welcome to private page')
else
res.redirect('/login')

)
server.use(handler).listen(3000)
console.log(`Sever is running on port $port`);
);

// Passport authenticate
Passport.use(new passportface(

clientID:'284388439125701',
clientSecret:'843d03a61b1f4b78e4efcf729b72c83d',
callbackURL:'http://localhost:3000/auth/fb/cb',
profileFields: ['email','displayName']
,
(accessToken, refreshToken, profile,done)=>
console.log(profile)
db.findOne(id: profile._json.id,(err,user)=>
if(err) return done(err)
if (user) return done(null,user)
const newUser = new db(
id: profile._json.id,
name: profile._json.name,
email: profile._json.email
)
newUser.save((err)=>
return done(null,newUser)
)
)

))

Passport.serializeUser((user,done)=>
done(null,user.id)
)

Passport.deserializeUser((id,done)=>
db.findOne(id:id,(err,user)=>
done(err, user)
)
)





My database






const mongoose = require('mongoose')
mongoose.Promise = global.Promise

mongoose.connect("mongodb://localhost/test")

const userSchema = new mongoose.Schema(
id: String,
name: String,
email: String
)

const user = mongoose.model('user', userSchema, 'user')

module.exports = user












share|improve this question














I am user Passport.js to loggin via Facebook
I am have a route called private, where user have to login first, if they are logged in, it will allow user to enter, otherwise it will redirect to the login page.
However everytime i try it always redirect me to the login page and req.isAuthenticate always show false.
Hope you can check it out for me, tks a lot



Here is my code



server.get('/private',(req,res)=>
console.log(req.isAuthenticated())
if (req.isAuthenticated())
res.send('welcome to private page')
else
res.redirect('/login')

)


My server.js






const next = require('next');
const routes = require('./routes');
const app = next( dev: process.env.NODE_ENV !== 'production' );
const handler = routes.getRequestHandler(app);
const port = 3000 || process.env.port
// passport
const Passport = require('passport')
const passportface = require('passport-facebook').Strategy
const db = require('./db.js')
const bodyParser = require('body-parser')
const session = require('express-session')

// With express
const express = require('express');
app.prepare().then(() =>
const server = express()
server.use(bodyParser.urlencoded(extended: true))
server.use(session(secret: 'mysecret'))
server.use(Passport.initialize())
server.use(Passport.session())
server.get('/auth/fb', Passport.authenticate('facebook', scope: ['email']))
server.get('/auth/fb/cb', Passport.authenticate('facebook',
failureRedirect:'/login',successRedirect:'/'
))
server.get('/private',(req,res)=>
console.log(req.isAuthenticated())
if (req.isAuthenticated())
res.send('welcome to private page')
else
res.redirect('/login')

)
server.use(handler).listen(3000)
console.log(`Sever is running on port $port`);
);

// Passport authenticate
Passport.use(new passportface(

clientID:'284388439125701',
clientSecret:'843d03a61b1f4b78e4efcf729b72c83d',
callbackURL:'http://localhost:3000/auth/fb/cb',
profileFields: ['email','displayName']
,
(accessToken, refreshToken, profile,done)=>
console.log(profile)
db.findOne(id: profile._json.id,(err,user)=>
if(err) return done(err)
if (user) return done(null,user)
const newUser = new db(
id: profile._json.id,
name: profile._json.name,
email: profile._json.email
)
newUser.save((err)=>
return done(null,newUser)
)
)

))

Passport.serializeUser((user,done)=>
done(null,user.id)
)

Passport.deserializeUser((id,done)=>
db.findOne(id:id,(err,user)=>
done(err, user)
)
)





My database






const mongoose = require('mongoose')
mongoose.Promise = global.Promise

mongoose.connect("mongodb://localhost/test")

const userSchema = new mongoose.Schema(
id: String,
name: String,
email: String
)

const user = mongoose.model('user', userSchema, 'user')

module.exports = user








const next = require('next');
const routes = require('./routes');
const app = next( dev: process.env.NODE_ENV !== 'production' );
const handler = routes.getRequestHandler(app);
const port = 3000 || process.env.port
// passport
const Passport = require('passport')
const passportface = require('passport-facebook').Strategy
const db = require('./db.js')
const bodyParser = require('body-parser')
const session = require('express-session')

// With express
const express = require('express');
app.prepare().then(() =>
const server = express()
server.use(bodyParser.urlencoded(extended: true))
server.use(session(secret: 'mysecret'))
server.use(Passport.initialize())
server.use(Passport.session())
server.get('/auth/fb', Passport.authenticate('facebook', scope: ['email']))
server.get('/auth/fb/cb', Passport.authenticate('facebook',
failureRedirect:'/login',successRedirect:'/'
))
server.get('/private',(req,res)=>
console.log(req.isAuthenticated())
if (req.isAuthenticated())
res.send('welcome to private page')
else
res.redirect('/login')

)
server.use(handler).listen(3000)
console.log(`Sever is running on port $port`);
);

// Passport authenticate
Passport.use(new passportface(

clientID:'284388439125701',
clientSecret:'843d03a61b1f4b78e4efcf729b72c83d',
callbackURL:'http://localhost:3000/auth/fb/cb',
profileFields: ['email','displayName']
,
(accessToken, refreshToken, profile,done)=>
console.log(profile)
db.findOne(id: profile._json.id,(err,user)=>
if(err) return done(err)
if (user) return done(null,user)
const newUser = new db(
id: profile._json.id,
name: profile._json.name,
email: profile._json.email
)
newUser.save((err)=>
return done(null,newUser)
)
)

))

Passport.serializeUser((user,done)=>
done(null,user.id)
)

Passport.deserializeUser((id,done)=>
db.findOne(id:id,(err,user)=>
done(err, user)
)
)





const next = require('next');
const routes = require('./routes');
const app = next( dev: process.env.NODE_ENV !== 'production' );
const handler = routes.getRequestHandler(app);
const port = 3000 || process.env.port
// passport
const Passport = require('passport')
const passportface = require('passport-facebook').Strategy
const db = require('./db.js')
const bodyParser = require('body-parser')
const session = require('express-session')

// With express
const express = require('express');
app.prepare().then(() =>
const server = express()
server.use(bodyParser.urlencoded(extended: true))
server.use(session(secret: 'mysecret'))
server.use(Passport.initialize())
server.use(Passport.session())
server.get('/auth/fb', Passport.authenticate('facebook', scope: ['email']))
server.get('/auth/fb/cb', Passport.authenticate('facebook',
failureRedirect:'/login',successRedirect:'/'
))
server.get('/private',(req,res)=>
console.log(req.isAuthenticated())
if (req.isAuthenticated())
res.send('welcome to private page')
else
res.redirect('/login')

)
server.use(handler).listen(3000)
console.log(`Sever is running on port $port`);
);

// Passport authenticate
Passport.use(new passportface(

clientID:'284388439125701',
clientSecret:'843d03a61b1f4b78e4efcf729b72c83d',
callbackURL:'http://localhost:3000/auth/fb/cb',
profileFields: ['email','displayName']
,
(accessToken, refreshToken, profile,done)=>
console.log(profile)
db.findOne(id: profile._json.id,(err,user)=>
if(err) return done(err)
if (user) return done(null,user)
const newUser = new db(
id: profile._json.id,
name: profile._json.name,
email: profile._json.email
)
newUser.save((err)=>
return done(null,newUser)
)
)

))

Passport.serializeUser((user,done)=>
done(null,user.id)
)

Passport.deserializeUser((id,done)=>
db.findOne(id:id,(err,user)=>
done(err, user)
)
)





const mongoose = require('mongoose')
mongoose.Promise = global.Promise

mongoose.connect("mongodb://localhost/test")

const userSchema = new mongoose.Schema(
id: String,
name: String,
email: String
)

const user = mongoose.model('user', userSchema, 'user')

module.exports = user





const mongoose = require('mongoose')
mongoose.Promise = global.Promise

mongoose.connect("mongodb://localhost/test")

const userSchema = new mongoose.Schema(
id: String,
name: String,
email: String
)

const user = mongoose.model('user', userSchema, 'user')

module.exports = user






node.js passport.js






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 23 at 9:33









Bánh Phồng TômBánh Phồng Tôm

12




12












  • I have the same issue, did you fix this?

    – Kevin Toet
    Apr 17 at 11:52

















  • I have the same issue, did you fix this?

    – Kevin Toet
    Apr 17 at 11:52
















I have the same issue, did you fix this?

– Kevin Toet
Apr 17 at 11:52





I have the same issue, did you fix this?

– Kevin Toet
Apr 17 at 11:52












0






active

oldest

votes












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%2f55312391%2fpassport-js-req-isauthenticated-always-show-false%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















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%2f55312391%2fpassport-js-req-isauthenticated-always-show-false%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

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript