wasowasowaso

This commit is contained in:
2023-07-26 18:11:25 +02:00
parent 284171c7e9
commit f90db54fc1
13 changed files with 442 additions and 85 deletions
+21
View File
@@ -0,0 +1,21 @@
import { serialize, CookieSerializeOptions } from 'cookie';
import { NextApiResponse } from 'next'
/**
* This sets `cookie` using the `res` object
*/
export const setCookie = (
res: NextApiResponse,
name: string,
value: unknown,
options: CookieSerializeOptions = {}
) => {
const stringValue =
typeof value === 'object' ? 'j:' + JSON.stringify(value) : String(value)
if (typeof options.maxAge === 'number') {
options.expires = new Date(Date.now() + options.maxAge * 1000)
}
res.setHeader('Set-Cookie', serialize(name, stringValue, options))
}