Skip to content

Commit 7402324

Browse files
committed
fix(cookies): usage of cookie package
1 parent 1e77335 commit 7402324

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

.changeset/poor-garlics-flash.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+
update import cookies

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import cookie from 'cookie'
1+
import * as cookie from 'cookie'
22
import type { SerializeOptions } from 'cookie'
33
import {
44
createContext,
@@ -11,13 +11,12 @@ import {
1111
import type { PropsWithChildren } from 'react'
1212
import { uniq } from '../helpers/array'
1313
import { stringToHash } from '../helpers/misc'
14-
import { isCategoryKind } from './helpers'
14+
import { IS_CLIENT, isCategoryKind } from './helpers'
1515
import type { Config, Consent, Integrations } from './types'
1616
import { useSegmentIntegrations } from './useSegmentIntegrations'
1717

1818
const COOKIE_PREFIX = '_scw_rgpd'
1919
const HASH_COOKIE = `${COOKIE_PREFIX}_hash`
20-
const IS_CLIENT = typeof document !== 'undefined'
2120

2221
// Appx 13 Months
2322
const CONSENT_MAX_AGE = 13 * 30 * 24 * 60 * 60

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { useSegment } from '@scaleway/use-segment'
2-
import cookie from 'cookie'
2+
import * as cookie from 'cookie'
33
import type { PropsWithChildren } from 'react'
44
import { useCookieConsent } from './CookieConsentProvider'
5+
import { IS_CLIENT } from './helpers'
56
import { type CategoryKind } from './helpers'
67

78
export const AMPLITUDE_INTEGRATION_NAME = 'Amplitude (Actions)'
@@ -14,7 +15,9 @@ type ConsentObject = {
1415
}
1516

1617
export const getSessionId = () => {
17-
const sessionId = cookie.parse(document.cookie)[COOKIE_SESSION_ID_NAME]
18+
const sessionId = IS_CLIENT
19+
? cookie.parse(document.cookie)[COOKIE_SESSION_ID_NAME]
20+
: ''
1821
if (sessionId) {
1922
return Number.parseInt(sessionId, 10)
2023
}

packages/cookie-consent/src/CookieConsentProvider/helpers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ export type CategoryKind = (typeof categories)[number]
1010

1111
export const isCategoryKind = (key: string): key is CategoryKind =>
1212
categories.includes(key as CategoryKind)
13+
14+
export const IS_CLIENT = typeof document !== 'undefined'

0 commit comments

Comments
 (0)