0

I am developing an app with ReactJs, the basic is done but now I have a problem. My app consists of 2 screens, one is called Login and the other is called Home. It's sort of a minigame linked to other pages. So if I have logged in on other pages, and then supposedly I click a button to redirect to my app, I want it to check the authentication before rendering, if the user is valid then it goes straight to Home, if not then the Login is required. Due to security reasons, I can't share any code, I just want to know what's the approach to this situation. Many thanks.

Anh Đỗ
  • 19
  • 3
  • 1
    How are the "pages" wired up? Are you using e.g. react-router? – AKX Mar 21 '22 at 10:15
  • Does this answer your question? [What is the best way to manage a user's session in React?](https://stackoverflow.com/questions/42420531/what-is-the-best-way-to-manage-a-users-session-in-react) – Matt Watson Mar 21 '22 at 10:17
  • @AKX Yes, I am. – Anh Đỗ Mar 21 '22 at 10:26
  • Okay. Then you'll need some global state to store the session in (zustand, react context, ...), and then the easiest might be to simply set up the router's routes so everything redirects to login if there are no credentials yet. Without being able to see code, that's pretty much the advice anyone can give. – AKX Mar 21 '22 at 10:28
  • Thank you, I'll try to work from there – Anh Đỗ Mar 21 '22 at 10:38

0 Answers0