Issue: The parameter type 'string | null' is not compatible with the expected type 'string'. The value 'null' is not a valid string.ts(2345)
Error on Line: this.setSession(res.body._id, res.headers.get('x-access-token'), res.headers.get('x-refresh-token'));
constructor(private httpClient: HttpClient, private webService: WebRequestService, private router: Router) { }
login(email: string, password: string) {
return this.webService.login(email, password).pipe(
shareReplay(),
tap((res: HttpResponse<any>) => {
// authentication tokens are present in the response headers
this.setSession(res.body._id, res.headers.get('x-access-token'), res.headers.get('x-refresh-token'));
console.log('Successfully logged in');
console.log(res);
})
)
}
logout() {
this.removeSession();
}
private setSession(userId: string, accessToken: string, refreshToken: string) {
localStorage.setItem('user-id', userId);
localStorage.setItem('access-token', accessToken);
localStorage.setItem('refresh-token', refreshToken);
}
private removeSession() {
localStorage.removeItem('user-id');
localStorage.removeItem('access-token');
localStorage.removeItem('refresh-token');
}