admin管理员组

文章数量:1188827

Trying to persist user login using cookies but it just won't work.

I am developing an application in NextJS 14.2.23 and I am using zustand for state management. When the user logs in, I authenticate using my backend and get a token in response. This token is encrypted and stored in cookies. I was using Next 12 earlier and when the user would refresh the page, I would use getInitialProps to get the cookie and gather the user data from backend using the token in the cookie. I recently upgraded to NextJS 14 and tried to the same using layout.tsx async function. The data is fetched on the server side during the initial load but when I try to persist the same in the zustand store, it does not behave the way I expect it to.

Can someone guide me what would be the best approach to persist the user login in the given scenario?

本文标签: typescriptPersist sessions in Next JS 14 using cookiesStack Overflow