How can I ensure that users only have access to their own information rather than the entire database?
I attempted to use an if-else statement to filter out the data I need, as shown in the example below, but it was unsuccessful.
custom-history.component.html
<div class="container">
<div class="row" *ngFor="let histories of history">
<div class="card card-block">
<h4 class="card-title">{{ histories.email }}</h4>
<p class="card-text">{{histories.amount}}</p>
</div>
</div>
</div>
custom-history.component.ts
import { Component, OnInit } from '@angular/core';
import { PostsService } from '../posts.service';
import { AuthService } from '../auth.service';
@Component({
selector: 'app-custom-history',
templateUrl: './custom-history.component.html',
styleUrls: ['./custom-history.component.css']
})
export class CustomHistoryComponent implements OnInit {
history: any;
histories: any;
public userEmail: string;
constructor(private postsService: PostsService, private auth: AuthService) { }
ngOnInit() {
this.auth.currentEmail.subscribe(email => this.userEmail = email);
this.postsService.getAllHistory().subscribe(history => {
if(history.email == this.userEmail){
this.history = history;
}
});
}
}