Hi there,
I followed the tutorial to set up authentication for angular 9. Now, I want to redirect to login page the user immediately if not logged, what I do is simply
export class AppComponent implements OnInit {
constructor(public auth: AuthService) {
}
ngOnInit(): void {
this.auth.getUser$().subscribe((c) => {
console.log(‘result user getuser’ + c)
if (c == undefined)
this.auth.login()
})
}
}
The problem is that the first user that is streamed is always undefined, afterwards, if the user is actually logged, the real user is returned, causing the reload of the component and breaking my system.
Moreover, I noticed that reloading a page where I am authenticated in incognito mode, it causes the service to forget the authentication.
Any solutions? Thank you