jeroenheijmans/sample-angular-oauth2-oidc-with-auth-guards

Login when user opens the page

mrkannan3 opened this issue · 3 comments

Hi,

I am trying to change this code to login automatically when user browse the home page. I updated the app menu component file to call the login method in the constructor but its keep looping. Could you please help me to figure out the issue? Thanks

Enabling the commented out feature should do the trick.

Alternatively, you can slap the forced login guard on all routes in your app, including the home page. This has an advantage, that you could leave one or two pages (FAQ, 404, etc) unprotected if you want.

Hope those pointers help! If you need lots more help thinking through your app design, another forum, or a colleague/friend, might be more readily available. Good luck!

Thanks for the pointer. I actually implemented by doing this.

https://github.com/manfredsteyer/angular-oauth2-oidc/blob/master/projects/sample/src/app/home/home.component.ts#L28

this.oauthService.loadDiscoveryDocumentAndTryLogin().then(_ => {
if (!this.oauthService.hasValidIdToken() || !this.oauthService.hasValidAccessToken()) {
this.oauthService.initImplicitFlow('some-state');
}
});

I will check out your pointer as well.