WIP: Refresh token implemented in BE, yet to be implemented in FE

This commit is contained in:
aditya.chandel
2025-03-08 13:25:21 -07:00
parent b48a79bd64
commit 7e49811efb
12 changed files with 117 additions and 54 deletions
@@ -7,17 +7,17 @@ import { RxStompService } from '../../shared/websocket/rx-stomp.service';
providedIn: 'root',
})
export class AuthService {
private apiUrl = 'http://localhost:7050/api/v1/auth/login';
private apiUrl = 'http://localhost:7050/api/v1/auth';
private rxStompService?: RxStompService;
private http = inject(HttpClient);
private injector = inject(Injector);
login(credentials: { username: string; password: string }): Observable<any> {
return this.http.post<{ token: string }>(this.apiUrl, credentials).pipe(
return this.http.post<{ accessToken: string; refreshToken: string }>(`${this.apiUrl}/login`, credentials).pipe(
tap((response) => {
if (response.token) {
this.saveToken(response.token);
if (response.accessToken && response.refreshToken) {
this.saveToken(response.accessToken);
this.getRxStompService().activate();
}
})
@@ -25,15 +25,15 @@ export class AuthService {
}
saveToken(token: string): void {
localStorage.setItem('token', token);
localStorage.setItem('accessToken', token);
}
getToken(): string | null {
return localStorage.getItem('token');
return localStorage.getItem('accessToken');
}
logout(): void {
localStorage.removeItem('token');
localStorage.removeItem('accessToken');
this.getRxStompService().deactivate();
}