chore: make theme cookie expire after 365 days

This commit is contained in:
Nicolas Meienberger 2023-10-23 08:47:36 +02:00
parent 1dd64af4ed
commit 3972340fe7

View file

@ -16,13 +16,13 @@ export const ThemeProvider = (props: Props) => {
useEffect(() => {
if (theme) {
cookies.set('theme', theme || initialTheme || 'light', { path: '/' });
cookies.set('theme', theme || initialTheme || 'light', { path: '/', expires: 365 });
document.body.dataset.bsTheme = theme;
} else if (!cookies.get('theme')) {
// Detect system theme
const systemTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
setDarkMode(systemTheme === 'dark');
cookies.set('theme', systemTheme, { path: '/' });
cookies.set('theme', systemTheme, { path: '/', expires: 365 });
document.body.dataset.bsTheme = systemTheme;
}