mirror of
https://github.com/vercel/commerce.git
synced 2025-07-24 02:31:24 +00:00
assets
components
config
lib
bigcommerce
api
cart
catalog
definitions
fragments
operations
utils
create-api-handler.ts
errors.ts
fetch-graphql-api.ts
fetch-store-api.ts
filter-edges.ts
get-cart-cookie.ts
is-allowed-method.ts
parse-item.ts
types.ts
checkout.ts
customers.ts
index.ts
cart
products
scripts
index.tsx
schema.d.ts
schema.graphql
use-price.tsx
commerce
to-pixels.ts
pages
public
utils
.gitignore
.prettierignore
README.md
codegen.json
global.d.ts
next-env.d.ts
next.config.js
package.json
postcss.config.js
tailwind.config.js
tsconfig.json
yarn.lock
21 lines
526 B
TypeScript
21 lines
526 B
TypeScript
import { serialize, CookieSerializeOptions } from 'cookie'
|
|
|
|
export default function getCartCookie(
|
|
name: string,
|
|
cartId?: string,
|
|
maxAge?: number
|
|
) {
|
|
const options: CookieSerializeOptions =
|
|
cartId && maxAge
|
|
? {
|
|
maxAge,
|
|
expires: new Date(Date.now() + maxAge * 1000),
|
|
secure: process.env.NODE_ENV === 'production',
|
|
path: '/',
|
|
sameSite: 'lax',
|
|
}
|
|
: { maxAge: -1, path: '/' } // Removes the cookie
|
|
|
|
return serialize(name, cartId || '', options)
|
|
}
|