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

Keep locale after session was closed #431

Closed
Natchii59 opened this issue Jul 30, 2023 · 6 comments · Fixed by #435
Closed

Keep locale after session was closed #431

Natchii59 opened this issue Jul 30, 2023 · 6 comments · Fixed by #435
Labels
enhancement New feature or request unconfirmed Needs triage.

Comments

@Natchii59
Copy link

Is your feature request related to a problem? Please describe.

When I close and open my site, it resumes my language preferences, instead of keeping the language I had chosen recently.

Describe the solution you'd like

Add the ability to keep the previous language.

Describe alternatives you've considered

The language is stored in a cookie whose age is the current session. You should fix that or store it in localStorage. Or have the possibility of saying which language to use from a user that is retrieved via database or from a token (Auth.js). That would be the best thing to do.

@Natchii59 Natchii59 added enhancement New feature or request unconfirmed Needs triage. labels Jul 30, 2023
@amannn
Copy link
Owner

amannn commented Jul 31, 2023

The cookie that next-intl sets doesn't expire after the session finishes.

It seems like Next.js/Vercel has an issue though where sometimes requests are cached too aggressively and therefore on locale change, the middleware doesn't run, which would update the cookie value. I'm wondering if it's worth trying to add a workaround to mitigate this.

Is that the bug you're seeing too?

Or have the possibility of saying which language to use from a user that is retrieved via database or from a token (Auth.js). That would be the best thing to do.

You can already do that if you prefer.

@Natchii59
Copy link
Author

@amannn Next-intl cookie expiration date is Session.

To store the language in a user in a database, do you have an example?

@amannn
Copy link
Owner

amannn commented Aug 1, 2023

Next-intl cookie expiration date is Session.

Oh, you're absolutely right—sorry for the confusion!

I've added #435 to set the max-age to one year. Does this sound right to you?

To store the language in a user in a database, do you have an example?

Currently not, unfortunately. You'd probably read it in the middleware and maybe adjust the request before passing it to the middleware.

@Natchii59
Copy link
Author

I've added #435 to set the max-age to one year. Does this sound right to you?

Is it possible to customize this? (Change the max-age as desired) @amannn

@amannn
Copy link
Owner

amannn commented Aug 2, 2023

Currently not, no. Do you have a need for it? My assumption is that you'd want to keep a manually changed locale around for as long as possible.

@Natchii59
Copy link
Author

I think it would be better for developers, depending on their needs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request unconfirmed Needs triage.
Projects
None yet
2 participants