1

I am running my client(frondend) app express app in a port 3000 and another admin express app in 8080.

But when I am navigating any pages or refreshing any page in client express app, the session in admin app is lost and redirecting to login.

I am using Express-session npm for admin and frond end is just like a cms frondend, ie no sessions or anything complex. Can any body tell me why is this happening?

1
  • 1
    Without knowing how you setup the session handling in your code it is not possible to tell. But I would doubt that the session is lost because of navigating in the other node app. It is more likely that you set a low lifetime for the session and that it just times out because of inactivity. Commented Oct 6, 2016 at 5:38

3 Answers 3

2

Cookies for an app running on port 3000 are also sent to an app running on port 8080 (and vice versa).

My guess is that you didn't give each app a unique cookie name, so you might get interference between the session handling of both apps.

So, use a different cookie name for each:

app.use(session({
  name : 'frontend.sid', // and, say, 'admin.sid' for the admin app
  ...
}));
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Robert.. This works... And May I ask you one more which I found session-memory-store module. SInce express-session stores value on memory store, using this for production wont be viable (as said in doc itself not suit for production). So Using session-memory-store do provide any help in production??
@AkhilGopan I wouldn't use the memory store in production. But there are a lot of alternatives, perhaps one that will work with a database that you're already using.
Thankyou Robert...I use Postgres and I will implement using it.
0

Run in different browsers :

try one of them in different browser like one in chrome and other in mozilla. It is happening due to session clashing over there.

Changing the browser might be a good solution for you.

Want to run in same browser :

Just run one service in normal mode and run other service in incognito mode

Comments

0

Based on the provided information I would suggest that you look over to the way you are initialising express-session. In case that the secure flag is set to true, it would expect a valid HTTPS certificate to be set for localhost, otherwise the session wont be created which can cause redirect problems.

From the docs:

secure: Specifies the boolean value for the Secure Set-Cookie attribute. When truthy, the Secure attribute is set, otherwise it is not. By default, the Secure attribute is not set. Please note that secure: true is a recommended option. However, it requires an https-enabled website, i.e., HTTPS is necessary for secure cookies. If secure is set, and you access your site over HTTP, the cookie will not be set.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.