get Shopify Cookies
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
ShopifyCookies
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.
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} />; }