Properly handle AuthMethod subscription in LogInComponent

This commit is contained in:
Alexandre Vryghem
2023-08-02 21:25:58 +02:00
parent 94ceee9080
commit 3dc73f9021

View File

@@ -1,5 +1,5 @@
import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core'; import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
import { Observable } from 'rxjs'; import { map, Observable } from 'rxjs';
import { select, Store } from '@ngrx/store'; import { select, Store } from '@ngrx/store';
import { AuthMethod } from '../../core/auth/models/auth.method'; import { AuthMethod } from '../../core/auth/models/auth.method';
import { import {
@@ -35,7 +35,7 @@ export class LogInComponent implements OnInit {
* The list of authentication methods available * The list of authentication methods available
* @type {AuthMethod[]} * @type {AuthMethod[]}
*/ */
public authMethods: AuthMethod[]; public authMethods: Observable<AuthMethod[]>;
/** /**
* Whether user is authenticated. * Whether user is authenticated.
@@ -55,13 +55,11 @@ export class LogInComponent implements OnInit {
} }
ngOnInit(): void { ngOnInit(): void {
this.authMethods = this.store.pipe(
this.store.pipe(
select(getAuthenticationMethods), select(getAuthenticationMethods),
).subscribe(methods => {
// ignore the ip authentication method when it's returned by the backend // ignore the ip authentication method when it's returned by the backend
this.authMethods = methods.filter(a => a.authMethodType !== AuthMethodType.Ip); map((methods: AuthMethod[]) => methods.filter((authMethod: AuthMethod) => authMethod.authMethodType !== AuthMethodType.Ip)),
}); );
// set loading // set loading
this.loading = this.store.pipe(select(isAuthenticationLoading)); this.loading = this.store.pipe(select(isAuthenticationLoading));