Search code examples
angularjsangular-cookies

cookies does not work correctly in angularjs


I read a lot of articles but still can't make cookies work. I have a controller for login page, and this controller basicaly calls service that make a login. In service callback vunstion I set cookies:

$cookieStore.uid   = response.ui;
$cookieStore.email = response.email;
$cookieStore.auth  = response.cookie;

$location.path('/');

After that I make a redirect on my index view. In controller for index view, I try to check cookies in the cookie chacker service.

    var email = $cookieStore.email;
    var auth  = $cookieStore.auth;


    if (typeof email !== 'undefined' && typeof auth !== 'undefined') {
        success("");
    }

And this works only for the moment when I was redirected to the page from login. When I moved to different view or reload page my cookies lost.


Solution

  • Adding records to the cookiestore is like so.

    $cookieStore.put("KEY", value);
    

    And to retrieve:

    $cookieStore.get("KEY");