Skip to content

Commit

Permalink
fix: do not discard already present set-cookie header (#327)
Browse files Browse the repository at this point in the history
fix: do not discard already present set-cookie header
  • Loading branch information
paulgv committed Jun 21, 2019
2 parents 1c314a9 + 5165d80 commit ec08be8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"acorn": "^6.1.1",
"acorn-dynamic-import": "^4.0.0",
"acorn-walk": "^6.1.1",
"cookie": "^0.4.0",
"cookies": "^0.7.3",
"is-https": "^1.0.0",
"js-cookie": "^2.2.0",
"vue-i18n": "^8.11.2",
Expand Down
9 changes: 5 additions & 4 deletions src/plugins/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Cookie from 'cookie'
import Cookies from 'cookies'
import JsCookie from 'js-cookie'
import Vue from 'vue'
import VueI18n from 'vue-i18n'
Expand Down Expand Up @@ -66,11 +66,12 @@ export default async (context) => {
path: '/'
})
} else if (res) {
const redirectCookie = Cookie.serialize(cookieKey, locale, {
const cookies = new Cookies(req, res)
cookies.set(cookieKey, locale, {
expires: new Date(date.setDate(date.getDate() + 365)),
path: '/'
path: '/',
httpOnly: false
})
res.setHeader('Set-Cookie', redirectCookie)
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/templates/middleware.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Cookie from 'cookie'
import Cookies from 'cookies'
import JsCookie from 'js-cookie'
import middleware from '../middleware'

middleware['i18n'] = async (context) => {
const { app, req, route, store, redirect, isHMR } = context;
const { app, req, res, route, store, redirect, isHMR } = context;

if (isHMR) {
return
Expand Down Expand Up @@ -43,8 +43,8 @@ middleware['i18n'] = async (context) => {
if (process.client) {
return JsCookie.get(cookieKey);
} else if (req && typeof req.headers.cookie !== 'undefined') {
const cookies = req.headers && req.headers.cookie ? Cookie.parse(req.headers.cookie) : {}
return cookies[cookieKey]
const cookies = new Cookies(req, res)
return cookies.get(cookieKey)
}
}
return null
Expand Down
15 changes: 14 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3079,7 +3079,7 @@ cookie-signature@1.0.6:
resolved "https://registry.yarnpkg.com/cookie-signature/-/cookie-signature-1.0.6.tgz#e303a882b342cc3ee8ca513a79999734dab3ae2c"
integrity sha1-4wOogrNCzD7oylE6eZmXNNqzriw=

cookie@0.4.0, cookie@^0.4.0:
cookie@0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.4.0.tgz#beb437e7022b3b6d49019d088665303ebe9c14ba"
integrity sha512-+Hp8fLp57wnUSt0tY0tHEXh4voZRDnoIrZPqlo3DPiI4y9lwg/jqx+1Om94/W6ZaPDOUbnjOt/99w66zk+l1Xg==
Expand All @@ -3089,6 +3089,14 @@ cookie@^0.3.1:
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.3.1.tgz#e7e0a1f9ef43b4c8ba925c5c5a96e806d16873bb"
integrity sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s=

cookies@^0.7.3:
version "0.7.3"
resolved "https://registry.yarnpkg.com/cookies/-/cookies-0.7.3.tgz#7912ce21fbf2e8c2da70cf1c3f351aecf59dadfa"
integrity sha512-+gixgxYSgQLTaTIilDHAdlNPZDENDQernEMiIcZpYYP14zgHsCt4Ce1FEjFtcp6GefhozebB6orvhAAWx/IS0A==
dependencies:
depd "~1.1.2"
keygrip "~1.0.3"

copy-concurrently@^1.0.0:
version "1.0.5"
resolved "https://registry.yarnpkg.com/copy-concurrently/-/copy-concurrently-1.0.5.tgz#92297398cae34937fcafd6ec8139c18051f0b5e0"
Expand Down Expand Up @@ -6362,6 +6370,11 @@ jsprim@^1.2.2:
json-schema "0.2.3"
verror "1.10.0"

keygrip@~1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/keygrip/-/keygrip-1.0.3.tgz#399d709f0aed2bab0a059e0cdd3a5023a053e1dc"
integrity sha512-/PpesirAIfaklxUzp4Yb7xBper9MwP6hNRA6BGGUFCgbJ+BM5CKBtsoxinNXkLHAr+GXS1/lSlF2rP7cv5Fl+g==

killable@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/killable/-/killable-1.0.1.tgz#4c8ce441187a061c7474fb87ca08e2a638194892"
Expand Down

0 comments on commit ec08be8

Please sign in to comment.