mirror of https://github.com/Ombi-app/Ombi
Kick out the user when the user has been invalidated. This should solve a few issues with "still being logged in"
parent
a4bbb8853b
commit
87233a7fd3
@ -0,0 +1,29 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor, HttpErrorResponse } from '@angular/common/http';
|
||||||
|
import { Observable, Subject, throwError } from 'rxjs';
|
||||||
|
import { catchError, throttleTime } from 'rxjs/operators';
|
||||||
|
import { AuthService } from './auth.service';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class UnauthorizedInterceptor implements HttpInterceptor {
|
||||||
|
|
||||||
|
private throttleLogout = new Subject();
|
||||||
|
constructor(private authService: AuthService, private router: Router) {
|
||||||
|
this.throttleLogout.pipe(throttleTime(5000)).subscribe(url => {
|
||||||
|
this.authService.logout();
|
||||||
|
this.router.navigate(["login"]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
||||||
|
return next.handle(request).pipe(
|
||||||
|
catchError((response: HttpErrorResponse) => {
|
||||||
|
if (response.status === 401) {
|
||||||
|
this.throttleLogout.next();
|
||||||
|
}
|
||||||
|
return throwError(response);
|
||||||
|
}
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
@ -1,28 +0,0 @@
|
|||||||
export function getBaseLocation() {
|
|
||||||
debugger;
|
|
||||||
let paths: string[] = location.pathname.split('/').splice(1, 1);
|
|
||||||
let basePath: string = (paths && paths[0] ? paths[0] : "");
|
|
||||||
if(invalidProxies.indexOf(basePath.toUpperCase()) === -1){
|
|
||||||
return '/' + basePath;
|
|
||||||
}
|
|
||||||
return '/';
|
|
||||||
}
|
|
||||||
|
|
||||||
const invalidProxies: string[] = [
|
|
||||||
'DISCOVER',
|
|
||||||
'REQUESTS-LIST',
|
|
||||||
'SETTINGS',
|
|
||||||
'ISSUES',
|
|
||||||
'USERMANAGEMENT',
|
|
||||||
'RECENTLYADDED',
|
|
||||||
'DETAILS',
|
|
||||||
'VOTE',
|
|
||||||
'LOGIN',
|
|
||||||
'LANDINGPAGE',
|
|
||||||
'TOKEN',
|
|
||||||
'RESET',
|
|
||||||
'CUSTOM',
|
|
||||||
'AUTH',
|
|
||||||
'WIZARD',
|
|
||||||
"CALENDAR"
|
|
||||||
]
|
|
Loading…
Reference in new issue