diff --git a/src/app/@cyborg/auth/server.interceptor.ts b/src/app/@cyborg/auth/server.interceptor.ts index 43b7d32..e5109ad 100644 --- a/src/app/@cyborg/auth/server.interceptor.ts +++ b/src/app/@cyborg/auth/server.interceptor.ts @@ -1,13 +1,12 @@ -import { Inject, Injectable, Injector } from '@angular/core'; +import { Injectable, Injector} from '@angular/core'; import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http'; import { Observable } from 'rxjs'; -import {NB_AUTH_TOKEN_INTERCEPTOR_FILTER, NbAuthService} from '@nebular/auth'; +import {NbAuthService} from '@nebular/auth'; @Injectable() export class ServerInterceptor implements HttpInterceptor { - constructor(private injector: Injector, - @Inject(NB_AUTH_TOKEN_INTERCEPTOR_FILTER) protected filter) { + constructor(private injector: Injector) { } protected get authService(): NbAuthService { @@ -16,7 +15,10 @@ export class ServerInterceptor implements HttpInterceptor { intercept(req: HttpRequest, next: HttpHandler): Observable> { const currentServer = localStorage.getItem('localServer'); - if (!this.filter(req)) { + console.log(currentServer); + console.log(req.url); + console.log(req.url.startsWith('/api/v1/')); + if (req.url.startsWith('/api/v1/') && currentServer) { req = req.clone({ url: currentServer + req.url }); diff --git a/src/app/@cyborg/auth/token.interceptor.ts b/src/app/@cyborg/auth/token.interceptor.ts index dd9a448..f0d5e7a 100644 --- a/src/app/@cyborg/auth/token.interceptor.ts +++ b/src/app/@cyborg/auth/token.interceptor.ts @@ -19,7 +19,9 @@ export class TokenInterceptor implements HttpInterceptor { } intercept(req: HttpRequest, next: HttpHandler): Observable> { - if (!this.filter(req)) { + console.log(req.url); + console.log(req.url.indexOf('/api/v1/')); + if (req.url.includes('/api/v1/')) { return this.authService.isAuthenticatedOrRefresh() .pipe( switchMap(authenticated => { diff --git a/src/app/@cyborg/components/login/login.component.ts b/src/app/@cyborg/components/login/login.component.ts index 1c17f2e..5f53224 100644 --- a/src/app/@cyborg/components/login/login.component.ts +++ b/src/app/@cyborg/components/login/login.component.ts @@ -4,50 +4,52 @@ import {Observable, of} from 'rxjs'; import {map} from 'rxjs/operators'; @Component({ - selector: 'cbg-login', - templateUrl: './login.component.html', - styleUrls: ['./login.component.scss'] + selector: 'cbg-login', + templateUrl: './login.component.html', + styleUrls: ['./login.component.scss'] }) -export class LoginComponent extends NbLoginComponent implements OnInit { - @ViewChild('cyborgServerInput') cyborgServerInput; - declare options: string[]; - specificServer = false; - filteredOptions$: Observable; - electronRunning = false; +export class LoginComponent extends NbLoginComponent implements OnInit { + @ViewChild('cyborgServerInput') cyborgServerInput; + declare options: string[]; + specificServer = false; + filteredOptions$: Observable; + electronRunning = false; - getFilteredOptions(value: string): Observable { - return of(value).pipe( - map(filterString => this.filter(filterString)), - ); - } - - onChange() { - this.filteredOptions$ = this.getFilteredOptions(this.cyborgServerInput.nativeElement.value); - } + getFilteredOptions(value: string): Observable { + return of(value).pipe( + map(filterString => this.filter(filterString)), + ); + } - onSelectionChange($event) { - this.filteredOptions$ = this.getFilteredOptions($event); - } + onChange() { + this.filteredOptions$ = this.getFilteredOptions(this.cyborgServerInput.nativeElement.value); + } - ngOnInit(): void { - if (process && process.versions.hasOwnProperty('electron')) { - this.electronRunning = true; + onSelectionChange($event) { + this.filteredOptions$ = this.getFilteredOptions($event); } - const savedServers = JSON.parse(localStorage.getItem('cyborgServers')); - this.options = []; - if (savedServers !== null && typeof savedServers === 'object' ) { - this.options = savedServers; + + ngOnInit(): void { + if (process && process.versions.hasOwnProperty('electron')) { + this.electronRunning = true; + } + const savedServers = JSON.parse(localStorage.getItem('cyborgServers')); + this.options = []; + if (savedServers !== null && typeof savedServers === 'object') { + this.options = savedServers; + } else { + this.options = []; + } } - } - checkServer(event): void { - if (!event) { - this.user.server = ''; + checkServer(event): void { + if (!event) { + this.user.server = ''; + } } - } - private filter(value: string): string[] { - const filterValue = value.toLowerCase(); - return this.options.filter(optionValue => optionValue.toLowerCase().includes(filterValue)); - } + private filter(value: string): string[] { + const filterValue = value.toLowerCase(); + return this.options.filter(optionValue => optionValue.toLowerCase().includes(filterValue)); + } } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 868d88b..aed1d7b 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -24,7 +24,7 @@ import { import { DjangoPasswordAuthStrategy } from './@core/framework/auth/djangopassword/djangopassword-strategy'; import { HomeComponent } from './home/home.component'; import { TokenInterceptor } from './@cyborg/auth/token.interceptor'; -import { ServerInterceptor } from './@cyborg/auth/server.interceptor'; +import { ServerInterceptor} from './@cyborg/auth/server.interceptor'; import { NB_AUTH_TOKEN_INTERCEPTOR_FILTER } from '@nebular/auth'; import { CyborgModule } from './@cyborg/cyborg.module'; import { HttpXSRFInterceptor } from './@cyborg/auth/xsrf.interceptor'; @@ -76,7 +76,7 @@ import { HttpXSRFInterceptor } from './@cyborg/auth/xsrf.interceptor'; }, { provide: NB_AUTH_TOKEN_INTERCEPTOR_FILTER, - useValue: (req) => req.url.indexOf('/api/v1/') !== 0, + useValue: (req) => req.url.indexOf('/api/v1/') !== -1, } ], bootstrap: [AppComponent],