1

I'm using nextjs and I want to use the cookie to share some data on multiple devices. when I set data in cookies on current devices, and check on another device, I see that data doesn't exist.

in _app.js

import { CookiesProvider } from "react-cookie"

<CookiesProvider>
          <UserProvider>
            <CartProvider>
              <Layout
              >
                <Component {...pageProps} />
              </Layout>
            </CartProvider>
          </UserProvider>
        </CookiesProvider>

in cartProvider

import { useCookies } from "react-cookie";


export default function CartProvider({ children }: Props) {
  const [cookies, setCookie, removeCookie] = useCookies([
    "cart_token",
    "token",
  ]);
  useEffect(()=>{
  API.get(`cart/show/${temp_token ? temp_token : ""}`)
              .then((res) => {
                setCookie("cart_token", res.data.data.cart_token, {
                  path: "/",
                  maxAge: 3600 * 24 * 360,
                  sameSite: true,
                });
                })
  },[])
  }
  

But when I check cookie on another device, I cant see cart_token in the cookie

amin71
  • 29
  • 3

1 Answers1

0

To add to @juliomalves comment, in your case, you would need to store the cart items in your backend and then in a new device, fetch it back when the same user logs in

RGog
  • 96
  • 12