TypeError: You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable

前端 未结 20 1170
时光说笑
时光说笑 2020-12-01 06:22

I am trying to map from a service call but getting an error. Looked at subscribe is not defined in angular 2? and it said that in order to subscribe we need to

20条回答
  •  南笙
    南笙 (楼主)
    2020-12-01 06:51

    I have been facing this issue when trying to authenticate a user using JSON Web Token. in my case it's related to authentication interceptor.

    Sending a request to authenticate a user doesn't have to provide a token since it doesn't exist yet.

    Check that your interceptor include this:

    if (req.headers.get('No-Auth') == "True")
                return next.handle(req.clone());
    

    And that you provide {'No-Auth':'True'} to your header's request like this:

      authenticateUser(user): Observable {
        const headers = new HttpHeaders({'No-Auth':'True'});
        headers.append('Content-Type', 'application/json');
        return this.httpClient.post(`${this.apiEndpoint}/auth/authenticate`, user, {headers: headers});
      }
    

提交回复
热议问题