diff --git a/src/app/login/login.component.ts b/src/app/login/login.component.ts index b9a645fc5b..ea74663fef 100644 --- a/src/app/login/login.component.ts +++ b/src/app/login/login.component.ts @@ -21,10 +21,14 @@ export class LoginComponent implements OnInit { ngOnInit() { this.getPlanetVersion(); - this.configurationCheckService.checkConfiguration().subscribe(isOnline => { - this.online = isOnline; - }); - } + this.configurationCheckService.checkConfiguration().subscribe(isOnline => { + if (!isOnline) { + this.online = 'off'; + return; + } + this.online = isOnline; + }); + } getPlanetVersion() { const opts = { responseType: 'text', withCredentials: false, headers: { 'Content-Type': 'text/plain' } }; diff --git a/src/app/shared/configuration-check.service.ts b/src/app/shared/configuration-check.service.ts index 4884ba6eda..2437b3943e 100644 --- a/src/app/shared/configuration-check.service.ts +++ b/src/app/shared/configuration-check.service.ts @@ -1,9 +1,10 @@ import { Injectable } from '@angular/core'; +import { HttpParams } from '@angular/common/http'; import { Router } from '@angular/router'; import { environment } from '../../environments/environment'; import { CouchService } from './couchdb.service'; import { of } from 'rxjs'; -import { tap, switchMap, catchError, map } from 'rxjs/operators'; +import { switchMap, catchError, map, timeout } from 'rxjs/operators'; @Injectable({ providedIn: 'root' @@ -34,7 +35,10 @@ export class ConfigurationCheckService { if (!data[0] || data[0].planetType === 'center') { return of(false); } - return this.couchService.get('', { domain: data[0].parentDomain }); + return this.couchService.get('', { domain: data[0].parentDomain }).pipe( + timeout(3000), + catchError(() => of(false)) + ); }), map(data => { this.online = (data) ? 'on' : 'off'; @@ -46,13 +50,13 @@ export class ConfigurationCheckService { } checkAdminExistence() { - return this.couchService.get('_users/_all_docs').pipe( - tap((data) => { - return true; // user can see data so there is no admin - }), - catchError((error) => { - return of(false); // user doesn't have permission so there is an admin - }) + return this.couchService.get('_users/_all_docs', { + params: new HttpParams() + .set('limit', '1') + .set('include_docs', 'false') + }).pipe( + map(() => true), + catchError(() => of(false)) ); }