(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;
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
node.js passport.js
add a comment |
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
node.js passport.js
I have the same issue, did you fix this?
– Kevin Toet
Apr 17 at 11:52
add a comment |
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
node.js passport.js
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
node.js passport.js
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
add a comment |
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
add a comment |
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
);
);
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%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
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%2f55312391%2fpassport-js-req-isauthenticated-always-show-false%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
I have the same issue, did you fix this?
– Kevin Toet
Apr 17 at 11:52