fix: token bug

This commit is contained in:
Lala, Shahd
2026-05-14 22:13:24 +00:00
parent e436dc871c
commit 2e84ec97c2
2 changed files with 6 additions and 13 deletions
+4 -11
View File
@@ -1,7 +1,7 @@
import { Injectable, inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { BehaviorSubject, Observable } from 'rxjs';
import { map, tap } from 'rxjs/operators';
import { map, switchMap, tap } from 'rxjs/operators';
import { environment } from '../../environments/environment';
import { LoginRequest, RegisterRequest, RegisterResponse, LoginResponse, CurrentUser } from '../models/auth.models';
@@ -42,16 +42,9 @@ export class AuthService {
email
})
.pipe(
tap((response) => {
localStorage.setItem('username', response.username);
localStorage.setItem('userId', response.id);
this.currentUserSubject.next({
id: response.id,
username: response.username,
rating: response.rating,
createdAt: response.createdAt
});
})
switchMap((response) =>
this.login(username, password).pipe(map(() => response))
)
);
}