Setting domain with ngCookies

I am using an app to login to a Drupal website. We are using Ionic v1. Angular version is 1.5.3 and angular-cookies version is 1.4.0.

After logging in, I need to save the session name and ID to a cookie for further authentication. So i am using ngCookies to save this session data to a cookie. My undertstanding is that I need to save the cookie with domain set to the domain of the Drupal website, which is local.mydomain.com. So I use this code a per the instructions on the ngCookie page (https://docs.angularjs.org/api/ngCookies/service/$cookies):

    $cookies.put(key, value, {
        'domain':'local.mydomain.com'
      });

This doesn’t work, so I have tried using $cookiesProvider to set the default domain:

.config(['$cookiesProvider', function($cookiesProvider) {
    // Set $cookies defaults
    $cookiesProvider.defaults.domain = 'local.mydomain.com';
    $cookiesProvider.defaults.path = '/';
}])

But this doesn’t work either. The domain is always saved as ‘localhost’.

Any help much appreciated.

Ionic info as follows:

Cordova CLI: 6.5.0
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
ios-deploy version: 1.9.1
ios-sim version: 5.0.13
OS: macOS Sierra
Node Version: v7.4.0
Xcode version: Xcode 8.3.3 Build version 8E3004b

You can try ng-biscuit.
See the demo where the domain has been set
http://stepan.js.org/ng-biscuit/demo/

thanks thesourav, i’ll give that a go.

Hi @thesourav - i have been trying this for a couple of days now. I’ve tried ngCookies and ngBiscuit with the same results. My app is running on localhost:8100 and the Drupal site is local.mydomain.com

The browser will not let me set a cookie for a different domain, and I am surprised that it would to be honest, even though these libraries claim to be able to do it. Do you have any suggestions - it’s possible I misunderstood your advice of course (which I am very grateful for). Thanks, Kevin

I have never tried on domains. How about plain old javascript?