I am currently implementing angularjs cookies in my project.
https://docs.angularjs.org/api/ngCookies/service/$cookies
Despite being aware of the security risks, I am using $cookies
to store user credentials. I aim for the user to log in once and have their session persist unless the cookies are manually cleared. However, I am facing an issue where the user has to log in again after closing the Chrome browser since the cookies are no longer available. I want the cookies to have a lasting presence without expiration.
Below is the relevant code segment written in a factory:
.factory('AuthenticationService',
['$base64', '$http', '$cookies', '$rootScope', '$timeout', 'configuration',
function ($base64, $http, $cookies, $rootScope, $timeout, $configuration) {
var service = {};
service.Login = function (username, password, callback) {
//login logic
};
service.SetCredentials = function (username, password) {
var authdata = $base64.encode(username + ':' + password);
$http.defaults.headers.common['Authorization'] = 'Basic ' + authdata;
$cookies.put('username', username);
$cookies.put('authdata', authdata);
};
return service;
}])
Is there a way to configure the cookies to never expire and persist even after the browser is closed?