Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why are we not auto setting sid cookie? #357

Open
Goutam192002 opened this issue Dec 2, 2021 · 3 comments
Open

Why are we not auto setting sid cookie? #357

Goutam192002 opened this issue Dec 2, 2021 · 3 comments

Comments

@Goutam192002
Copy link

Noticed that we do not set sid cookie automatically. Would like to understand the idea behind doing this?

Shouldn't there be a way to automatically check if sid cookie exists, set req.session else generate a new session and set the cookie?

Next also supports express style middlewares (https://nextjs.org/docs/middleware) Can we leverage that?

@hoangvvo
Copy link
Owner

hoangvvo commented Dec 4, 2021

I intentionally do not set sid cookie if no session value is set. The reason is that, if the session is empty while the sid cookie is set, we would have a redundant database call to query the session.

@Goutam192002
Copy link
Author

There are a lot of situations where a developer might need to use the session for analysing traffic..number of sessions per day, even though the session might be empty..atleast a page load might have happened.

@hoangvvo
Copy link
Owner

hoangvvo commented Dec 7, 2021

There are a lot of situations where a developer might need to use the session for analysing traffic..number of sessions per day, even though the session might be empty..atleast a page load might have happened.

In that case, can't you just set the session?

req.session.page_loaded = true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants