Skip to content

Commit 280b9bf

Browse files
authored
Merge pull request #402 from intersective/hotfix/av2-328/force-the-user-logout-when-the-apikey-is-invalid
[AV2-328]force the user logout when the apikey is invalid
2 parents fd2c0d4 + 363612a commit 280b9bf

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

src/app/auth/auth-logout/auth-logout.component.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component } from '@angular/core';
22
import { AuthService } from '../auth.service';
33
import { Router } from '@angular/router';
4+
import { RouterEnter } from '@services/router-enter.service';
45

56
@Component({
67
selector: 'app-auth-logout',
78
template: '',
89
})
9-
export class AuthLogoutComponent implements OnInit {
10-
10+
export class AuthLogoutComponent extends RouterEnter {
11+
routeUrl = '/logout';
1112
constructor(
12-
private router: Router,
13+
public router: Router,
1314
private authService: AuthService
14-
) {}
15+
) {
16+
super(router);
17+
}
1518

16-
ngOnInit() {
19+
onEnter() {
1720
this.authService.logout();
1821
}
1922

src/app/shared/request/request.service.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export class QueryEncoder implements HttpParameterCodec {
3535
export class RequestService {
3636
private appkey: string;
3737
private prefixUrl: string;
38+
private loggedOut: boolean;
3839

3940
constructor(
4041
private http: HttpClient,
@@ -186,7 +187,15 @@ export class RequestService {
186187
console.error(error); // log to console instead
187188
}
188189
// log the user out if jwt expired
189-
if (this.utils.has(error, 'error.message') && error.error.message === 'Expired apikey') {
190+
if (this.utils.has(error, 'error.message') && ['Expired apikey', 'Invalid apikey'].includes(error.error.message) && !this.loggedOut) {
191+
// in case lots of api returns the same apikey invalid at the same time
192+
this.loggedOut = true;
193+
setTimeout(
194+
() => {
195+
this.loggedOut = false;
196+
},
197+
2000
198+
);
190199
this.router.navigate(['logout']);
191200
}
192201
// Return the error response data

0 commit comments

Comments
 (0)