I am having an issue with Auth0’s AuthService
when being redirected to my login callback URL. After successfully logging in, I route the users to my login callback URL (http://localhost:4200/authorized) so I can do some logic, like grabbing data from my DB. However, in my AuthorizedComponent
, if I import Auth0’s AuthService
and pass it in my constructor, my application will immediately route away from my login callback URL and take the user to the root of my application. Let me show you some code:
import {Component, OnInit} from '@angular/core';
import {AuthService} from '@auth0/auth0-angular';
@Component({
selector: 'app-authorized',
templateUrl: './authorized.component.html',
styleUrls: ['./authorized.component.sass']
})
export class AuthorizedComponent implements OnInit {
constructor(private auth0Service: AuthService) {
}
ngOnInit(): void {
}
}
Just by passing in private auth0Service: AuthService
into my constructor, my app will redirect away from here and go to http://localhost:4200. I have no idea why it is doing this.
Here is where I am invoking Auth0’s login flow:
import {Component, OnInit} from '@angular/core';
import {Router} from '@angular/router';
import {AuthService} from '@auth0/auth0-angular';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.sass']
})
export class LoginComponent implements OnInit {
constructor(private router: Router, private auth0Service: AuthService) {
}
ngOnInit(): void {
}
login(): void {
this.auth0Service.loginWithRedirect({
redirect_uri: 'http://localhost:4200/authorized'
});
}
}
I don’t think I’m doing anything crazy with the redirect.
I have looked around for an answer, but what I’ve found doesn’t really work for me.
Any help would be appreciated.