Commit 3dba74a9 authored by Lukas Burgey's avatar Lukas Burgey

Change auth error handling

parent 8f07efc4
......@@ -107,8 +107,13 @@ export interface User {
vos: VO[];
}
export interface Session {
deactivated?: boolean;
}
export interface State {
error?: string;
msg?: string;
session?: Session;
user: User;
}
......
......@@ -18,7 +18,11 @@ import {
@Injectable()
export class UserService {
private initialized = false;
private loggedIn: boolean = false;
private loggedIn = false;
// relogin on failed XHR calls
// is turned off when the user is deactivated
private autoReLogin = true;
private user: User;
private user$: BehaviorSubject<User>;
......@@ -150,6 +154,7 @@ export class UserService {
let update: Update = JSON.parse(message.body);
console.log('update:', update);
// TODO rename error to msg
if (update.error && update.error != '') {
this.snackBar.open(update.error);
}
......@@ -185,10 +190,15 @@ export class UserService {
private updateState(update: State): void {
if (update) {
// report an occured error
if (update.error) {
this.snackBar.open(update.error);
if (update.msg) {
this.snackBar.open(update.msg);
}
if (update.session && update.session.deactivated) {
this.autoReLogin = false;
}
console.log(update.session);
this.user = update.user;
this.user$.next(this.user);
......@@ -206,7 +216,7 @@ export class UserService {
private handleError(fetch: boolean, msg?: string) {
return (error: any) => {
if (error.status == 403) {
if (error.status === 403 && this.autoReLogin) {
this.login();
return
}
......@@ -223,7 +233,7 @@ export class UserService {
}
private logErrorAndFetch(error: any) {
if (error.status === 403) {
if (error.status === 403 && this.autoReLogin) {
this.login();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment