I've encountered an issue with my authentication flow. After logging in with a user, I have to refresh the page to see the data correctly. Even after logging out and logging in with another user, the view still shows data from the previous user. It seems like it's always one step behind. I attempted to fix this by destroying the subscription but that didn't resolve the issue. Additionally, since the problem starts when I need to refresh the page for the first user's data, destroying the subscription may not be the correct solution.
Here is the code snippet:
auth.service: This is where users' credentials are posted, tokens are received, and data is stored for authenticated users.
import { Storage } from '@ionic/storage';
import { JwtHelperService } from '@auth0/angular-jwt';
export const TOKEN_KEY = 'access_token';
export const USERNAME_KEY = 'username_key';
export const USER_ID = 'user_id';
// Remaining code...
page.ts: This is where I retrieve and display the data in my view. The user service fetches a single user and the subscription is destroyed at the end.
import { Storage } from '@ionic/storage';
import { USER_ID } from 'src/app/services/auth.service';
import { SubscriptionLike } from 'rxjs';
// Remaining code...
login.ts: Manages routing to the main page.
// get return url from route parameters or default to '/'
// Remaining code...
authGuard
export class AuthGuard implements CanActivate {
// Constructor and canActivate function...
}