I have a unique service that connects to 2 different API endpoints. The first endpoint retrieves the user's id along with a JWT token:
@Injectable()
export class UserService {
appLogin = 'http://url.for.the.login.api';
//returns id and token
userData = 'http://url.for.the.user_info.api';
//returns user info
constructor(private http: HttpClient) { }
getAll() {
return this.http.get<User[]>(`${this.appLogin}`);
//retrieves id and token, can be displayed in the template like this {{currentUser.id}}
}
}
Next, I require another method that utilizes the id and token retrieved from the first request to make a subsequent GET
request. The URL for this request should look something like this:
http://url.for.the.user_info.api/userID?token=token_string
Here is the current implementation for this scenario:
getInfo(id: number, token: string) {
let userData = this.http.get<User[]>(`${this.appLogin}` + id + '?token=' + token);
return this.http.get<User[]>(`${userData}`);
}
However, I am encountering challenges with this setup. Any assistance provided would be greatly appreciated.