Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { APP_INITIALIZER, NgModule } from '@angular/core';
- import { BrowserModule } from '@angular/platform-browser';
- import { FormsModule } from '@angular/forms';
- import { AppComponent } from './app.component';
- import { HelloComponent } from './hello.component';
- export function authGaurd(): () => Promise<any> {
- return (): Promise<any> => {
- return new Promise((resolve, reject) => {
- if(localStorage.getItem('app-token')) {
- resolve();
- } else {
- window.location.href = 'www.my-external-sso-login-page.com';// this sso page will set the local storge 'app-token'
- }
- });
- };
- }
- @NgModule({
- imports: [ BrowserModule, FormsModule ],
- declarations: [ AppComponent, HelloComponent ],
- providers: [{
- provide: APP_INITIALIZER,
- useFactory: authGaurd,
- multi: true
- }],
- bootstrap: [ AppComponent ]
- })
- export class AppModule { }
Add Comment
Please, Sign In to add comment