I am configuring a login in Angular 17 in which I am using userStorageService but when I want to store the user there it generates this error
Argument of type ‘Object’ is not assignable to parameter of type ‘string’
this is my code
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable, map } from 'rxjs';
import { UserStorageService } from '../storage/user-storage.service';
const BASIC_URL = "http://localhost:8080/"
@Injectable({
providedIn: 'root'
})
export class AuthService {
constructor(private http: HttpClient,
private userStorageService: UserStorageService
) { }
register(signupRequest:any): Observable<any>{
return this.http.post(BASIC_URL+"sign-up", signupRequest);
}
login(username: string, password:string):any{
const headers = new HttpHeaders().set('Content-Type', 'application/json');
const body = {username, password};
return this.http.post(BASIC_URL + 'authenticate', body, {headers, observe: 'response'}).pipe(
map((res)=>{
const token = res.headers.get('authorization').substring(7);
const user = res.body;
if(token && user){
this.userStorageService.saveToken(token);
this.userStorageService.saveUser(user);
return true;
}
return false;
})
);
}
}
I have already checked the imports and everything but I don’t know what is wrong
New contributor
CesarH1408 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.