Whitelist and catch error using google

I’m trying to use the auth0-angular library with Angular 10 to allow a specific set of google users to log in to my site.

I found a guide on creating a Whitelist rule, which works okay, but I have a couple questions:

  • Is there a way I can feed the list of valid emails into this rule from my app using config or anything? Right now, I just have a hard-coded list of strings in the rules, which adds an unwanted maintenance cost.

  • The example throws an UnauthorizedError() in the rule, which doesn’t result in displaying any error page in my app. It just redirects back to the callback with isLoggedIn as false. I tried using the Observable returned by loginWithRedirect() to catch the error, but this error is never thrown.

Thanks,
Mayhew

Hi @mayhew3,

Do the email addresses share a domain? If so you can use a domain-specific rule.

If not, you could store the email addresses in a .txt file in Dropbox and reference that in the rule. Here is an example: Dropbox WhiteList

You could use this approach with other cloud storage options or your own protected API as well.

You can capature login errors by subscribing to the error$ observable

authService.error$.subscribe((error) => console.log(error));

If you’re using the Angular Quick Start, you can edit the ngOnInit function in the src/app/components/nav-bar/nav-bar.component.ts file to log the error:

  ngOnInit() {
    this.auth.error$.subscribe((error) => console.log(error));
  }

Hope that helps!

Stephanie

1 Like

Thanks for your response!

The error$ observable works just like I needed, thanks!

I’m interested in API solution, but would still want to be able to send input from my app about my environment or configuration. Is that possible?

Yes, Rules have access to the Context object which contains the clientMetadata property as well as other information about your app. You can store key/value pairs of data in your application’s client metadata by opening up the advanced settings in the application settings in the dashboard.

Or you can use the Management API’s /api/v2/clients/{id} endpoint to add data to the client_metadata object.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.