I'm implementing a login system using based on two requests. The first request yields the userId, and the userId is passed to the second request to find the userRole, which provides authentication status and redirection to relevant dashboard.
From the API side, both requests take header options and body parameters. Additionally the second request takes the token provided by the first request. I'm able to pass header options to the first call and it's successful:
this.http.post<any>(`${environment.baseUrlUserSecurity}/users/login`, data, Option)
but the second call:
this.http.get(`${environment.baseUrlUserSecurity}/prsnls`, userId, RoleOptions)
doesn't accept the header option RoleOptions
. This is the code:
login(data){
const Option ={ headers: new HttpHeaders({'Access-Control-Allow-Origin': '*', 'Content-Type': 'application/json',"USER_CODE":data.USER_CODE})};
//see that you "return" an observable
return this.http.post<any>(`${environment.baseUrlUserSecurity}/users/login`, data, Option)
.pipe(
switchMap(value=>{
const userId = value[0].result.userId
const currentToken = value[0].result.token
const RoleOptions = { headers: new HttpHeaders({
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
'Authorization : 'Bearer' + currentToken,
'USER_CODE':data.USER_CODE
)};
}
return this.http.get(`${environment.baseUrlUserSecurity}/prsnls`, userId,
RoleOptions)
}).pipe(map(user =>(
{ ...user}
)))
But VS Code complains about the RoleOptions
which is the third argument passed to the get request within the switchMap
saying that only "1 or 2 arguments are needed, but received 3". Why can't I pass header options to the GET request added to the body parameter passed to it?