Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions projects/v3/src/app/pages/home/home.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ export class HomePage implements OnInit, OnDestroy, AfterViewChecked {
this.isExpertWithoutTeam = role === 'mentor' && !teamId;
this.pulseCheckIndicatorEnabled = this.storageService.getFeature('pulseCheckIndicator');
this.isMobile = this.utils.isMobile();

// subscribe to team changes broadcast from shared service
this.sharedService.team$
.pipe(
filter(team => team !== null),
takeUntil(this.unsubscribe$)
)
.subscribe(() => {
// re-evaluate expert without team status when team changes
const currentRole = this.storageService.getUser().role;
const currentTeamId = this.storageService.getUser().teamId;
this.isExpertWithoutTeam = currentRole === 'mentor' && !currentTeamId;
});

this.homeService.milestones$
.pipe(
distinctUntilChanged(),
Expand Down Expand Up @@ -185,6 +199,8 @@ export class HomePage implements OnInit, OnDestroy, AfterViewChecked {
},
});

// call updateDashboard on initial load to ensure fresh data
this.updateDashboard();
}

ngOnDestroy(): void {
Expand All @@ -206,6 +222,13 @@ export class HomePage implements OnInit, OnDestroy, AfterViewChecked {

async updateDashboard() {
await this.sharedService.refreshJWT(); // refresh JWT token [CORE-6083]

// re-evaluate user role and team status after JWT refresh updates teamId
const role = this.storageService.getUser().role;
const teamId = this.storageService.getUser().teamId;
this.isParticipant = role === 'participant';
this.isExpertWithoutTeam = role === 'mentor' && !teamId;

this.experience = this.storageService.get("experience");
this.homeService.getMilestones({ forceRefresh: true });
this.achievementService.getAchievements();
Expand Down
12 changes: 9 additions & 3 deletions projects/v3/src/app/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ interface AuthQuery {
apikey?: string;
service?: string;
experienceUuid?: string;
forceRefresh?: boolean;
}

@Injectable({
Expand Down Expand Up @@ -154,9 +155,14 @@ export class AuthService {
const lastFetchTime: number = +this.storage.get('lastAuthFetchTime');
const authCache = this.authCache$.getValue() || this.storage.get('authCache');

// 2 conditions to pull from server:
// when experienceUuid is not null (required for switch experience)
// when authToken available (directLogin)
// conditions to pull from server:
// - when forceRefresh is true (bypass cache)
// - when experienceUuid is not null (required for switch experience)
// - when authToken available (directLogin)
if (data?.forceRefresh) {
return this.fetchData(data);
}

if (!(data?.experienceUuid || data?.authToken) && lastFetchTime && (currentTime - lastFetchTime) < this.authCacheDuration && authCache) {
return of(authCache);
} else {
Expand Down
2 changes: 1 addition & 1 deletion projects/v3/src/app/services/shared.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class SharedService {
* @return {Promise<any>} non-strict return value, we won't use
*/
async refreshJWT(): Promise<any> {
const res: AuthEndpoint = await firstValueFrom(this.authService.authenticate());
const res: AuthEndpoint = await firstValueFrom(this.authService.authenticate({ forceRefresh: true }));

const auth = res?.data?.auth;
const latestTeamId = auth?.experience?.team?.id;
Expand Down