Skip to content

Commit

Permalink
user cannot view account transactions unless logged in
Browse files Browse the repository at this point in the history
  • Loading branch information
NisanurBulut committed Dec 1, 2020
1 parent 03b918e commit 393ea59
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 6 additions & 4 deletions Camekan.Client/src/app/account/account.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { AsyncSubject, BehaviorSubject } from 'rxjs';
import { BehaviorSubject, of, ReplaySubject } from 'rxjs';
import { map } from 'rxjs/operators';
import { environment } from 'src/environments/environment';
import { IUser } from '../shared/models/user.model';
Expand All @@ -12,14 +12,16 @@ import { IUser } from '../shared/models/user.model';
export class AccountService {

baseUrl = environment.apiUrl;
private currenUserSource = new BehaviorSubject<IUser>(null);
private currenUserSource = new ReplaySubject<IUser>(1);
currentUser$ = this.currenUserSource.asObservable();

constructor(private http: HttpClient, private router: Router) { }

getCurrentUser() { return this.currenUserSource.value; }

loadCurrentUser(token: string) {
if (token === null) {
this.currenUserSource.next(null);
return of(null);
}
const httpOptions = {
headers: new HttpHeaders({
'Authorization': `Bearer ${token}`
Expand Down
10 changes: 4 additions & 6 deletions Camekan.Client/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ export class AppComponent implements OnInit {
}
loadUser() {
const token = localStorage.getItem('token');
if (token) {
this.accountService.loadCurrentUser(token)
.subscribe(() => {
console.log('mevcut kullanici getirildi');
}, error => console.log(error));
}
this.accountService.loadCurrentUser(token)
.subscribe(() => {
console.log('mevcut kullanici getirildi');
}, error => console.log(error));
}
loadBasket() {
const basketId = localStorage.getItem('basket_id');
Expand Down

0 comments on commit 393ea59

Please sign in to comment.