logout ut through interceptor
This commit is contained in:
parent
dbab592360
commit
ee18d0843c
|
@ -69,20 +69,20 @@ export class DmpComponent implements OnInit{
|
|||
this.dmpResource.query(params).then(dmps => this.dmps = dmps);
|
||||
}
|
||||
);
|
||||
},
|
||||
(err: HttpErrorResponse) => {
|
||||
if (err.error instanceof Error) {
|
||||
// A client-side or network error occurred. Handle it accordingly.
|
||||
console.log('An error occurred:', err.error.message);
|
||||
} else {
|
||||
// The backend returned an unsuccessful response code.
|
||||
// The response body may contain clues as to what went wrong,
|
||||
if(err.status == 401){
|
||||
this.isignOutBtn.nativeElement.click();
|
||||
}
|
||||
console.log(`Backend returned code ${err.status}, body was: ${err.error}`);
|
||||
}
|
||||
}
|
||||
// (err: HttpErrorResponse) => {
|
||||
// if (err.error instanceof Error) {
|
||||
// // A client-side or network error occurred. Handle it accordingly.
|
||||
// console.log('An error occurred:', err.error.message);
|
||||
// } else {
|
||||
// // The backend returned an unsuccessful response code.
|
||||
// // The response body may contain clues as to what went wrong,
|
||||
// if(err.status == 401){
|
||||
// this.isignOutBtn.nativeElement.click();
|
||||
// }
|
||||
// console.log(`Backend returned code ${err.status}, body was: ${err.error}`);
|
||||
// }
|
||||
// }
|
||||
);
|
||||
|
||||
this.serverService.getAllProjects().subscribe(
|
||||
|
|
|
@ -83,20 +83,20 @@ export class ProjectsComponent implements OnInit{
|
|||
this.projectResource.query(params).then(projects => this.projects = projects);
|
||||
}
|
||||
);
|
||||
},
|
||||
(err: HttpErrorResponse) => {
|
||||
if (err.error instanceof Error) {
|
||||
// A client-side or network error occurred. Handle it accordingly.
|
||||
console.log('An error occurred:', err.error.message);
|
||||
} else {
|
||||
// The backend returned an unsuccessful response code.
|
||||
// The response body may contain clues as to what went wrong,
|
||||
if(err.status == 401){
|
||||
this.isignOutBtn.nativeElement.click();
|
||||
}
|
||||
console.log(`Backend returned code ${err.status}, body was: ${err.error}`);
|
||||
}
|
||||
}
|
||||
// (err: HttpErrorResponse) => {
|
||||
// if (err.error instanceof Error) {
|
||||
// // A client-side or network error occurred. Handle it accordingly.
|
||||
// console.log('An error occurred:', err.error.message);
|
||||
// } else {
|
||||
// // The backend returned an unsuccessful response code.
|
||||
// // The response body may contain clues as to what went wrong,
|
||||
// if(err.status == 401){
|
||||
// this.isignOutBtn.nativeElement.click();
|
||||
// }
|
||||
// console.log(`Backend returned code ${err.status}, body was: ${err.error}`);
|
||||
// }
|
||||
// }
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {HttpEvent, HttpInterceptor, HttpHandler, HttpRequest, HttpResponse, HttpErrorResponse} from '@angular/common/http';
|
||||
import { TokenService, TokenProvider } from './token.service';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class GlobalInterceptor implements HttpInterceptor {
|
||||
|
||||
constructor() {
|
||||
constructor(private tokenService: TokenService) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -21,7 +22,12 @@ export class GlobalInterceptor implements HttpInterceptor {
|
|||
}, (err: any) => {
|
||||
if (err instanceof HttpErrorResponse) {
|
||||
if (err.status === 401) {
|
||||
EDW VALE TO KWDIKA GIA TO LOGOUT KAI SXOLIASE TON OPOU ALLOU TON EXEIS
|
||||
var auth2 = gapi.auth2.getAuthInstance();
|
||||
auth2.signOut().then(function () {
|
||||
console.log('User signed out.');
|
||||
localStorage.removeItem('currentUser');
|
||||
});
|
||||
this.tokenService.setToken(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue