Local storage fetch and conditional navigation based on it

I am doing an app where I save the user details, token fetched from REST API after the first time to local storage.
I check the local storage and will route to Login page only if local storage is empty.
After login is succesful I am writing the details to local storage and push the nav to account page which shows user details.
Now it has become like a loop where, local storage take time to write and before that navigation happens and local storage is empty and moves back to login page. but after a while the local storage is saved.

How to avoid this situation or do a work around here.

localstorage do not need more time. all actions on browsers localstorage are synchronous.

So maybe you are start routing before you call localStorage.setItem()?

Use LocalStorage with promises