Skip to content

Commit c844fd0

Browse files
committed
Always set same site as lax while setting cookies
1 parent 75f1c90 commit c844fd0

File tree

6 files changed

+58
-56
lines changed

6 files changed

+58
-56
lines changed

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"npmClient": "yarn",
33
"useWorkspaces": true,
4-
"version": "2.2.3"
4+
"version": "2.2.4"
55
}

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
},
66
"description": "Enable dark mode for Next.js",
77
"devDependencies": {
8-
"@typescript-eslint/eslint-plugin": "^2.28.0",
9-
"@typescript-eslint/parser": "^2.28.0",
8+
"@typescript-eslint/eslint-plugin": "^2.31.0",
9+
"@typescript-eslint/parser": "^2.31.0",
1010
"eslint": "^6.8.0",
1111
"eslint-config-alloy": "^3.7.1",
1212
"eslint-plugin-react": "^7.19.0",
1313
"husky": "4.2.5",
1414
"lerna": "^3.20.2",
15-
"lint-staged": "^10.1.6",
15+
"lint-staged": "^10.2.2",
1616
"rimraf": "3.0.2",
1717
"typescript": "^3.8.3"
1818
},
@@ -34,7 +34,7 @@
3434
"publish:release": "lerna publish --tag-version-prefix=\"\" --force-publish=* --no-push --no-git-tag-version",
3535
"start": "yarn build:quick && lerna run start --parallel"
3636
},
37-
"version": "2.2.3",
37+
"version": "2.2.4",
3838
"workspaces": [
3939
"packages/*"
4040
]

packages/next-dark-mode-example/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
},
66
"dependencies": {
77
"next": "^9.3.6",
8-
"next-dark-mode": "^2.2.3",
8+
"next-dark-mode": "^2.2.4",
99
"react": "^16.13.1",
1010
"react-dom": "^16.13.1"
1111
},
@@ -29,5 +29,5 @@
2929
"serve": "next start",
3030
"start": "next"
3131
},
32-
"version": "2.2.3"
32+
"version": "2.2.4"
3333
}

packages/next-dark-mode/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
},
66
"dependencies": {
77
"@assortment/darkmodejs": "^1.2.0",
8-
"nookies": "^2.2.2"
8+
"nookies": "^2.3.0"
99
},
1010
"description": "Enable dark mode for Next.js",
1111
"devDependencies": {
1212
"@types/cookie": "^0.3.3",
1313
"@types/react": "^16.9.34",
14-
"concurrently": "^5.1.0",
15-
"next": "^9.3.5",
14+
"concurrently": "^5.2.0",
15+
"next": "^9.3.6",
1616
"react": "^16.13.1",
1717
"react-dom": "^16.13.1"
1818
},
@@ -43,5 +43,5 @@
4343
},
4444
"source": "src/index.tsx",
4545
"types": "es6/index.d.ts",
46-
"version": "2.2.3"
46+
"version": "2.2.4"
4747
}

packages/next-dark-mode/src/index.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ export default (App: NextComponentType | any, config?: Partial<Config>) => {
2525
switchToAutoMode: () => {
2626
setState(state => {
2727
if (state.autoModeSupported) {
28-
setCookie(null, autoModeCookieName, '1', {})
28+
setCookie(null, autoModeCookieName, '1', { sameSite: 'lax' })
2929
const darkModeActive = state.browserMode === MODE.DARK
30-
setCookie(null, darkModeCookieName, darkModeActive ? '1' : '0', {})
30+
setCookie(null, darkModeCookieName, darkModeActive ? '1' : '0', { sameSite: 'lax' })
3131

3232
return { ...state, autoModeActive: true, darkModeActive }
3333
}
@@ -37,13 +37,13 @@ export default (App: NextComponentType | any, config?: Partial<Config>) => {
3737
},
3838
switchToDarkMode: () => {
3939
setState(state => ({ ...state, autoModeActive: false, darkModeActive: true }))
40-
setCookie(null, autoModeCookieName, '0', {})
41-
setCookie(null, darkModeCookieName, '1', {})
40+
setCookie(null, autoModeCookieName, '0', { sameSite: 'lax' })
41+
setCookie(null, darkModeCookieName, '1', { sameSite: 'lax' })
4242
},
4343
switchToLightMode: () => {
4444
setState(state => ({ ...state, autoModeActive: false, darkModeActive: false }))
45-
setCookie(null, autoModeCookieName, '0', {})
46-
setCookie(null, darkModeCookieName, '0', {})
45+
setCookie(null, autoModeCookieName, '0', { sameSite: 'lax' })
46+
setCookie(null, darkModeCookieName, '0', { sameSite: 'lax' })
4747
},
4848
})
4949

@@ -54,10 +54,10 @@ export default (App: NextComponentType | any, config?: Partial<Config>) => {
5454
case themes.DARK:
5555
setState(state => {
5656
if (state.autoModeSupported) {
57-
setCookie(null, darkModeCookieName, '1', {})
57+
setCookie(null, darkModeCookieName, '1', { sameSite: 'lax' })
5858
return { ...state, browserMode: MODE.DARK, darkModeActive: true }
5959
} else {
60-
if (state.autoModeActive) setCookie(null, darkModeCookieName, '1', {})
60+
if (state.autoModeActive) setCookie(null, darkModeCookieName, '1', { sameSite: 'lax' })
6161
return {
6262
...state,
6363
autoModeSupported: true,
@@ -70,10 +70,10 @@ export default (App: NextComponentType | any, config?: Partial<Config>) => {
7070
case themes.LIGHT:
7171
setState(state => {
7272
if (state.autoModeSupported) {
73-
setCookie(null, darkModeCookieName, '0', {})
73+
setCookie(null, darkModeCookieName, '0', { sameSite: 'lax' })
7474
return { ...state, browserMode: MODE.LIGHT, darkModeActive: false }
7575
} else {
76-
if (state.autoModeActive) setCookie(null, darkModeCookieName, '0', {})
76+
if (state.autoModeActive) setCookie(null, darkModeCookieName, '0', { sameSite: 'lax' })
7777
return {
7878
...state,
7979
autoModeSupported: true,
@@ -85,7 +85,7 @@ export default (App: NextComponentType | any, config?: Partial<Config>) => {
8585
break
8686
case themes.NO_PREF:
8787
case themes.NO_SUPP:
88-
setCookie(null, autoModeCookieName, '0', {})
88+
setCookie(null, autoModeCookieName, '0', { sameSite: 'lax' })
8989
setState(state => ({ ...state, autoModeSupported: false }))
9090
break
9191
}
@@ -115,8 +115,10 @@ export default (App: NextComponentType | any, config?: Partial<Config>) => {
115115
const autoModeString = autoMode ? '1' : '0'
116116
const darkModeString = darkMode ? '1' : '0'
117117

118-
if (autoModeString !== autoModeCookie) setCookie(appContext.ctx, autoModeCookieName, autoModeString, {})
119-
if (darkModeString !== darkModeCookie) setCookie(appContext.ctx, darkModeCookieName, darkModeString, {})
118+
if (autoModeString !== autoModeCookie)
119+
setCookie(appContext.ctx, autoModeCookieName, autoModeString, { sameSite: 'lax' })
120+
if (darkModeString !== darkModeCookie)
121+
setCookie(appContext.ctx, darkModeCookieName, darkModeString, { sameSite: 'lax' })
120122

121123
return { autoMode, darkMode, initialProps }
122124
}

yarn.lock

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,40 +2055,40 @@
20552055
"@types/events" "*"
20562056
"@types/node" "*"
20572057

2058-
"@typescript-eslint/eslint-plugin@^2.30.0":
2059-
version "2.30.0"
2060-
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.30.0.tgz#312a37e80542a764d96e8ad88a105316cdcd7b05"
2061-
integrity sha512-PGejii0qIZ9Q40RB2jIHyUpRWs1GJuHP1pkoCiaeicfwO9z7Fx03NQzupuyzAmv+q9/gFNHu7lo1ByMXe8PNyg==
2058+
"@typescript-eslint/eslint-plugin@^2.31.0":
2059+
version "2.31.0"
2060+
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.31.0.tgz#942c921fec5e200b79593c71fafb1e3f57aa2e36"
2061+
integrity sha512-iIC0Pb8qDaoit+m80Ln/aaeu9zKQdOLF4SHcGLarSeY1gurW6aU4JsOPMjKQwXlw70MvWKZQc6S2NamA8SJ/gg==
20622062
dependencies:
2063-
"@typescript-eslint/experimental-utils" "2.30.0"
2063+
"@typescript-eslint/experimental-utils" "2.31.0"
20642064
functional-red-black-tree "^1.0.1"
20652065
regexpp "^3.0.0"
20662066
tsutils "^3.17.1"
20672067

2068-
"@typescript-eslint/experimental-utils@2.30.0":
2069-
version "2.30.0"
2070-
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-2.30.0.tgz#9845e868c01f3aed66472c561d4b6bac44809dd0"
2071-
integrity sha512-L3/tS9t+hAHksy8xuorhOzhdefN0ERPDWmR9CclsIGOUqGKy6tqc/P+SoXeJRye5gazkuPO0cK9MQRnolykzkA==
2068+
"@typescript-eslint/experimental-utils@2.31.0":
2069+
version "2.31.0"
2070+
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-2.31.0.tgz#a9ec514bf7fd5e5e82bc10dcb6a86d58baae9508"
2071+
integrity sha512-MI6IWkutLYQYTQgZ48IVnRXmLR/0Q6oAyJgiOror74arUMh7EWjJkADfirZhRsUMHeLJ85U2iySDwHTSnNi9vA==
20722072
dependencies:
20732073
"@types/json-schema" "^7.0.3"
2074-
"@typescript-eslint/typescript-estree" "2.30.0"
2074+
"@typescript-eslint/typescript-estree" "2.31.0"
20752075
eslint-scope "^5.0.0"
20762076
eslint-utils "^2.0.0"
20772077

2078-
"@typescript-eslint/parser@^2.30.0":
2079-
version "2.30.0"
2080-
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-2.30.0.tgz#7681c305a6f4341ae2579f5e3a75846c29eee9ce"
2081-
integrity sha512-9kDOxzp0K85UnpmPJqUzdWaCNorYYgk1yZmf4IKzpeTlSAclnFsrLjfwD9mQExctLoLoGAUXq1co+fbr+3HeFw==
2078+
"@typescript-eslint/parser@^2.31.0":
2079+
version "2.31.0"
2080+
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-2.31.0.tgz#beddd4e8efe64995108b229b2862cd5752d40d6f"
2081+
integrity sha512-uph+w6xUOlyV2DLSC6o+fBDzZ5i7+3/TxAsH4h3eC64tlga57oMb96vVlXoMwjR/nN+xyWlsnxtbDkB46M2EPQ==
20822082
dependencies:
20832083
"@types/eslint-visitor-keys" "^1.0.0"
2084-
"@typescript-eslint/experimental-utils" "2.30.0"
2085-
"@typescript-eslint/typescript-estree" "2.30.0"
2084+
"@typescript-eslint/experimental-utils" "2.31.0"
2085+
"@typescript-eslint/typescript-estree" "2.31.0"
20862086
eslint-visitor-keys "^1.1.0"
20872087

2088-
"@typescript-eslint/typescript-estree@2.30.0":
2089-
version "2.30.0"
2090-
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.30.0.tgz#1b8e848b55144270255ffbfe4c63291f8f766615"
2091-
integrity sha512-nI5WOechrA0qAhnr+DzqwmqHsx7Ulr/+0H7bWCcClDhhWkSyZR5BmTvnBEyONwJCTWHfc5PAQExX24VD26IAVw==
2088+
"@typescript-eslint/typescript-estree@2.31.0":
2089+
version "2.31.0"
2090+
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.31.0.tgz#ac536c2d46672aa1f27ba0ec2140d53670635cfd"
2091+
integrity sha512-vxW149bXFXXuBrAak0eKHOzbcu9cvi6iNcJDzEtOkRwGHxJG15chiAQAwhLOsk+86p9GTr/TziYvw+H9kMaIgA==
20922092
dependencies:
20932093
debug "^4.1.1"
20942094
eslint-visitor-keys "^1.1.0"
@@ -5542,7 +5542,7 @@ humanize-ms@^1.2.1:
55425542
dependencies:
55435543
ms "^2.0.0"
55445544

5545-
husky@^4.2.5:
5545+
husky@4.2.5:
55465546
version "4.2.5"
55475547
resolved "https://registry.yarnpkg.com/husky/-/husky-4.2.5.tgz#2b4f7622673a71579f901d9885ed448394b5fa36"
55485548
integrity sha512-SYZ95AjKcX7goYVZtVZF2i6XiZcHknw50iXvY7b0MiGoj5RwdgRQNEHdb+gPDPCXKlzwrybjFjkL6FOj8uRhZQ==
@@ -7189,10 +7189,10 @@ node-releases@^1.1.44, node-releases@^1.1.53:
71897189
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.1.53.tgz#2d821bfa499ed7c5dffc5e2f28c88e78a08ee3f4"
71907190
integrity sha512-wp8zyQVwef2hpZ/dJH7SfSrIPD6YoJz6BDQDpGEkcA0s3LpAQoxBIYmfIq6QAhC1DhwsyCgTaTTcONwX8qzCuQ==
71917191

7192-
nookies@^2.2.4:
7193-
version "2.2.4"
7194-
resolved "https://registry.yarnpkg.com/nookies/-/nookies-2.2.4.tgz#e77f731cbe33c839e70744cba7605a5784da5783"
7195-
integrity sha512-2AzKgbirUaky+b9nCFbTB/EMfKWAzftLpnVOyLxN3n5UabbWKHE/zLZz6zQwPgckgZhKl9yM4eBZ+KJNSi3J8w==
7192+
nookies@^2.3.0:
7193+
version "2.3.0"
7194+
resolved "https://registry.yarnpkg.com/nookies/-/nookies-2.3.0.tgz#56726ff10a6455820e4ff0d11602c3af2b21a0cb"
7195+
integrity sha512-qet6azxnYVeojj4O9qmm0pL8yp8QWrnPQZxS8aZED5s1vGQmhLhoWK4iYS1NDL6ajhpgHzCMPYjqsWSH83xvQw==
71967196
dependencies:
71977197
cookie "^0.4.0"
71987198
set-cookie-parser "^2.4.3"
@@ -8877,20 +8877,20 @@ rimraf@2.6.3:
88778877
dependencies:
88788878
glob "^7.1.3"
88798879

8880+
rimraf@3.0.2:
8881+
version "3.0.2"
8882+
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.2.tgz#f1a5402ba6220ad52cc1282bac1ae3aa49fd061a"
8883+
integrity sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==
8884+
dependencies:
8885+
glob "^7.1.3"
8886+
88808887
rimraf@^2.5.4, rimraf@^2.6.2, rimraf@^2.6.3:
88818888
version "2.7.1"
88828889
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.7.1.tgz#35797f13a7fdadc566142c29d4f07ccad483e3ec"
88838890
integrity sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==
88848891
dependencies:
88858892
glob "^7.1.3"
88868893

8887-
rimraf@^3.0.2:
8888-
version "3.0.2"
8889-
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.2.tgz#f1a5402ba6220ad52cc1282bac1ae3aa49fd061a"
8890-
integrity sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==
8891-
dependencies:
8892-
glob "^7.1.3"
8893-
88948894
ripemd160@^2.0.0, ripemd160@^2.0.1:
88958895
version "2.0.2"
88968896
resolved "https://registry.yarnpkg.com/ripemd160/-/ripemd160-2.0.2.tgz#a1c1a6f624751577ba5d07914cbc92850585890c"

0 commit comments

Comments
 (0)