skip to Main Content

I’m trying to check weather a specific cookie exist and delete some data from redux if it doesn’t, but I’m not able to get the cookies even after using a package called ‘cookies-next’.

I’m using client side component in order to mutate the state in redux. Anyone knows how to get cookies in client side with or without a package?

2

Answers


  1. Chosen as BEST ANSWER

    I got the answer that httpOnly cookie can't be accessed using javascript.

    If anyone knows any way around to delete data from redux when a cookie is removed, please help.


  2. Using cookies-next package

    import { getCookie } from 'cookies-next';
    const cookieValue = getCookie('cookie_name');
    

    Without any package

    const cookieValue = document.cookie.split('; ')
      .find(row => row.startsWith('cookieName='))
      ?.split('=')[1];
    

    You can access cookies using document.cookie.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search