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

Use expires setting for cookie #10

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Add documentation for i18n (first approach)

### Fixed
- Use expires setting value to set cookie.

## [1.2.1] - 2023-09-25
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ It's the `domain` of your cookie, by default the current website (`window.locati

### expires

It's the `expires` of your cookie, by default it is set for a month from the current day. It should be either a Date or a number.
It's the `expires` of your cookie, by default it is set for 92 days (3 months) from the current day. It should be a number of days.

### banner

Expand Down
4 changes: 2 additions & 2 deletions dist/assets/leckerli.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/defaultSettings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const defaultSettings = {
name: 'leckerli',
expires: 92,
banner: {
title: 'This website uses cookies.',
description:
Expand Down
8 changes: 2 additions & 6 deletions src/hooks/useSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,15 @@ const initialState = mergeDeepRight(
window.leckerliSettings ?? {}
);

// Build the expiration date
const expirationDate = new Date();
expirationDate.setMonth(expirationDate.getMonth() + 1);

// Define cookie configuration
const cookieConfig: {
sameSite: 'strict';
domain: string;
expires?: number | Date;
expires: number;
} = {
sameSite: 'strict',
domain: initialState.domain,
expires: expirationDate, // 1 month by default
expires: initialState.expires, // 3 months by default
};

// Get cookie value
Expand Down
1 change: 1 addition & 0 deletions src/types/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import defaultSettings from '../defaultSettings.ts';
type Settings = typeof defaultSettings & {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
baseData: any;
expires: number;
permissions: string[];
enableGtmAutoLoad: boolean;
};
Expand Down