The expiration time and domain name for cookies are not saved in Angular.js

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

Answer №1

Angularjs cookiestore has been phased out and developers are encouraged to utilize $cookies instead. However, some may find that $cookies can be a bit bloated. Personally, I have always preferred sticking to native JavaScript for handling cookies.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Steps to display page content only after running Java code in JSP

The webpage index.jsp is responsible for retrieving images and text data from a database using Java code. Within the JavaScript file, I have included: $(document).ready(function(){ //When Document is Ready, Show the Main Page $("#showifjavaenable ...

Text input not displaying as expected in React Native compared to a text area

I'm having trouble with the Text Area Placeholder not appearing in the center, I would like it to align with the top of the placeholder as shown in the image. Can you please provide suggestions on how to achieve this design? https://i.sstatic.net/Aqhn ...

Using JQuery to create an animated slideToggle effect for a multicolumn list

I have a large list where each li element has a width of 33%, resulting in 3 columns: computers monitors hi-fi sex-toys pancakes scissors Each column contains a hidden UL, which is revealed through slideToggle on click. JQuery $('.subCate ...

Hide other dropdown when one dropdown is clicked

I am currently working with a dropdown data-filter in combination with the isotope plugin. My goal is to have the ability to close an open dropdown when another list item is clicked, and also have the arrow twirl down when the dropdown is open. I am seek ...

Save a PHP variable following a JavaScript (or any other language) redirection

I am attempting to accomplish the following task: A parent element (referred to as A) should be the only means of accessing an iframe within another application (known as B) on the same domain. It is important that direct access to B is restricted, with a ...

Tips for fixing a shader issue with a custom hover state shader on an image component in a React project utilizing react-three-fiber

I am currently working on implementing an image component with a hover effect using shaders in react-three-fiber. The shader I'm using was originally created by TheFrost and it can be found at https://codepen.io/frost084/full/OKZNRm. However, I am e ...

How can I update my EJS template in ExpressJS after retrieving JSON data using NodeJS?

Utilizing NodeJS, I am making API calls and passing the data to my EJS template through ExpressJS with the following code snippet: app.get('/', function (req, res) { res.render('routes/index', { plLoopTimes: plLoopTimes, pl54Ti ...

Managing user sessions in Node.js

What is the best way to manage SESSIONS in Node.js? Specifically, I am interested in storing a UserID in a session using Node.js. How can this be accomplished, and is it possible to access that Node.js session in PHP as well? I am looking for an equivale ...

Substitute the expression with placeholders for JavaScript variables

Looking for a JavaScript regex pattern that will replace all instances of {{variableName}} with the corresponding JavaScript variable placeholders in a given string, such as ${variableName}. let str = 'Lorem ipsum dolor {{variable1}}, sit amet consect ...

Error encountered when auto-generating IDs in Next.js with Firebase Firestore database

Hello, I am trying to access the details of my page in Next.js and retrieve data from a Firestore database. Here is the error message I am encountering: Firebase initialized successfully page.js:32 router.query: undefined page.js:34 Movie ID: undefined p ...

Automatically switch Twitter Bootstrap tabs without any manual effort

Is there a way to set up the Twitter Bootstrap tabs to cycle through on their own, similar to a carousel? I want each tab to automatically switch to the next one every 10 seconds. Check out this example for reference: If you click on the news stories, yo ...

The system was unable to locate node.js with socket.io

I'm having trouble locating the file. According to the documentation I reviewed, socket.io is supposed to be automatically exposed. Encountered Error: polling-xhr.js?bd56:264 GET http://localhost:8081/socket.io/?EIO=3&transport=polling&t=LyY ...

Reset the input field once the message has been successfully sent

My goal is to clear the form message input field after the form is sent. However, it seems to be clearing the data before it has a chance to be sent. Here is the code I'm using: <script> $(function () { $('form#SendForm'). ...

Issues with choosing AngularJs

I am facing a couple of issues. There are 2 items within my scope: 1) tasks: 12: id: 12 user_id: 1 2) users: 1: id: 1 username: sergey I am attempting to display a select with a default value (in this case it s ...

Unable to host Express and React application on port 80

I have a React application compiled with Express serving as a static React site, and I want to host them on port 80. The challenge is that my VPS runs Ubuntu with Plesk Onyx supporting multiple applications as subdomains on vhosts using port 80: server.l ...

Access the contents of objects during the creation process

I am currently in the process of creating a large object that includes API path variables. The challenge I am facing is the need to frequently modify these API paths for application migration purposes. To address this, I had the idea of consolidating base ...

Could anyone assist me in positioning my personalized Context Menu beside my cursor?

If possible, I would appreciate some assistance with my custom context menu. It may require some minor tweaks or a fresh idea on how to address the issue. Ideally, I would like to keep the HTML and CSS somewhat unchanged. [I'm not sure what to write ...

Error in retrieving information from the worldweatheronline API

I have been attempting to retrieve weather information from 'worldweatheronline' by making an $http call in an angular factory: this.testApi = function(coords) { var deferred = $q.defer(); $http.jsonp(API_ROOTS + '?key=9834 ...

Coordinating communication between separate AngularJS directives autonomously

Instead of directly addressing the issue at hand, I am taking a more organizational approach. My query revolves around having two directives that are independent of each other and can function separately to fulfill their respective purposes. However, if on ...

Can you create a dropdown menu using information from one JSON file and have the selected option come from another source?

Recently, I came across this JavaScript code that is supposed to create a dropdown list of statuses: $.getJSON('/statuses', { ajax: 'true' }, function (data) { var html; var len = data.length; html + ...