0

I'm making use of the angular-cookie library, found here. On this page it states the following:

To create a cookie use

ipCookie(key, value);

The value supports strings, numbers, booleans, arrays and objects and will be automatically serialized into the cookie.

I've created a few cookie without fail but when I attempt to create a rememberMe it fails to create - this cookies value is like this

var cookieContents = {};
cookieContents.tokenID = user.tokenId;

Were the user.tokenId is a string that is 4434 characters long. So my question is - does this fail to create just because the size of the token passed? If so would it be better to split the token into two, e.g. tokenIdPartOne and tokenIdPartTwo (bad names I know)

Thoughts?

Thanks

Community
  • 1
  • 1
Katana24
  • 8,706
  • 19
  • 76
  • 118

1 Answers1

1

Cookie size limit is 4kb, which mean that split it or not, you can't store it.

I think you should use local storage. suited module - angular-local-storage

The data is kept aslong you or the client user clean the data,

Usage is easily:

bower install angular-local-storage --save

 var storyService = angular.module('storyService', ['LocalStorageModule']);

In a controller (or any else):

storyService.controller('myCtrl', ['$scope', 'localStorageService', 
                                     function($scope, localStorageService) {
       localStorageService.set(key, val); //return boolean
       localStorageService.get(key); // returl val

}]);

Match this usage to your scenario (for example - store the key and maybe an expirtation timestamp near)

Ben Diamant
  • 6,186
  • 4
  • 35
  • 50
  • Yes i just found that out - i split the token into two and added it to the object but that obviously doesn't change the total size of the cookie value. Is that library that you supplied any different to the session storage accessed through $window.sessionStorage? I don't think it is... – Katana24 Feb 11 '15 at 13:37
  • Your answer is here - http://stackoverflow.com/questions/5523140/local-storage-vs-session-storage – Ben Diamant Feb 11 '15 at 14:10