Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/app/http-interceptors/permission-interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,10 @@ export class PermissionInterceptor implements HttpInterceptor {
const currentUrl = req.url;
const isOnPermittedUrl = pageUrl === '/login' || currentUrl === '/login' || currentUrl.indexOf('/apis/v1beta1/auth') > -1;

const errorStatus = error.status === 401 || error.status === 403;
// Display a login alert on a permissions related (401/403) error.
// Display a login alerts on a permissions related (401/403) error.
// If we're already displaying such an alert, don't display it again.
if(errorStatus && !this.snackbarRef && !isOnPermittedUrl) {
let message = 'Not logged in';
if(error.status === 403) {
message = 'Unauthorized'
}

if(error.status === 401 && !this.snackbarRef && !isOnPermittedUrl) {
let message = 'You are not logged in';
this.snackbarRef = this.snackbar.open(message, 'Login');
this.snackbarRef.afterDismissed()
.subscribe(res => {
Expand All @@ -47,6 +42,14 @@ export class PermissionInterceptor implements HttpInterceptor {
}
})
}
if(error.status === 403 && !this.snackbarRef && !isOnPermittedUrl) {
let message = 'Unauthorized';
this.snackbarRef = this.snackbar.open(message, 'Close');
this.snackbarRef.afterDismissed()
.subscribe(() => {
this.snackbarRef = null;
})
}

return throwError(error);
})
Expand Down