Skip to content

Commit

Permalink
Added Observable User
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatanvicente committed Jan 29, 2024
1 parent 1134904 commit 8c4c3ca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/app/interceptors/jwt-interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class JwtInterceptor implements HttpInterceptor {

console.log("~~~~~~~~~~~"+JSON.stringify(currentUser));

this.authService.user.subscribe((user) => {
this.authService.user$.subscribe((user) => {
console.log("#########"+JSON.stringify(user));
});

Expand Down
9 changes: 6 additions & 3 deletions src/app/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export class AuthService {

private readonly anonym: string = "anonym";
private userSubject: BehaviorSubject<User>;
public user: Observable<User>;
public user$: Observable<User>;

constructor(private http: HttpClient, private router: Router) {
this.userSubject = new BehaviorSubject(JSON.parse(localStorage.getItem("user")!));
this.user = this.userSubject.asObservable();
this.user$ = this.userSubject.asObservable();
}

/**
Expand All @@ -40,9 +40,12 @@ export class AuthService {
/**
* Register a user and log in with the new user. Set new user as current user.
*/
public register(dni: string, email:string, password: string, confirmPassword:string){
public register(dni: string, email:string, password: string, confirmPassword:string): User{



return this.currentUser;

}

/**
Expand Down

0 comments on commit 8c4c3ca

Please sign in to comment.