From: Volker Theile Date: Fri, 6 Dec 2019 14:12:27 +0000 (+0100) Subject: mgr/dashboard: Use Observable in auth.service X-Git-Tag: v15.1.0~606^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=846d17e33ed0c3206e29a729aeb11fe8222a65d6;p=ceph.git mgr/dashboard: Use Observable in auth.service Signed-off-by: Volker Theile --- diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/login/login.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/login/login.component.ts index b8c5b10a61893..430efa87fa4e7 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/login/login.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/login/login.component.ts @@ -62,7 +62,7 @@ export class LoginComponent implements OnInit { } login() { - this.authService.login(this.model).then(() => { + this.authService.login(this.model).subscribe(() => { this.router.navigate(['']); }); } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/auth.service.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/auth.service.spec.ts index e7ff555705d6c..6a2e63d7b4192 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/auth.service.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/auth.service.spec.ts @@ -34,7 +34,7 @@ describe('AuthService', () => { it('should login and save the user', fakeAsync(() => { const fakeCredentials = { username: 'foo', password: 'bar' }; const fakeResponse = { username: 'foo', token: 'tokenbytes' }; - service.login(fakeCredentials); + service.login(fakeCredentials).subscribe(); const req = httpTesting.expectOne('api/auth'); expect(req.request.method).toBe('POST'); expect(req.request.body).toEqual(fakeCredentials); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/auth.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/auth.service.ts index 18382f61d12a9..8ab1fb7d43261 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/auth.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/auth.service.ts @@ -2,6 +2,9 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Router } from '@angular/router'; +import { Observable } from 'rxjs'; +import { tap } from 'rxjs/operators'; + import { Credentials } from '../models/credentials'; import { LoginResponse } from '../models/login-response'; import { AuthStorageService } from '../services/auth-storage.service'; @@ -21,13 +24,12 @@ export class AuthService { return this.http.post('api/auth/check', { token: token }); } - login(credentials: Credentials) { - return this.http - .post('api/auth', credentials) - .toPromise() - .then((resp: LoginResponse) => { + login(credentials: Credentials): Observable { + return this.http.post('api/auth', credentials).pipe( + tap((resp: LoginResponse) => { this.authStorageService.set(resp.username, resp.token, resp.permissions, resp.sso); - }); + }) + ); } logout(callback: Function = null) {