How to work with cookies in the Ionic 2?

I’m trying to make an app that uses the authorization based on cookies. But I have a problem. I can not get cookies from server in the application. I see them in the Chrome Dev Tools.

But there are no in the Response object in my app.

How can I get a cookie from the server?

Thank you in advance!

1 Like

Hi, I’m having the same issue, were you able to solve this ?

that cookie you see on the server has nothing to do with what you need in your app to authenticate. You need to provide more detail on where you are trying to authenticate yourself and what the server sends back to your client so you can store it and use it when you make some requests to that server.

I have same issue. Is there any relation:

I tried but can not success.

Hi guys, did you solve it? I am having the same issue. Please see

I had ng2-cookies working. No changes needed.
There were some updates to the package in the meanwhile.

Just do like this:

npm install ng2-cookies

import { Cookie } from 'ng2-cookies/ng2-cookies';
    Cookie.set('cookieName', 'cookieValue');
    let myCookie = Cookie.get('cookieName');

Hi guys, I am also facing this issue.

  1. Is it really possible to work with cookie-based authentication/session on Ionic 2?
    As I observed cookie-based is best suited to Web-based applications. Please give your thoughts on this.
  2. If so, is this advisable?
  3. Or are we going to stick to Token-based authentication/session?

Please advice guys. I am a bit new to Ionic framework.

Thanks a lot.

I am facing the same issue as well. I’ve been able to resolve this temporarily using the Ionic native HTTP plugin. This gives you control over cookies, like set, remove, and clear.

I am still looking for a solution that works with Angular. Any advice is much appreciated.

I have the same problem. It takes me ages to find out how to send a simple request from a device. In browser cookie is sent along, in device or simulator nothing is sent and it is not possible to find the Set-Cookie in the http res.headers[’_headers’] array.

Can somebody from Ionic answer the question? We are trying to adapt your technology, come on!

if you are doing CORS
cookies are stored on your back-end domain and can’t be access on front-end
you need to get cookies in back-end and send through the response