0

I am using chrome and mozilla browsers working on reactjs.

after logout i am able to redirect to the login page(please see pic(2))

1

From this login page if i click on back arrow in the browser I am able to access the application.

2

As per the project requirement once user logout I will be redirecting to login page from login untill login he should not be able to access application by enetring back button.

For on click on logout function do i need to make any thing or from login component renders i want back event should not work.

Please help me thanks in advnace.

georgeawg
  • 48,608
  • 13
  • 72
  • 95

2 Answers2

0

Clicking on logout, you are not clearing your store and hence you are still able to view application when clicking back button. In your root reducer, while combining reducers, you can handle LOGOUT action and return state as undefined.

G_S
  • 7,068
  • 2
  • 21
  • 51
  • 1
    i am clearing the store tokens i am not able to run the services when i logout. but I i am able to see the UI. – user9196877 Jan 13 '18 at 12:05
0

Goal : As per the project requirement once user logout I will be redirecting to login page from login untill login he should not be able to access application by enetring back button

Assuming you're looking for javascript solution (tags are javascript, react)

In short, you can't disable back button (or changing browser behaviour) even in native javascript see this

My suggestion

  • Client side way : use pushstate manipulation see this answer
  • Server side way : when user click logout, redirect it to temporarily page (lets say landing.php). In your landing, redirect again to login page. This way, when user hit backspace / back button he will be redirected to landing page, which then redirect again to login page making him unable to access application. Dirty, but fastest solution i guess. Take a look at my sample specially for you sample
Egy Mohammad Erdin
  • 3,402
  • 6
  • 33
  • 57