diff --git a/lib/index.js b/lib/index.js index ec731881..8142f626 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,6 +1,7 @@ import ironStore from "iron-store"; import cookie from "cookie"; import createDebug from "debug"; +import flat from "array.prototype.flat"; const debug = createDebug("next-iron-session"); @@ -67,7 +68,7 @@ export async function applySession( `next-iron-session: Cookie length is too big ${cookieValue.length}, browsers will refuse it`, ); } - const existingSetCookie = [res.getHeader("set-cookie") || []].flat(); + const existingSetCookie = flat([res.getHeader("set-cookie") || []]); res.setHeader("set-cookie", [...existingSetCookie, cookieValue]); return cookieValue; }, @@ -77,7 +78,7 @@ export async function applySession( ...cookieOptions, maxAge: 0, }); - const existingSetCookie = [res.getHeader("set-cookie") || []].flat(); + const existingSetCookie = flat([res.getHeader("set-cookie") || []]); res.setHeader("set-cookie", [...existingSetCookie, cookieValue]); }, }; diff --git a/package.json b/package.json index 2ac220da..17b8bdd5 100644 --- a/package.json +++ b/package.json @@ -32,9 +32,7 @@ { "targets": { "node": "10" - }, - "useBuiltIns": "usage", - "corejs": 3 + } } ] ] @@ -81,6 +79,7 @@ ] }, "dependencies": { + "array.prototype.flat": "^1.2.3", "clone": "^2.1.2", "cookie": "^0.4.1", "debug": "^4.1.1",