Here what you're doing is taking two arguments then put them into a single object, which is when it makes sense to take that object from the beginning as one parameter
const createCookie = (otps) => {
const token = sign(opts, process.env.SECRET);
return token;
};
we can do validation here like
const createCookie = (otps) => {
if (!opts.userId) throw new Error('missing user id in cookie input') // or whatever error message you feel makes sense to you
const token = sign(opts, process.env.SECRET);
return token;
};
validation is always good, in your original function, you could forget to enter a value and the function will not tell you anything.
posts-project/src/utillity/createCookies.js
Line 4 in 543acb9
Here what you're doing is taking two arguments then put them into a single object, which is when it makes sense to take that object from the beginning as one parameter
we can do validation here like
validation is always good, in your original function, you could forget to enter a value and the function will not tell you anything.