get Shopify Cookiesutility
utility
Parses cookie string and returns Shopify cookies.
If the Shopify cookies doesn't exist, this method will return empty string for each missing cookie.
Anchor to getShopifyCookies-parametersParameters
- stringrequired
- _shopify_sstring
Shopify session token: Value of
cookie.
- _shopify_ystring
Shopify unique user token: Value of
cookie.
ShopifyCookies
GetShopifyCookiesGeneratedType
- cookies
string
ShopifyCookies
export function getShopifyCookies(cookies: string): ShopifyCookies {
const cookieData = parse(cookies);
return {
[SHOPIFY_Y]: cookieData[SHOPIFY_Y] || '',
[SHOPIFY_S]: cookieData[SHOPIFY_S] || '',
};
}
ShopifyCookies
- _shopify_s
Shopify session token: Value of `_shopify_s` cookie.
string
- _shopify_y
Shopify unique user token: Value of `_shopify_y` cookie.
string
{
/** Shopify unique user token: Value of `_shopify_y` cookie. */
[SHOPIFY_Y]: string;
/** Shopify session token: Value of `_shopify_s` cookie. */
[SHOPIFY_S]: string;
}
Was this section helpful?
Shopify cookies names
- stringrequired
Shopify session token: Value of
cookie.
- stringrequired
Shopify unique user token: Value of
cookie.
ShopifyCookies
- _shopify_s
Shopify session token: Value of `_shopify_s` cookie.
string
- _shopify_y
Shopify unique user token: Value of `_shopify_y` cookie.
string
{
/** Shopify unique user token: Value of `_shopify_y` cookie. */
[SHOPIFY_Y]: string;
/** Shopify session token: Value of `_shopify_s` cookie. */
[SHOPIFY_S]: string;
}
Was this section helpful?
Example code
import * as React from 'react';
import {useEffect} from 'react';
import {getShopifyCookies} from '@shopify/hydrogen';
export default function App({Component, pageProps}) {
useEffect(() => {
getShopifyCookies(document.cookie);
});
return <Component {...pageProps} />;
}
examples
Example code
description
I am the default example
JavaScript
import * as React from 'react'; import {useEffect} from 'react'; import {getShopifyCookies} from '@shopify/hydrogen'; export default function App({Component, pageProps}) { useEffect(() => { getShopifyCookies(document.cookie); }); return <Component {...pageProps} />; }
TypeScript
import * as React from 'react'; import {useEffect} from 'react'; import {getShopifyCookies} from '@shopify/hydrogen'; export default function App({Component, pageProps}) { useEffect(() => { getShopifyCookies(document.cookie); }); return <Component {...pageProps} />; }