Comments (8)
How to log a user out? On subsequent get requests to the server the previous user seems to remain logged in.
if the next person wants to login , i have to forcibly logout from facebook then let the next person login to my app
from todos-express-facebook.
Inside profile.ejs, add the following line:
<p><a href="/logout">Logout</a></p>
Then go to server.js and add a logout route:
app.get('/logout', function(req, res) {
req.logout();
res.redirect('/');
});
From what I tried, passport takes care of the entire authentication process in the background so you can just call req.logout()
. You can redirect to whatever page you want the user to go after logging out.
from todos-express-facebook.
@rajojon23 Good work!
Hope @passport can add this sample to file.
from todos-express-facebook.
this doesn't seem to work any more. Can anyone else confirm?
from todos-express-facebook.
Hi, @jBachalo! @rajojon23 's answer is work for me. But I packaged server.js into a router (routers/passport.js).
This is what my app.js looks like:
var express = require('express')
, passport = require('passport');
var fb = require('./routers/passport')(passport);
app.use(passport.initialize());
app.use(passport.session());
app.use('/fb', fb);
and the routers/passport.js
var express = require('express');
var router = express.Router();
module.exports = router;
module.exports = function(passport){
var Strategy = require('passport-facebook').Strategy;
passport.use(new Strategy({
clientID: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
callbackURL: '...',
},
function(accessToken, refreshToken, profile, cb) {
return cb(null, profile);
}));
passport.serializeUser(function(user, cb) {
cb(null, user);
});
passport.deserializeUser(function(obj, cb) {
cb(null, obj);
});
router.get('/login', passport.authenticate('facebook', {}),
function(req, res) {
/* seems not be executed */
});
// callback
router.get('/return', passport.authenticate('facebook', {failureRedirect: '/'}),
function(req, res){
...
});
router.get('/logout', function(req, res) {
req.logout();
res.redirect('/');
});
return router;
}
The profile.ejs content is the same as he said.
from todos-express-facebook.
@fbukevin I presume the passprt.serializeUser is a singleton? so if you had multiple routes that were similar to this? eg, facebook/google/blarblar then which ever is called last would have the serializeUser function ??
also, I presume require(./routes/passport_facebook) is meant to be ./routers/passport ??
or have i understood something incorrectly?
from todos-express-facebook.
@WORMSS Yap, you're right. There is a typo of required file name. ./routes/passport_facebook
in app.js should be ./routers/passport
. I fixed it. Thanks!
from todos-express-facebook.
Use express session and in the logout route destroy the session
from todos-express-facebook.
Related Issues (19)
- Redirect to Messenger after successful login?
- Do both resave and saveUninitialized options have to be set to true?
- TypeError: OAuth2Strategy requires a clientID option HOT 5
- TypeError: OAuth2Strategy requires a clientID option HOT 1
- How to set envirmental variables HOT 3
- What's a "client ID"? Is this another word for "App ID"? HOT 1
- Documentation request - using accessToken on subsequent graph calls HOT 1
- AppDomain in app settings
- Get Only Token from the Facebook Passport
- Not able to go to facebook url HOT 4
- Request Object Lost context
- Getting HTTPS error HOT 4
- ReadMe Incorrect Port HOT 1
- Please ignore
- Please add failureFlash example HOT 3
- Not able to redirect to callback i.e. '/return' HOT 1
- OUTDATED readme HOT 1
- Add in user storage example HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from todos-express-facebook.