$cookieStore expires not being set

3.2k views Asked by At

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?

1

There are 1 answers

0
aUXcoder On

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
}