mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-23 14:59:36 +02:00
Enhance cookie management: set SameSite attribute for locale and theme cookies, and add comments for clarity
This commit is contained in:
parent
02f534662b
commit
958e9de84e
2 changed files with 6 additions and 5 deletions
|
@ -24,7 +24,7 @@
|
||||||
const submitLocaleChange = (event: Event) => {
|
const submitLocaleChange = (event: Event) => {
|
||||||
const select = event.target as HTMLSelectElement;
|
const select = event.target as HTMLSelectElement;
|
||||||
const newLocale = select.value;
|
const newLocale = select.value;
|
||||||
document.cookie = `locale=${newLocale}; path=/`;
|
document.cookie = `locale=${newLocale}; path=/; max-age=${60 * 60 * 24 * 365}; SameSite=Lax`;
|
||||||
locale.set(newLocale);
|
locale.set(newLocale);
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,7 +11,8 @@ export const actions: Actions = {
|
||||||
if (theme && themes.find((t) => t.name === theme)) {
|
if (theme && themes.find((t) => t.name === theme)) {
|
||||||
cookies.set('colortheme', theme, {
|
cookies.set('colortheme', theme, {
|
||||||
path: '/',
|
path: '/',
|
||||||
maxAge: 60 * 60 * 24 * 365
|
maxAge: 60 * 60 * 24 * 365, // 1 year
|
||||||
|
sameSite: 'lax'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -39,11 +40,11 @@ export const actions: Actions = {
|
||||||
},
|
},
|
||||||
setLocale: async ({ url, cookies }) => {
|
setLocale: async ({ url, cookies }) => {
|
||||||
const locale = url.searchParams.get('locale');
|
const locale = url.searchParams.get('locale');
|
||||||
// change the theme only if it is one of the allowed themes
|
// change the locale only if it is one of the allowed locales
|
||||||
if (locale && ['en', 'es'].includes(locale)) {
|
if (locale) {
|
||||||
cookies.set('locale', locale, {
|
cookies.set('locale', locale, {
|
||||||
path: '/',
|
path: '/',
|
||||||
maxAge: 60 * 60 * 24 * 365
|
maxAge: 60 * 60 * 24 * 365 // 1 year
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue