When opening a new tab, the login page appears despite being already logged in on a different tab

As a newcomer to web development, I have successfully added a login functionality on my website. However, I am facing an issue where opening a new tab and accessing the login URL redirects me to the login page even if I am already logged in on another tab. Ideally, I would like to be redirected to the homepage instead.

I am unsure of what part of the code to share as I am not sure what is causing this problem. I am using JavaScript and Backbone.js for the front end. Any help or guidance would be appreciated.

EDIT

After logging in, I receive a user-specific token from a REST service which I then use for further data retrieval. The issue arises when accessing this token in another tab, as it appears to be NULL due to browser session isolation. I need to implement a check to see if a token exists before redirecting to the home page. Where should I store this token to ensure it is accessible across multiple tabs? Your suggestions are welcome.

Answer â„–1

It's quite difficult to provide a definitive answer without examining your code, so I'll offer an educated guess:

Chances are that you're not generating a cookie with a sessionId after the user successfully logs in. This cookie would then be utilized in every request sent to the server to verify the user's authentication.

When you open a new tab and there's no existing cookie/session, this new instance of the application has no awareness of the other instance where the user is already logged in.

You may find helpful information in this answer

EDIT

You might be using sessionStorage instead of cookies, based on what I've learned about your app's behavior.

Refer to the documentation for session storage

The sessionStorage property provides access to a session Storage object. sessionStorage is comparable to Window.localStorage, but the difference lies in data stored in localStorage having no expiration set, whereas data in sessionStorage is cleared when the page session ends. A page session lasts as long as the browser remains open and persists through page reloads and restores. Opening a page in a new tab or window initiates a new session, different from how session cookies operate.

Ensure your application stores the token either in cookies or localStorage, and also reads from them correctly. Perhaps the cookies are being created but never read?

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

Increase the dimensions of the jQuery modal confirmation box

I am working on a jQuery confirmation dialog that displays some details for the user. My goal is to have the dialog adjust its dimensions after the user clicks "YES" to show a smaller text like "Please wait...". How can I dynamically change the size of the ...

"Maximizing Efficiency: Chaining Several Actions Using the JavaScript Ternary Operator

When the condition is true, how can I chain two operations together? a = 96 c = 0 a > 50 ? c += 1 && console.log('passed') : console.log('try more') I attempted chaining with && and it successfully worked in react, b ...

Having trouble retrieving the JSON value as it returns undefined

Having trouble extracting specific values from JSON data. I'm trying to retrieve the value of result.datafeed[0].prod[0].vertical[0].deviceProductJson[0].product_brand, but it keeps returning as undefined. To investigate further, I examined the stru ...

Guide to activating form elements using a JQuery function

I need help setting up a form with 11 rows and 11 columns. By default, the form fields should be disabled, but when I click on an "EDIT" button, they should become enabled. Any assistance would be greatly appreciated. Thank you in advance. Here is my edit ...

Methods for optimizing THREE.js performance

I'm currently working on developing a basic Minecraft-inspired game using THREE.js. Unfortunately, the performance of my project is not as smooth as I'd like it to be. My approach involves using box geometry for creating voxels, but I'm fa ...

How to retrieve an object variable in Java Nashorn

I've encountered an issue in my script where I am able to call methods using invokeMethod() in Java, but I'm struggling to access the content of object fields. Below is the JavaScript code snippet: var Test = { TestVar: "SomeTest", Te ...

Javascript beginner attempting to grasp the DOM using AJAX, feeling perplexed (conceptual)

I'm a data guy who dabbles in Python and web development, but lacks understanding of JavaScript and the DOM. Recently, I encountered a strange issue that prompted me to seek clarity on the mechanics behind it. The problem scenario: There are numerou ...

Is there a way to ensure that this ajax code functions seamlessly with all types of HTML files?

Currently, I am facing a challenge with an ajax call that retrieves data from a database, which I need to load into an HTML file. The issue lies in the fact that I have various HTML files and I am unaware of their contents. Despite spending countless hour ...

Managing Dark Mode in Material UI with Redux

Having a React application integrated with Material UI, I encountered an issue with the dark mode functionality. Whenever I attempt to modify the dark mode state on a page where the content is rendered from redux state data, the entire page crashes. It app ...

Nodemon is failing to automatically re-run the changes I've made in my local codebase

Recently, I developed a basic node function that simply outputs "hello world." When I ran the script using the command line node myfirst.js, it successfully displayed the message in the browser. Then, I decided to install nodemon so that it would re-exec ...

Implementing a configuration file into a client-side web application using asynchronous methods

Currently, I am facing a challenge with an SPA that is being developed using various custom components from different sources. The main issue at hand is how to initialize certain settings (such as Endpoint URLs) using a settings file that can be configure ...

Perform the trigger function when scrolling for the first time

I am working on a project where I need to trigger a click event when the user scrolls down 700px. This is the code I have so far: $(window).scroll(function(){ playVideo(); }); function playVideo() { var wScroll = $(window).scrollTop(); if (wS ...

I am looking to switch from a hamburger menu to a cross icon when clicked

Hey there, I'm currently working on a Shopify website and trying to make the hamburger menu change to a cross when clicked. I've been experimenting with different methods, but unfortunately haven't had any success so far. I have two images â ...

PHP enables users to look at manual values in columns and MySQL values row by row

I have created a PHP program to organize seating arrangements for an exam hall. The user manually inputs the names of the halls, which should be displayed in columns in a table. The register numbers are fetched from a MySQL database and should be displayed ...

What is the best way to invoke a JavaScript function that utilizes the jQuery library?

Recently I came across this interesting function: function squarifyMe(element) { squareItUp() window.onresize = function(element) { squareItUp(); } function squareItUp() { $(element).height($(element).width()); } } and its usage is as ...

Ways to downsize the ASPX page

I am currently working on a C#/ASP.NET web application in VS 2008 and facing an issue with the layout of my page. The buttons are appearing at the top, leaving a large gap between them and the resultLabel text. I have tried adjusting the label position m ...

Is there a way to show "Closed" or "Open" depending on the time in Vue.js HTML?

Here is the JSON data representing the hours of operation for a particular shop: { "status": true, "data": { "pid": 1, "bussinessName": "ard", "services": "looking for passionate", "inventory": [], "workHr": ...

Language setting required for dijit.form.DateTextBox

I am attempting to create a calendar control dynamically using Dojo 1.5 and set the language to Spanish, but so far I have been unsuccessful. I tried using "lang:es-es" among other things with no success... here is the element: <input type="text" const ...

Is it possible to create a query selector that is able to find an element based on its attributes while also excluding elements with a specific class name?

Imagine you have elements that look like this: <div class="a b" data-one="1" data-two="2"></div> <div class="c" data-one="1" data-two="2"></div> <div class="b" data-one="1" data-two="2"></div> Is there a way to selec ...

Executing a cloud function in Firebase from an Angular-Ionic application by making an HTTP request

I am a newcomer to GCP and app development, so please bear with me if this question seems mundane. Currently, I have an angular-ionic app that is connected to Firebase allowing me to interact with the Firestore database. Now, my challenge is to invoke a ht ...