Is AngularJS $cookies still expiring after refreshing despite setting an expiration time in the options parameter?

Currently, I am developing an angular application that requires session tracking. To achieve this, I am utilizing the $cookies service in angular 1.4+. In my specific case, I am using version 1.4.9 for this project.

The issue arises when I log in as a user and set my cookies upon successful login with the following code:

var cookieArray = {session_id: sessID, token_access: accessToken};
$cookies.put('my_session', cookieArray, {expires: new Date(2016,6, 30)});

Upon checking my cookies in Chrome after logging in, I can see that the cookie has been properly created with expiration date set to July 30th, 2016. However, every time I refresh the page, this particular cookie is deleted. Although I have set the expires property, it doesn't seem to solve the issue. I have thoroughly reviewed the app's codebase but could not find any other instances where cookies are being tampered with, which leaves me puzzled.

Answer №1

Issue resolved! To assist others facing similar dilemmas, I wish to share my findings.

Initially, in this instance, when storing a complete object as a cookie, it is crucial to utilize the $cookies.putObject() function instead of solely using $cookies.put(). By doing so, the cookie will be stored appropriately and will not be deleted from the browser upon refresh, despite displaying "expires: ".

Furthermore, ensure that you retrieve the cookie by utilizing $cookies.getObject('key') before verifying a proper session.

I trust this information proves beneficial to those encountering difficulties with $cookies.put().

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

Dynamically add a plugin to jQuery during execution

After installing jQuery and a jQuery-Plugin via npm, I am facing the challenge of using it within an ES6 module. The issue arises from the fact that the plugin documentation only provides instructions for a global installation through the script tag, which ...

Angular: Intercept Drag and Drop Actions

I am utilizing angular-ui to create a sortable list using "drag and drop" functionality, and it is functioning perfectly. Here is an example of how it works: index.html <ul ui-sortable ng-model="list"> <li ng-repeat="item in list" class="it ...

"Encountering a JavaScript Issue While Displaying an iFrame

Having trouble displaying an iframe on a ColdFusion website when passing values in the URL. A similar method worked fine on a non-ColdFusion site, so I suspect the issue is with ColdFusion itself. Unfortunately, I have no experience with ColdFusion. If I ...

Fill a popup window with data retrieved from a MySQL query result

I have created an HTML page that displays data retrieved from a MySQL database. Users have the option to edit records, and I want to implement a modal form that opens up and shows data related to a specific "id" from the database when the edit button is cl ...

Angular - Execute a function once the observable has finished

I am currently working with a 2 part process that involves importing a list of usernames in Component 1, submitting it to a service, and then using the returned user profile data in Component 2. The issue I am facing is that when I receive the data back f ...

Combine a string variable and an array object in JavaScript or AngularJS

Hey there! I'm currently attempting to combine an array, a variable, and a "." in between them. The object I receive from json is stored in data, while valuePickup represents a variable. My current approach: self.GetIndex = function (valuePickup) { ...

Stylish CSS Tricks with Font Awesome Icons

In my project, I am utilizing Font Awesome SVG with JavaScript multiple times. Currently, I am working on creating a button that displays an arrow icon to the right of the text when hovered over. However, I encountered an issue where there is a blank squar ...

"Utilize Vue's model binding feature to assign a numerical value

I've encountered an issue while using v-model on an input box. I'm trying to bind the value as a number, but it doesn't seem to be working as expected. When I perform an operation like myModel += 25, instead of getting 125, I end up with 100 ...

Why doesn't vuex4.0 function properly as hooks when used within a Vue3 onMounted async function?

When foo() is completed, I need to choose one of bar1(), bar2(), or bar3() as the actual function to be sent to the web socket and store the callback value in vuex. 1. bar1(): If I include bar1() in the onMounted scope, it does not work and the store beco ...

"Troubrella: Attempting to inject one controller into another resulted in an error

I have a controller named A that I am trying to inject into all my other controllers. Controller A communicates with a factory that performs authentication services and interacts with the database. The factory, named myFactoryServices.js, is included in m ...

Why does the arrow function get executed right away once it is wrapped?

Currently, I am working on developing an app using react native. The goal is to have the screen automatically advance to the next one if there is no touch response within 5 seconds. I have implemented a function where pressing a button or entering text wi ...

Verify user access rights with Vue.js Laravel

I am currently working on a project using Laravel and Vue. In my middleware, I have the following code: public function handle($request, Closure $next) { $user = auth()->user(); if ($user->hasRole('admin')) { return ...

Is it possible to access an HttpOnly cookie in a node client environment?

Just dipping my toes into the world of Node.js and following along with some tutorials. I've managed to set up a basic node server running this code snippet: // MY SERVER CODE const http = require('http'); const Cookies = require('cook ...

Is there a way to determine if the cursor is currently focused on an input field, textarea, or select dropdown

To successfully submit a form after running an AJAX request and checking the result, you can use an "a" tag with an onclick function. However, using the enter key to submit the form may skip the AJAX code execution. One solution is to bind a keypress eve ...

Creating Stunning CSS Animations for a Slider Using SVG

Looking for help to create an SVG CSS animation for a slider using a mockup image. The animation will feature a balloon with a number value that zooms in and out from left to right or right to left. Currently stuck at the starting point and unsure how to ...

View the edited image preview instantly upon selecting the image

I have selected an image and previewed it before submitting the form. However, now I wish to be able to edit the file immediately after selecting it, preview the changes, and then submit the file. <input type ="file" accept="image/*" id="image" name="i ...

Display HTML content within designated fixed-column sizes

Looking to divide the content of an HTML file into multiple fixed size columns, both in terms of height and width, then display it in a Webview. I attempted employing the CSS properties mentioned below, but couldn't get it to function as desired. -we ...

Sending CustomData using ng-file-upload with WebApi

I'm facing an issue while attempting to upload a file along with some metadata to a WebApi Service that I built using ng-file-upload and Angular. The file name and bytes are coming through as expected, but the metadata I am trying to pass is not being ...

Getting the content of a textarea within a v-for loop collection

Exploring this particular situation In a .vue file within the template <div v-for="(tweet, index) in tweets"> <div class="each_tweet"> <textarea v-on:keyup="typing(index)" placeholder="Share your thoughts">{{ tweet.c ...

Execute a JavaScript function once the server-side validation has successfully been carried out

I am facing a challenge with a lightbox that contains a small form (2 fields) within an UpdatePanel. My goal is to close this lightbox using JavaScript when the 'Save' button is clicked. The complication arises from the presence of a server-side ...