Parses cookie string and returns Shopify cookies.
import * as React from 'react';
import {useEffect} from 'react';
import {getShopifyCookies} from '@shopify/hydrogen-react';
export default function App({Component, pageProps}) {
useEffect(() => {
getShopifyCookies(document.cookie);
});
return <Component {...pageProps} />;
}
import * as React from 'react';
import {useEffect} from 'react';
import {getShopifyCookies} from '@shopify/hydrogen-react';
export default function App({Component, pageProps}) {
useEffect(() => {
getShopifyCookies(document.cookie);
});
return <Component {...pageProps} />;
}
If the Shopify cookies doesn't exist, this method will return empty string for each missing cookie.
cookies: string
export function getShopifyCookies(cookies: string): ShopifyCookies { const cookieData = parse(cookies); return { [SHOPIFY_Y]: cookieData[SHOPIFY_Y] || '', [SHOPIFY_S]: cookieData[SHOPIFY_S] || '', }; }
Shopify session token: Value of `_shopify_s` cookie.
Shopify unique user token: Value of `_shopify_y` cookie.
Shopify cookies names
Shopify session token: Value of `_shopify_s` cookie.
Shopify unique user token: Value of `_shopify_y` cookie.