gelilaa / VoxBox

Volunteer xChange Box is a social platform made by students in HYF Belgium that is aimed to connect both volunteers and help seekers within a community so that we can focus on channeling our inner good and assist each other to build a stronger foundation of a better world.
https://voxbox.herokuapp.com/
MIT License
2 stars 4 forks source link

Token exp fix #96

Closed yildiraykoyuncu closed 3 years ago

yildiraykoyuncu commented 3 years ago

fixed the token expiration problem. instead of giving an error now, it redirects the user to the login page

dirk-jacobs commented 3 years ago

@yildiraykoyuncu

Not 100% convinced about this solution. I have the impression, correct me if I'm wrong, that we will need to adapt every component in the application. If the application grows, this can become very error-prone

Idea is to bring a 'generic' mechanism into play. eg:

  1. middleware check on backend which removes the cookie
  2. generic check on the frontend, something like
<Route 
  path="/some-path" 
  render={() => !isAuthenticated ?
    <Login/> :
    <Redirect to="/some-path" />
}/>

What do you think ?

dirk-jacobs commented 3 years ago

Other (different, non-router-based) frontend inspiration food https://medium.com/javascript-in-plain-english/authentication-in-react-caf2abfa0494

https://codesandbox.io/s/dazzling-cloud-u6hg7?from-embed=&file=/src/protectedPage.js