As a newcomer, I am currently working on storing cookies and setting parameters such as expiration date, domain name, and security. I have created a factory to handle cookie storage.
app.factory('SetCookies',function($cookieStore,$timeout,$window){
var authService = {};
authService.create = function (username,email,id,sessionID) {
var expired = new Date();
expired.setTime(expired.getTime() + (10*1000));
$cookieStore.put('Name',username, {expires : expired, secure:true, domain:'http://localhost/test' });
$cookieStore.put('Email',email, {expires : expired, secure:true, domain:'http://localhost/test' });
$cookieStore.put('LogCode',id, {expires : expired, secure:true, domain:'http://localhost/test' });
$cookieStore.put('Token',sessionID, {expires : expired, secure:true, domain:'http://localhost/test' });
$cookieStore.put('isLoggedIn',true, {expires : expired, secure:true, domain:'http://localhost/test' });
};
return authService;
})
In my login controller, I invoked this factory method to set the necessary cookies:
SetCookies.create(user.data.username, user.data.email, user.data.id, user.data.session_id);
After logging in, I checked the cookie timeout in the main controller:
$timeout(function(){
if(!$cookieStore.get('isLoggedIn')){
$location.path('/');
}
},20);
However, when I checked the cookies on various browsers, there was only one value present.
The outcome is depicted in the screenshot below: enter image description here