Giter Site home page Giter Site logo

Comments (4)

Stephankarl avatar Stephankarl commented on May 27, 2024

from node_passport_login.

colboycolinmeeks avatar colboycolinmeeks commented on May 27, 2024

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.

inspiretk avatar inspiretk commented on May 27, 2024

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.

tapan31 avatar tapan31 commented on May 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.