Redirects to login on production if no user found.

This commit is contained in:
Aaron Louie 2020-05-23 12:15:28 -04:00
parent 198cfd90bb
commit 13b47ba894
2 changed files with 13 additions and 6 deletions

View File

@ -1,6 +1,6 @@
import {Component, OnInit} from '@angular/core';
import {Component, Inject, OnInit} from '@angular/core';
import {Router} from '@angular/router';
import {ApiService, isSignedIn, User} from 'sartography-workflow-lib';
import {ApiService, AppEnvironment, isSignedIn, User, UserParams} from 'sartography-workflow-lib';
interface NavItem {
path?: string;
@ -19,11 +19,11 @@ interface NavItem {
export class NavbarComponent {
navLinks: NavItem[];
user: User;
isSignedIn = isSignedIn;
constructor(
private router: Router,
private api: ApiService,
@Inject('APP_ENVIRONMENT') private environment: AppEnvironment,
) {
this._loadUser();
}
@ -39,7 +39,14 @@ export class NavbarComponent {
this._loadNavLinks();
}, error => {
localStorage.removeItem('token');
this.api.openUrl('/');
if (this.environment.production) {
localStorage.setItem('prev_url', location.href);
const emptyUserParams: UserParams = { uid: null };
this.api.redirectToLogin(location.origin + '/session', emptyUserParams);
} else {
this.api.openUrl('/');
}
});
}
}

View File

@ -71,8 +71,8 @@ export class SignInComponent implements OnInit {
// For testing purposes, create a user to simulate login.
if (!this.environment.production) {
this.model.redirect_url = location.origin + '/session';
this.api.redirectToLogin(location.href, this.model);
localStorage.setItem('prev_url', location.href);
this.api.redirectToLogin(location.origin + '/session', this.model);
} else {
this.error = new Error('This feature does not work in production.');
}