Yas
October 14, 2021, 3:56pm
1
that’s a very simle issue.
currently, my app (SPA, Angular 12) has only 3pages. root, logincallback and error.
redirectUri: http://localhost:4200/logincallback
errorPath: /error
in this case, if a blocked user try to log in my app, Auth0 will callback with error like below
http://localhost:4200/logincallback?error=unauthorized&error_description=user%20is%20blocked&state=xxxxxx
but auth0 library redirects to /error
without query parameter automatically and quickly (by errorPath
configuration), so I can not get error reason like “unauthorized, user is blocked” and so on.
please tell me how to get error at the automatic redirect destination.
plartform: Angular 12
SDK: auth0/auth0-angular 1.17.0
Yas
October 21, 2021, 4:25pm
2
I figured out the solution from the official sample as below by myself.
import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { AuthService } from '@auth0/auth0-angular';
import { Observable, timer } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
@Component({
selector: 'app-error',
templateUrl: './error.component.html',
})
export class ErrorComponent {
public error$: Observable<any> = this.auth.error$;
constructor(private auth: AuthService, private router: Router) {}
ngOnInit() {
timer(0).pipe(takeUntil(this.error$)).subscribe(() => {
this.router.navigateByUrl('/');
});
This file has been truncated. show original
// get error object from library, at the component that is set in errorPath option.
public error$: Observable<any> = this.auth.error$;
and we need to add more small code to html.
we can see useful code at above link.
thank you so much!
1 Like
Thanks for sharing that with the rest of community @Yas !