Resolve asynchronous code before Ionic app starts


#1

Is there a way to run asynchronous code before Ionic app starts? For example read from Ionic’s Storage and pass the loaded data to a Service before the app actually starts to load a page.

I’m building Ionic application for the Desktop and mobile devices where users can login and with the help of deep links later user can access a certain page directly without need to go through the login page if the JWT token is not expired. Also this would be the case when user does press F5, the app needs to start from the current page.

With most pages I need to have data from the backend with JWT related authorization headers (which is loaded from Ionic/Storage asynchronously for the first time by AuthenticationService) but if the page component runs before the AuthenticationService loads the JWT token data from Storage the request will be without proper authorization headers and fail. Page triggers the load data from backend in the ionViewDidLoad event. Of course this problem only occurs when user does press f5 or enter a page directly with a direct URL.

Any advice to solve the problem would be appreciated :slight_smile: