Skip to content

Commit 61156f6

Browse files
feat(cookie-consent): pass cookie options when deleting one consent (#1553)
1 parent 8012b81 commit 61156f6

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

.changeset/silver-camels-worry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@scaleway/cookie-consent': patch
3+
---
4+
5+
Pass cookie options when removing consent for a specific category

packages/cookie-consent/src/CookieConsentProvider/CookieConsentProvider.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ export const CookieConsentProvider = ({
152152
if (!consentValue) {
153153
// If consent is set to false we have to delete the cookie
154154
document.cookie = cookie.serialize(cookieName, '', {
155+
...cookiesOptions,
155156
expires: new Date(0),
156157
})
157158
} else {

packages/cookie-consent/src/CookieConsentProvider/__tests__/index.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,16 @@ describe('CookieConsent - CookieConsentProvider', () => {
149149
})
150150
})
151151

152-
const cookieOptions = { sameSite: 'strict', secure: true }
152+
const cookieOptions = { sameSite: 'strict', secure: true, path: '/' }
153153

154154
expect(spy).toHaveBeenCalledTimes(3)
155155
expect(spy).toHaveBeenNthCalledWith(2, '_scw_rgpd_marketing', 'true', {
156156
...cookieOptions,
157157
maxAge: 33696000,
158-
path: '/',
159158
})
160159
expect(spy).toHaveBeenNthCalledWith(3, '_scw_rgpd_hash', '913003917', {
161160
...cookieOptions,
162161
maxAge: 15552000,
163-
path: '/',
164162
})
165163

166164
act(() => {
@@ -172,12 +170,12 @@ describe('CookieConsent - CookieConsentProvider', () => {
172170

173171
expect(spy).toHaveBeenCalledTimes(6)
174172
expect(spy).toHaveBeenNthCalledWith(5, '_scw_rgpd_marketing', '', {
173+
...cookieOptions,
175174
expires: new Date(0),
176175
})
177176
expect(spy).toHaveBeenNthCalledWith(6, '_scw_rgpd_hash', '913003917', {
178177
...cookieOptions,
179178
maxAge: 15552000,
180-
path: '/',
181179
})
182180
})
183181

0 commit comments

Comments
 (0)