3
votes

I've read a few forums and can't seem to find this issue.

I have an auth service that should respond with a token.

This is my auth Service call.

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { map } from 'rxjs/operators';

@Injectable()
export class AuthService {
    baseUrl: 'https://api.website.com/login/';

    constructor(private http: HttpClient) { }

    login(model: any) {
        return this.http.post(this.baseUrl, model)
            .pipe(
                map(data => data)
            );
    }
}

in my login component, I have the following call:

login() {
    this.auth.login(this.model)
      .subscribe(
        (data: any) => {
          console.log(data);
        },
        (error: any) => {
          console.log(error);
        }
      );
  }

I'm receiving the following error in the console -

TypeError: Cannot read property 'toLowerCase' of undefined at HttpXsrfInterceptor.push../node_modules/@angular/common/fesm5/http.js.HttpXsrfInterceptor.intercept (http.js:1719) at HttpInterceptorHandler.push../node_modules/@angular/common/fesm5/http.js.HttpInterceptorHandler.handle (http.js:1135) at HttpInterceptingHandler.push../node_modules/@angular/common/fesm5/http.js.HttpInterceptingHandler.handle (http.js:1770) at MergeMapSubscriber.project (http.js:975) at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber._tryNext (mergeMap.js:61) at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber._next (mergeMap.js:51) at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54) at Observable._subscribe (scalar.js:5) at Observable.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable._trySubscribe (Observable.js:43) at Observable.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable.subscribe (Observable.js:29)

I don't have any interceptors, and am not sure where this is all coming from. Any help?

1
I think this is likely to do with the endpoint returning nothing, error is then probably caused by trying to pipe() and map() undefined. Can you get a response from the api in postman?Dince12
I don't think so because the network never even makes a call to that url. It's empty.J.G.Sable
change baseUrl: 'https://api.website.com/login/'; to baseUrl = 'https://api.website.com/login/';frido
duh. thanks! Stupid mistake.J.G.Sable

1 Answers

2
votes

Change

 baseUrl: 'https://api.website.com/login/';

to

 baseUrl= 'https://api.website.com/login/';