Closed mean-cj closed 4 years ago
Hi @mean-cj, that is not supported, you have to pass the options object when you call it directly with set
, get
and remove
. The only supported options keys are alias
and parseJSON
.
This is untested, but I guess you could remap it with the cookie-universal
library by creating a plugin yourself manually, instead of using the wrapper library which is cookie-universal-nuxt
. For example:
import cookieUniversal from "cookie-universal";
export default ({ req, res }, inject) => {
const aliasName = 'cookies'
const parseJsonbyDefault = true
const myOptions = {
path: "/",
expires: new Date(Date.now() + 604800), // 7day
// maxAge : ,
// httpOnly : null,
domain: ".domain.com",
// encode : ()=>{},
sameSite: null,
secure: true
};
const cookieLib = cookieUniversal(req, res, parseJsonbyDefault);
const cookieLibWithDefaults = {
get: (name, optsOverride = {}) =>
cookieLib.get(name, { ...myOptions, ...optsOverride }),
set: (name, value, optsOverride = {}) =>
cookieLib.set(name, value, { ...myOptions, ...optsOverride }),
remove: (name, optsOverride = {}) =>
cookieLib.set(name, { ...myOptions, ...optsOverride })
};
inject(aliasName, cookieLibWithDefaults);
};
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Hello
How i can set default option for cookie-universal-nuxt ,
this not work for me
thank you.