My introduction to Ionic (TypeScript + Angular) came out of necessity at work, as I had never worked on mobile development before. This is a whole new experience for me.
I'm currently facing an issue that has me completely stumped. Let me walk you through the scenarios:
Scenario 1
- UserA logs in with their credentials
- UserA is directed to their profile page after logging in
- UserA logs out
Scenario 2
- UserB logs in with their credentials
- UserB is redirected to the profile page after logging in (but sees UserA's profile information)
Considerations
I am using @ionic/storage to manage sessions and it doesn't seem to be a storage-related problem. After logging out, I checked await session.get('user') which returned undefined. Upon logging back in, await session.get('user') displayed the correct user (the one who just logged in).
What Could Be Going Wrong?
I suspect that Ionic is caching the page when a new user logs in, preventing the constructor and ngOnInit methods from being called again. As a result, the variables retain old user data, leading to incorrect information being displayed.
This seems like the root cause because the issue doesn't occur consistently. Sometimes everything renders correctly initially, but I'm unsure how to resolve this :/
Questions
Has anyone encountered this issue before? What steps did you take to address it?
Is there a way to instruct Ionic not to cache the page?
Can the previous content be forcibly destroyed after a router.navigate() to another page?