gates
gates

Reputation: 4603

Browser serving a cached version of the site

So I have this /login, where the javascript is asking the user enter a password, and we are authenticating with the server and getting back a auth_token.

We are storing that auth_token in a cookie to go to the other pages in the site. Now after entering the password, and going over to the home page.

There is a logout button, which is clearing the cookie. And setting the location = /

document.cookie = 'auth_token=;expires=Thu, 01 Jan 1990 10:50:21 PST;';
location.replace('/');

Now if I press logout, it's clearing the cookie and going to /. If I press back, it's going to a black page. This is expected.

However if I press -> on browser and do <- and -> it's still serving the cached version of the home page, which required the authentication.

The problem is it's not hitting the server to check the cookie is valid or not.

How do I prevent this cached version from serving?

Upvotes: 0

Views: 38

Answers (2)

Md Junaid Alam
Md Junaid Alam

Reputation: 1349

After logout you are clearing cookie, so before loading other pages you should check the value of cookie stored. Based on the condition redirect to another page.

Upvotes: 1

Barry Bonds
Barry Bonds

Reputation: 118

You should check if the auth_token is present in the cookie before the page loads. If the frontend is in React, the function to check should rest in componentWillMount. If it is in html/css and JS, the function should be called in a <script> tag. So, this function should be present in any page which requires a check for authentication.

Upvotes: 0

Related Questions