0

I use NextJs and make several pages with SSR(server-side rendering) I have to send the userId to the server

At first, I realized I had to use a cookie

npm i js-cookie

but I use Redux-Saga and I call API in Redux Action For sending Cookie into Redux Action from the SSR page I use this code

export const getServerSideProps = wrapper.getServerSideProps(
  async ({ store, query, req }) => {
let cookie = req.headers.cookie;
store.dispatch(loadProductDetailData(`${id}`,cookie));
})

for export deviceId from the cookie, I make this function

export const getCookie = (cookie: string, key: string) => {
let value = ''
cookie.split(';').forEach((e) => {
    if (e.includes(key)) {
        value = e.split('=')[1]
    }
})
return value

}

I call this function

getCookie(cookie,'deviceId')

0 Answers0