Browse Source

Improvements after code review

pull/1080/head
Thomas 3 years ago
parent
commit
0f29b3d9a9
  1. 20
      apps/client/src/app/services/internet-identity.service.ts

20
apps/client/src/app/services/internet-identity.service.ts

@ -1,20 +1,22 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Injectable, OnDestroy } from '@angular/core';
import { AuthClient } from '@dfinity/auth-client';
import { OAuthResponse } from '@ghostfolio/common/interfaces';
import { EMPTY } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { EMPTY, Subject } from 'rxjs';
import { catchError, takeUntil } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class InternetIdentityService {
export class InternetIdentityService implements OnDestroy {
private unsubscribeSubject = new Subject<void>();
public constructor(private http: HttpClient) {}
public async login(): Promise<OAuthResponse> {
const authClient = await AuthClient.create();
return await new Promise((resolve, reject) => {
return new Promise((resolve, reject) => {
authClient.login({
onError: async () => {
return reject();
@ -30,7 +32,8 @@ export class InternetIdentityService {
catchError(() => {
reject();
return EMPTY;
})
}),
takeUntil(this.unsubscribeSubject)
)
.subscribe((response) => {
resolve(response);
@ -39,4 +42,9 @@ export class InternetIdentityService {
});
});
}
public ngOnDestroy() {
this.unsubscribeSubject.next();
this.unsubscribeSubject.complete();
}
}

Loading…
Cancel
Save