I recently started learning Angular (4) and followed the tutorials of Angular.io.
But now that I'm trying to build my own application I'm running into a bit of a problem. I've spent the whole day trying to figuring this out but I failed.
I'm working on an auth service that has only a login and a logout for now.
The login
works fine, but I don't get the logout
to work. It seems to break on the toPromise()
call.
const url = `${environment.serviceURL}/api/account/logout`;
const headers = new Headers({'Content-Type': 'application/x-www-form-urlencoded',
'withCredentials':true,
'Authorization': `Bearer ${this.token}`});
let options = new RequestOptions({headers: headers});
let result = this.http.post(
url, options).toPromise().then(/*do something*/);
This gives me the following error in the console:
ERROR Error: Uncaught (in promise): TypeError: v.split is not a function
TypeError: v.split is not a function at http://localhost:4200/vendor.bundle.js:26382:76
at Array.forEach (native)
at http://localhost:4200/vendor.bundle.js:26382:20
at Map.forEach (native)
at Headers.toJSON (http://localhost:4200/vendor.bundle.js:26380:23)
at Object.stringify (<anonymous>)
at Request.Body.text (http://localhost:4200/vendor.bundle.js:26957:25)
at Request.getBody (http://localhost:4200/vendor.bundle.js:27865:29)
at Observable._subscribe (http://localhost:4200/vendor.bundle.js:27393:37)
at Observable._trySubscribe (http://localhost:4200/vendor.bundle.js:567:25)
at http://localhost:4200/vendor.bundle.js:26382:76
at Array.forEach (native)
at http://localhost:4200/vendor.bundle.js:26382:20
at Map.forEach (native)
at Headers.toJSON (http://localhost:4200/vendor.bundle.js:26380:23)
at Object.stringify (<anonymous>)
at Request.Body.text (http://localhost:4200/vendor.bundle.js:26957:25)
at Request.getBody (http://localhost:4200/vendor.bundle.js:27865:29)
at Observable._subscribe (http://localhost:4200/vendor.bundle.js:27393:37)
at Observable._trySubscribe (http://localhost:4200/vendor.bundle.js:567:25)
at resolvePromise (http://localhost:4200/polyfills.bundle.js:3224:31)
at http://localhost:4200/polyfills.bundle.js:3150:17
at SafeSubscriber._error (http://localhost:4200/vendor.bundle.js:66387:85)
at SafeSubscriber.__tryOrSetError (http://localhost:4200/vendor.bundle.js:16367:16)
at SafeSubscriber.error (http://localhost:4200/vendor.bundle.js:16321:26)
at Subscriber._error (http://localhost:4200/vendor.bundle.js:16248:26)
at Subscriber.error (http://localhost:4200/vendor.bundle.js:16222:18)
at Observable._trySubscribe (http://localhost:4200/vendor.bundle.js:572:18)
at Observable.subscribe (http://localhost:4200/vendor.bundle.js:555:27)
at http://localhost:4200/vendor.bundle.js:66387:15
The mayor difference is (at least I think) that the login
returns data containing the user info and the logout
doesn't return any data. It just removes the session in the service.
I just want to know if the request has succeeded so I can act upon it. What am I doing wrong or what should I do differently to get this working?