Comments (4)
from node_passport_login.
After trying many, many suggestions, I decided to attack it from a different side. I'm guessing that hitting the [Back] button is pulling the page from the cache, so I figured the best way to fix the problem is to prevent pages being cached. I added this:
app.use((req, res, next) => { res.set('Cache-Control', 'no-store, no-cache, must-revalidate, private') next() })
just after
const app = express();
Now when I hit the back button after logging out, I get the login page again and the error message "Please log in to view this resource"
Hope this is of some help
Colin
from node_passport_login.
In file: node_passport_login/config/auth.js, you can add this line:
res.set('Cache-Control', 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0') // no caache so when logged out, cant browser back button to reload page, forces reload
This does what your code does, but only for pages that needs authorization. The rest of your site can be used as normal cache.
See below
module.exports = {
ensureAuthenticated: function(req, res, next) {
if (req.isAuthenticated()) {
res.set('Cache-Control', 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0') // no caache so when logged out, cant browser back button to reload page, forces reload
return next();
}
req.flash('error_msg', 'Please log in to view that resource');
res.redirect('/users/login');
},
forwardAuthenticated: function(req, res, next) {
if (!req.isAuthenticated()) {
return next();
}
res.redirect('/dashboard');
}
};
from node_passport_login.
I don't get the 'You are now logged out' flash message after logging out. Can anyone help
from node_passport_login.
Related Issues (20)
- UnhandledPromiseRejectionWarning: MongooseError: Operation `users.findOne()` buffering timed out after 10000ms HOT 4
- Error on opening Register Page HOT 2
- Error On Opening Login Page HOT 1
- Problem with passport middle authentication HOT 2
- title for test issue HOT 1
- Test 2
- test 3
- test
- Register >> if email already exists
- SyntaxError: Unexpected token '/'
- email Match
- Please help ... Bootstrap is not working
- messages.ejs showing errors (Screenshot Attached.) HOT 2
- Include statement in ejs file not correct HOT 1
- ReferenceError: newUser is not defined HOT 1
- How to deploy in IBM cloud? HOT 1
- Could not find the include file "./partials/messages" HOT 2
- _mongoose.Error.OverwriteModelError(name); HOT 2
- Error: No default engine was specified and no extension was provided. at new View (D:\Node_Passport\node_modules\express\lib\view.js:61: HOT 1
- MongoDB Compass Local URI not connecting 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 node_passport_login.