Skip to content

Commit

Permalink
Resolved an issue that caused the web client to attempt to report a l…
Browse files Browse the repository at this point in the history
…ogin event before the user's account was fully created. (#146)
  • Loading branch information
sei-bstein authored Oct 19, 2023
1 parent bd020f4 commit a379f5f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component } from '@angular/core';
import { Observable, map, tap } from 'rxjs';
import { Observable, filter, map, tap } from 'rxjs';
import { LogService } from '@/services/log.service';
import { RouterService } from '@/services/router.service';
import { ConfigService } from '@/utility/config.service';
Expand Down Expand Up @@ -42,7 +42,8 @@ export class SponsorSelectBannerComponent {
this.sponsor$ = localUserService
.user$
.pipe(
map(u => u?.sponsor)
map(u => u?.sponsor),
filter(s => !!s)
);
}
}
9 changes: 1 addition & 8 deletions projects/gameboard-ui/src/app/utility/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,7 @@ export class AuthService {
}

async externalLoginCallback(url?: string): Promise<User> {
const user = await this.mgr.signinRedirectCallback(url);

if (this.access_token()) {
// log the login event for the current user (we track date of last login and total login count)
await firstValueFrom(this.userService.updateLoginEvents());
}

return user;
return await this.mgr.signinRedirectCallback(url);
}

logout(): void {
Expand Down
17 changes: 15 additions & 2 deletions projects/gameboard-ui/src/app/utility/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@

import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { BehaviorSubject, combineLatest, of, timer } from 'rxjs';
import { catchError, filter, map, switchMap, tap } from 'rxjs/operators';
import { BehaviorSubject, combineLatest, firstValueFrom, of, timer } from 'rxjs';
import { catchError, distinctUntilChanged, filter, map, switchMap, tap } from 'rxjs/operators';
import { ApiUser, UserOidcProfile } from '../api/user-models';
import { UserService as ApiUserService } from '../api/user.service';
import { AuthService, AuthTokenState } from './auth.service';
import { ConfigService } from './config.service';
import { LogService } from '@/services/log.service';
import { UnsubscriberService } from '@/services/unsubscriber.service';

@Injectable({ providedIn: 'root' })
export class UserService {
Expand All @@ -20,6 +21,7 @@ export class UserService {
constructor(
private auth: AuthService,
private log: LogService,
private unsub: UnsubscriberService,
api: ApiUserService,
config: ConfigService,
router: Router
Expand Down Expand Up @@ -56,6 +58,17 @@ export class UserService {
this.user$.next(null);
router.navigate(['/login']);
});

// log the login event for the current user (we track date of last login and total login count)
this.unsub.add(
this.user$.pipe(
// when the user's id changes
distinctUntilChanged((prev, current) => (prev?.id || null) === (current?.id || null)),
// and when the user is truthy
filter(u => !!u),
// record a login event
).subscribe(async u => await firstValueFrom(api.updateLoginEvents()))
);
}

logout(): void {
Expand Down

0 comments on commit a379f5f

Please sign in to comment.