Guest User

Untitled

a guest
Dec 12th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. import { APP_INITIALIZER, NgModule } from '@angular/core';
  2. import { BrowserModule } from '@angular/platform-browser';
  3. import { FormsModule } from '@angular/forms';
  4.  
  5. import { AppComponent } from './app.component';
  6. import { HelloComponent } from './hello.component';
  7.  
  8. export function authGaurd(): () => Promise<any> {
  9. return (): Promise<any> => {
  10. return new Promise((resolve, reject) => {
  11. if(localStorage.getItem('app-token')) {
  12. resolve();
  13. } else {
  14. window.location.href = 'www.my-external-sso-login-page.com';// this sso page will set the local storge 'app-token'
  15. }
  16. });
  17. };
  18. }
  19.  
  20. @NgModule({
  21. imports: [ BrowserModule, FormsModule ],
  22. declarations: [ AppComponent, HelloComponent ],
  23. providers: [{
  24. provide: APP_INITIALIZER,
  25. useFactory: authGaurd,
  26. multi: true
  27. }],
  28. bootstrap: [ AppComponent ]
  29. })
  30. export class AppModule { }
Add Comment
Please, Sign In to add comment