How to bypass AuthGuard to access Component through shared url

1,149 views
Skip to first unread message

sonal sonavane

unread,
May 11, 2019, 2:01:00 AM5/11/19
to Angular and AngularJS discussion
Hi All,

I am new to angular and trying to figure out how to access components that have AuthGuard activated without the need to login into my application. 

My application needs to be logged in to access any of the forms in it. but I also need to access one form through shared URL. for this, I need to bypass logging into the application and just access this form using URL?  How can access this form component through URL while bypassing the login? I also want to make sure the security of the application would not be compromised. And same for the form that needs to be accessed without a login.

I am using Angular 7.

Thanks,
Sonal

Sander Elias

unread,
May 14, 2019, 8:23:44 AM5/14/19
to Angular and AngularJS discussion
Hi Sonal,

You can inspect your request in your guard, and make a 'whitelist' of urls that can skip the test.
I'm doing something similar like that, but in an interceptor, to make sure the tokens only gets send back to the places they belong.

Regards
Sander

sonal

unread,
May 22, 2019, 11:04:13 PM5/22/19
to Angular and AngularJS discussion
Thank you Sander. I will try this.

sunil patel

unread,
May 22, 2019, 11:15:40 PM5/22/19
to ang...@googlegroups.com
Hii sonal,
You need to create one AuthComponent.service.ts 
And creat one class in it like export calsss AuthGuard {
Function_name() {
  If (your condition) {
    return true;
  } else { return false;}
}
 }

In routing file import this file and use it like

{path: 'home', component:HomeComponent, [AuthGuard] }

I hope it is work for you.

--
You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
To view this discussion on the web visit https://groups.google.com/d/msgid/angular/625eaad1-6ea0-40d1-8a1c-0baf74e8164e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages