To organize tasks for each user, you can create a structured collection by adding a node with the logged-in user's name or key, and then include a task collection within each node.
For instance:
{
"User1" : {
tasks : [
{
taskName : "demotask"
},
{
taskName : "demotask"
}
]
},
"User2" : {
tasks : [
{
taskName : "demotask"
},
{
taskName : "demotask"
}
]
}
}
Firebase stores the details of the logged-in user in browser storage, so it is necessary to check if the user is logged in or not. By using *ngIf
, you can show or hide menu items accordingly.
For example:
// Create a common helper Service
checkLoginUser() {
let user = null;
// Code to verify if the user is logged in or not.
// If there is a user in local storage, save it in the "user" variable.
return user ? true : false;
}
// Inject the service into the component and store the user status in a component variable
isUserLoggedIn = this.checkLoginUser();
// Handle showing/hiding using *ngIf in the template
<ul>
<li *ngIf="isUserLoggedIn">Tasks</li>
<li *ngIf="isUserLoggedIn">Add Task</li>
<li *ngIf="isUserLoggedIn">Logout</li>
</ul>