After shutting down the tab in Vuejs, Chrome automatically clears the localstorage

While working on a web app using Vuejs, I encountered an issue with storing the jwt token in localstorage. Every time I close the tab, the token gets lost and requires me to login again. Interestingly, the app works fine in Opera GX but not in Google Chrome.

This is how I set the token :

localStorage.setItem("token", token);

And this is how I retrieve it :

let token = localStorage.getItem("token");

Answer №1

It seems the issue lies with Chrome browser,

Make sure to use

localstorage.getItem("X")
before you
setItem("X","V")

This will ensure that the local storage persists even after closing the browser.

I found this helpful link: Why isn't localStorage persisting in Chrome?

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

Implementing a change event upon setting a value to an input element using JavaScript

My plan is to develop a Chrome extension that can automatically fill passwords. The code for this functionality looks like the following: //get the account document.querySelector("input[type=text]").addEventListener('input', () => { ...

Error: Unexpected token encountered during the implementation of a reducer in Redux

Every time I use gulp to build my application, it keeps throwing a syntax error at me: SyntaxError: /Users/USER/Documents/portfolio_projects/USER_PROJECT/PROJECT/src/main/webapp/src/reducers/AuthorizationReducer.js: Unexpected token (12:4) while parsing ...

Using JavaScript parameters in a HTML document

I am trying to replicate a page similar to this. The issue I am facing is the inability to use external JS files in ASP.net (as far as I know). Therefore, I am defining the functions and attempting to utilize them within the HTML page instead. <%@ P ...

Setting up CORS in my React application with a Node.js backend

I created my react app using create-react-app. The app performs a POST call to an external API (elasticsearch) hosted on a different server not managed by me. When the user inputs data into the form and submits it, the onSubmit function calls getResponse() ...

Expression or ng-bind doesn't display

Let me explain the situation: (in controller) var userData = $http( { method: "post", url: "http://localhost/t-app/mobile-data/update-tasks.php", data: { done_tasks : $scope.done_tasks, job_id: $routeParams.job_id, emp ...

The reduction method in d3 is producing a result of NaN

UPDATE: I have added a JSFIDDLE link and adjusted the original values in this post to match. However, the fiddle is not functioning properly due to the external CSV file. I attempted a solution found on this thread, but was unsuccessful. Nevertheless, you ...

Is it possible to extract a specific value from JSON data by making an AJAX call or applying a filter to the fetched JSON data?

I have been utilizing a treeview template and successfully displaying all the data. However, I am facing an issue where I need to pass a value from index.php to getdata.php. I attempted using an AJAX filter on the index.php page and also tried sending a v ...

The function document.getElementById(...) is failing to retrieve the text data from the table as expected

Greetings fellow HTML and JavaScript novice! I've got a table with input cells in the bottom row: <table class="convtbl" id="table1"> <tr> <td>Distance 1 (in miles)</td> <td>Time ...

What could be causing the ajax request to return empty data?

In the given scenario, there is a form with a field for uploading a file. Upon submitting the form using AJAX post method to send it to the server, I observe that the FormData contains data on the client-side but does not reach the server (request.POST={}) ...

Leveraging the filter functionality within an AngularJS table

I'm currently developing a web application using AngularJS with MVC. I am trying to implement data filtering within my table, but encountering an error during debugging. Here is the specific error message: link to error description Error: $rootSco ...

- increase clarity and readability- separate sections for better

I'm working on a code snippet to showcase 4 buttons: #buttons { text-align: center; padding-top: 4%; } #buttons img { display: inline-block; list-style: none; padding: 10px; } #buttons p { color: #fff; font-family: ; font-weight: ...

Force jQuery to refresh the data entered in the input field

I have a range slider that updates an input field with data. My goal is to multiply this data by 50 and display the result below it, but unfortunately, the script only seems to work when I manually enter data into the field. For instance, if you input 5 i ...

Using VueJS to assign data within a method function

Below is the HTML code that I have written: <div id="myApp"> <div class="items"> <div class="item" v-for="quiz in quizzes" :key="quiz.id"} <span>{{ quiz.question }}</span> <span v-if="selected[quiz. ...

Ever wonder what goes on behind the scenes when you press a button before the Javascript method is carried out

My web application is built using ASP.NET MVC 4, jQuery, and Telerik's Kendo controls. Within my webpage, I have the following code snippet: <input id="cmdSaveToFile" title="Save To File" class="button" type="button" value="Save To File" onclick= ...

Dynamically load npm modules in Webpack using variables for the require statement

Is there a way to dynamically require an NPM module using a variable? Below is the sample code I've been trying, everything seems to be working fine except for importing NPM modules dynamically. const firstModule = 'my-npm-module'; const s ...

Choosing read-only text fields using JQuery

I am working on an ASP.NET MVC project and I am looking to select all text boxes with the "readOnly" attribute on the current page. Once identified, I want to trigger a modal jQuery dialog on keypress for each of these disabled text boxes. Any suggestion ...

Creating a wrapper class in Express JS: A step-by-step guide

I am currently developing a basic wrapper app that retrieves the following information from user requests: a) Request Date & Time b) Request URL c) Response Time This is my approach to wrapping the functionality using Express.js: var express = require(&a ...

What's the best way to incorporate a clear options icon when choosing an option in a MaterialUI select component?

I am looking to enhance the user experience by adding a clear options icon that appears when a selection is made from the list of options. <Select InputProps={{ startAdornment: ( <InputAdornment position='end'> <Cl ...

having difficulty grasping the variable's scope within this code

Here we have a code snippet where the variable vid is initialized inside a function. The question arises on how this variable can be used outside the function, specifically in the context of vid.play(). How does the program know that vid was created usin ...

Using jQuery to create a function that triggers when the value of a text input is altered

I am currently working on creating a function that will be triggered when the value of a text input changes. The function works fine if I manually change the value, but it does not work if the value is changed automatically by an event on another element. ...