Uses error interceptor to handle redirecting to login

This commit is contained in:
Aaron Louie 2020-05-23 13:37:17 -04:00
parent 13b47ba894
commit 4a71a552d6
5 changed files with 11 additions and 16 deletions

6
package-lock.json generated
View File

@ -12291,9 +12291,9 @@
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
},
"sartography-workflow-lib": {
"version": "0.0.177",
"resolved": "https://registry.npmjs.org/sartography-workflow-lib/-/sartography-workflow-lib-0.0.177.tgz",
"integrity": "sha512-lR+3MljVyWj6hPJ/a3bxKhBaZ0CoK5WxNVq6Xb3Qo6CiCbuzG/CJiE3jcS1fsgPDNyLHzCKlwpNH6z95pfPI2w=="
"version": "0.0.180",
"resolved": "https://registry.npmjs.org/sartography-workflow-lib/-/sartography-workflow-lib-0.0.180.tgz",
"integrity": "sha512-d/ePxdkeIX/ZW3Sp5NIkZsitxRxS560PWorOd9RaojyJtMks2EgCwuN0Gs18NkT0Qrvk7fJHKYYV89k0/H0djQ=="
},
"sass": {
"version": "1.23.3",

View File

@ -53,7 +53,7 @@
"ngx-file-drop": "^8.0.8",
"ngx-markdown": "^9.0.0",
"rxjs": "~6.5.4",
"sartography-workflow-lib": "^0.0.177",
"sartography-workflow-lib": "^0.0.180",
"tslib": "^1.11.1",
"uuid": "^7.0.2",
"zone.js": "^0.10.3"

View File

@ -23,6 +23,7 @@ import {FormlyModule} from '@ngx-formly/core';
import {
AppEnvironment,
AuthInterceptor,
ErrorInterceptor,
SartographyFormsModule,
SartographyPipesModule,
SartographyWorkflowLibModule
@ -46,12 +47,12 @@ import {FooterComponent} from './footer/footer.component';
import {HomeComponent} from './home/home.component';
import {ModelerComponent} from './modeler/modeler.component';
import {NavbarComponent} from './navbar/navbar.component';
import {ProtocolBuilderComponent} from './protocol-builder/protocol-builder.component';
import {ReferenceFilesComponent} from './reference-files/reference-files.component';
import {SignInComponent} from './sign-in/sign-in.component';
import {SignOutComponent} from './sign-out/sign-out.component';
import {WorkflowSpecCardComponent} from './workflow-spec-card/workflow-spec-card.component';
import {WorkflowSpecListComponent} from './workflow-spec-list/workflow-spec-list.component';
import { ProtocolBuilderComponent } from './protocol-builder/protocol-builder.component';
import { ReferenceFilesComponent } from './reference-files/reference-files.component';
@Injectable()
export class ThisEnvironment implements AppEnvironment {
@ -131,6 +132,7 @@ export class ThisEnvironment implements AppEnvironment {
{provide: 'APP_ENVIRONMENT', useClass: ThisEnvironment},
{provide: APP_BASE_HREF, useValue: environment.baseHref},
{provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true},
{provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true},
]
})
export class AppModule {

View File

@ -39,14 +39,6 @@ export class NavbarComponent {
this._loadNavLinks();
}, error => {
localStorage.removeItem('token');
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,9 @@ export class SignInComponent implements OnInit {
// For testing purposes, create a user to simulate login.
if (!this.environment.production) {
localStorage.setItem('prev_url', location.href);
this.api.redirectToLogin(location.origin + '/session', this.model);
localStorage.setItem('prev_url', location.origin);
this.model.redirect_url = location.origin + '/session';
this.api.redirectToLogin(this.model.redirect_url, this.model);
} else {
this.error = new Error('This feature does not work in production.');
}