In my angular 2 we do not have a login page. I want to authenticate user during page load by passing some values to rest api. The app calls main.ts which has angular 2 bootstrap function which finally loads AppComponent. The appcomponent has router outlet which loads other routes for the page. I do not want to load my router outlet and dashboard route until appcomponent authenticates the user. How can i protect the whole appcomponent? I know how to protect indivual routes by configuring canactivate but in this situtation I want to protect appcomponent which is the terminal itself.
Asked
Active
Viewed 358 times
0
-
You can use `APP_INITIALIZER` http://stackoverflow.com/questions/37611549/how-to-pass-parameters-rendered-from-backend-to-angular2-bootstrap-method/37611614#37611614 – Günter Zöchbauer Jul 08 '16 at 04:45
-
export function RunApplication(userid:string) { bootstrap(AppComponent, [ APP_ROUTER_PROVIDERS, HTTP_PROVIDERS, provide("isLoggedIn", { useFactory: (auth:AuthService) => () => auth.login(userid), deps:[HTTP_PROVIDERS], multi: true }), ]).catch((err) => console.error(err)); } - How do I ensure AuthService is resolved before App Component ngOninit. – Robin Kedia Jul 12 '16 at 01:05