7

I am setting expiration date of a the cookie in the following manner:

var dt = new Date();
dt.setMinutes(dt.getMinutes() + 30);                           

$cookieStore.put("loggedin", true, { expires: dt })

The cookie is being created but the expiration of it shows as "When the browsing session ends". Wth?

americanslon
  • 4,048
  • 4
  • 32
  • 57
  • As far as I know $cookieStore has no option to set expiry. It just accepts 2 parameters. https://code.angularjs.org/1.3.16/docs/api/ngCookies/service/$cookieStore for more details. – Abhishek Jain Jun 10 '15 at 18:55
  • You are right. Google brought me here https://code.angularjs.org/1.4.0/docs/api/ngCookies/service/$cookies and I got all mixed up with versions angular versions and $cookies vs $cookieStore – americanslon Jun 10 '15 at 19:05
  • Ahh ok... Honest mistake!! :-) – Abhishek Jain Jun 10 '15 at 19:07

1 Answers1

0

Set cookies attributes at config level to all cookies (using moment.js to set expiration date).

angular.module('myApp').config(cookies);

function cookies($cookiesProvider, moment) {
    // site domain like: domine.com 
    $cookiesProvider.defaults.domain = 'yourdomine.com';
    // set expiration to next week (+ 1 week)
    $cookiesProvider.defaults.expires = moment().add(1, 'week').calendar();
    // see HTTP cookies to view attributes
}
aUXcoder
  • 1,048
  • 1
  • 20
  • 32