After successfully implementing Angular Firebase email and password registration and login, the next step is to check the user's state in the navigation template. If the user is logged in, I want to hide the login button and register button. I tried searching for tutorials on how to achieve this and came across using AuthService and AuthInfo as shown here:
The challenge I'm facing is that these tutorials involve a lot of promises and concepts that I'm not familiar with, which can be confusing. I'm looking for a simpler approach and guidance from someone who can assist me.
Below are snippets of my current code:
Navigation -
<ul class="nav navbar-nav">
<li><a routerLink="" routerLinkActive="active">Home</a></li>
<li><a routerLink="login" routerLinkActive="active" *ngIf="!authInfo?.isLoggedIn()">Login</a></li>
<li><a routerLink="register" routerLinkActive="active" *ngIf="!authInfo?.isLoggedIn()">Register</a></li>
<li><a routerLink="quiz" routerLinkActive="active">Quiz</a></li>
</ul>
Auth service file containing user creation and login logic for Firebase -
@Injectable({
providedIn: 'root'
})
export class AuthService {
private user: Observable<firebase.User>;
constructor(private _firebaseAuth: AngularFireAuth, private router: Router) {
// Logic for initializing user
...
}
// Methods for logging in and registering users
...
}
... (more content follows)