Giter VIP home page Giter VIP logo

next-client-cookies's People

Stargazers

Raisan avatar  avatar Ryo avatar Jacob Beard avatar  avatar EinsLucaaa avatar  avatar Ramy Chu avatar Hams Kuveluka avatar Ricardo Monteiro avatar Lucas Palma avatar Victor Ferreira Tavares avatar Kerwan avatar Uvindu Pathirana avatar Mateusz avatar António Duarte avatar Zoha avatar Rais Azaria Aryaguna  avatar Sergey Monin avatar yiminghe avatar Volk avatar Wésley Guimarães avatar Massahoud avatar  avatar José Barros avatar Oskar Krämer avatar Nobuhito Kurose avatar Grigory Morgachev avatar Philippe Fanaro avatar Franco Carrara avatar Kirill avatar Mauro Stepanoski avatar Grant Burry avatar  avatar Ramazan Yamac avatar BoBeenLee avatar Kyle G avatar David Barrat avatar  avatar Brock Herion avatar Lid Force avatar Vo Phu Phat avatar Ben Petty avatar  avatar Thomas Lekanger avatar Daniel Sandiego avatar Doug Steinberg avatar Jeremy Möglich avatar Vinicius Matos avatar Ali Farooq avatar !!rwd avatar Zlatko Fedor avatar Lenz Weber-Tronic avatar Junaid Faryad avatar Hudson Newey avatar Jeongjin Oh avatar Tim Mikeladze avatar AZ Software avatar Alden Quimby avatar Kadir Selki avatar Migliorelli avatar Tejas Sharma avatar Sibelius Seraphini avatar Maciej Fidler avatar Nathan Hughes avatar Mordechai Meisels avatar Josh avatar  avatar akshay kadam (a2k) avatar Rasul Nuriyev avatar Matheus Verissimo avatar YV avatar Amirreza Farzan avatar 张晓刚 avatar MazDel avatar taro avatar  avatar  avatar Sungmin Cho avatar Pedro avatar Nicholas Y. avatar  avatar keric avatar Eray Dereagzi avatar Lon Beshiri avatar David Fava avatar Luke Doig avatar Abdullah Al Noman avatar Atsushi Kitamura avatar Yaun avatar Eran Hirsch avatar Laurin avatar Erdem Arslan avatar shr4pnel avatar Shogo Nagasaka avatar SND avatar Ben Einwechter avatar João Pedro Magalhães avatar Ryusei avatar Maciej Podsiedlak avatar

Watchers

Moshe Simantov avatar

next-client-cookies's Issues

Error: Hydration failed because the initial UI does not match what was rendered on the server

I believe I followed all instructions correctly, but the cookie data is undefined by the time my component renders on the client. Here's a quick overview of what I'm doing. I'm using the App router, and I have a cookie that get sets through an API route on a sign in page. Then I go back to the Home page of the site and I'm wanting to check the cookie to see if it's expired from my Navbar component. As I'm sure you guessed, I'm going to use the active cookie as a flag for whether the user is logged in or not, then update the UI as needed (ex., the Navbar will show "Sign In" if the cookie is expired).

In the Navbar component, I'm attempting to inject the cookie data into the jsx just so I can see it's there, much like your example in the Github instructions. When the page loads, for a split second I see the cookie appear, then it disappears and an error is displayed, which I'll show in a moment. Also, through logging I can see that the cookie is getting retrieved server side, it's showing in the terminal, but it's not getting retrieved client side, as it's undefined in the browser console.

The cookie is getting retrieved at least on the server, so I know something's working. I'm new to NextJS development, so I'm not understanding what's going wrong here. Here's the error getting displayed:

Unhandled Runtime Error
Error: Hydration failed because the initial UI does not match what was rendered on the server.

Warning: Did not expect server HTML to contain the text node "eifjlspapeIEFhjfiels9eksghels3ahhnilk.eyJzZXNzaW9uVG9rZW4iOiJyOjllYmQ5OGM1YjAxZDhiMWZjNTc4ODczNzAxMWVkM2NkIiwiaWF0IjoxNjk4ODU1NTc4LCJleHAiOjE2OTg4NTYxNzh9.se8x2ovczG_0tA9nujZrxX7puE5UokTsyTH_aIx-_JE" in <div>.

See more info here: https://nextjs.org/docs/messages/react-hydration-error

Component Stack
div
div
nav
Navbar
./app/components/Navbar.tsx (18:84)
main

Nextjs cookies vs Yours

Nextjs cookies I am using it to set on my SSR post and getting it with yours but your cookies cannot get that native cookies setted but get another setted ones

TypeScript issue

Hi, I'm getting this TypeScript error when importing the server part:

image

Linter doesn't complain when imported from next-client-cookies/dist/server, but that'll break the runtime.

Bit weird, since you are using TypeScript here and have things properly typed. Probably some sort of a misconfiguration here or on my end..

Here's my tsconfig.json:

{
  "compilerOptions": {
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "incremental": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "baseUrl": ".",
    "paths": {
      "@/*": ["./*"]
    },
    "plugins": [
      {
        "name": "next"
      }
    ],
    "strictNullChecks": true
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "constants.mjs"],
  "exclude": ["node_modules"]
}

Error: It's currently unsupported to use "export *" in a client boundary. Please use named exports instead.

I have a React hook where there is also query getter defined for an axios call. E.g.

import { useQuery } from '@tanstack/react-query';
import { useCookies } from 'next-client-cookies';

export async function fetchTasks(cookies): Promise<object[]> {
  try {
    const tasks =
      (await axios.get({ headers: { cookies }, url: '/api/tasks'))?.data || [];
    return tasks;
  } catch (err) {
    console.error({ error: err }, 'Failed to fetch onboarding tasks');
    return [];
  }
}

export function useTasks() {
  const cookies = useCookies();
  return useQuery(() => fetchTasks(cookies));
}

The import { useCookies } from 'next-client-cookies'; import statement causes application to crush with:

Failed to compile
./node_modules/next-client-cookies/dist/index.mjs
Error: It's currently unsupported to use "export *" in a client boundary. Please use named exports instead.
This error occurred during the build process and can only be dismissed by fixing the error.

cookies() expects to have requestAsyncStorage, none available.

I'm not sure if my usage is incorrect or not but my error is following:

Collecting page data ...Error: Invariant: cookies() expects to have requestAsyncStorage, none available. at cookies (webpack-internal:///2491:50:15) at getCookies (webpack-internal:///9491:22:36) at eval (webpack-internal:///573:16:96) at 573 (C:\Users\Alex\Desktop\GitHub\Frontend\.next\server\app\Dashboard\page.js:1:262747) at __webpack_require__ (C:\Users\Alex\Desktop\GitHub\Frontend\.next\server\webpack-runtime.js:1:146) at eval (webpack-internal:///877:57:17)

Here's my code:

"use server"
...
import { getCookies } from 'next-client-cookies/server'

const Dashboard = async () => {

const cookies = getCookies();

const userData = JSON.parse(cookies.get('userData'));

...

return(
    ...
    )
} 

export default Dashboard;

update import <CookiesProvider>

update the CookiesProvider import, the default import in VSCode is as follows:

import { CookiesProvider } from "next-client-cookies";

and the import is considered deprecated. The readme says that you should specify
import { CookiesProvider } from "next-client-cookies/server";

it took me a long time to figure out why the console was constantly displaying

⨯ node_modules\next-client-cookies\dist\hook.js (44:0) @ eval
 ⨯ Error: Missing <CookiesProvider>
    at CreateUserPage (./src/app/admin/create-user/page.tsx:67:84)
null

Because of my inattention in the readme, I didn't understand what caused the error.

Document that CookieProvider bails out the route segment from static generation

I noticed while building my application that the entire app now opted out of static generation.
After debugging the problem I concluded the cause to be wrapping the root layout with <CookieProvider>.

In my case, I only needed client cookies on a single page, so wrapping the root was an overkill.

I think it would be beneficial to document this.

Error: Missing <CookiesProvider>

Hi Moshest, thanks for your awesome package, i have a wired error in my nextjs 14 logs and the package is working perfectly and i can see the cookie in client side but i have this error in my server side:

⨯ node_modules\next-client-cookies\dist\hook.js (44:12) @ eval
 ⨯ Error: Missing <CookiesProvider>
    at Form_handler (./app/components/ai/form_handler.tsx:21:84)

here is my code:

"use client";

import { useCookies } from 'next-client-cookies';


export function Form_handler() {
  const cookies = useCookies();
  const my_token = cookies.get('token')
  console.log(my_token)


  


  return (
    <section className="flex justify-center">
      <div>nothing</div>
    </section>
  );
}

export default Form_handler;

Cannot be used with Next.js canary releases

There's a dependency resolution error when trying to use this library with Next.js canary:

npm ERR! code ERESOLVE
--
22:37:29.375 | npm ERR! ERESOLVE could not resolve
22:37:29.375 | npm ERR!
22:37:29.376 | npm ERR! While resolving: [email protected]
22:37:29.376 | npm ERR! Found: [email protected]
22:37:29.376 | npm ERR! node_modules/next
22:37:29.376 | npm ERR!   next@"^14.1.1-canary.0" from the root project
22:37:29.376 | npm ERR!
22:37:29.376 | npm ERR! Could not resolve dependency:
22:37:29.376 | npm ERR! peer next@">= 13.0.0" from [email protected]
22:37:29.376 | npm ERR! node_modules/next-client-cookies
22:37:29.376 | npm ERR!   next-client-cookies@"^1.1.0" from the root project
22:37:29.376 | npm ERR!
22:37:29.376 | npm ERR! Conflicting peer dependency: [email protected]
22:37:29.377 | npm ERR! node_modules/next
22:37:29.377 | npm ERR!   peer next@">= 13.0.0" from [email protected]
22:37:29.377 | npm ERR!   node_modules/next-client-cookies
22:37:29.377 | npm ERR!     next-client-cookies@"^1.1.0" from the root project
22:37:29.377 | npm ERR!
22:37:29.377 | npm ERR! Fix the upstream dependency conflict, or retry
22:37:29.377 | npm ERR! this command with --force or --legacy-peer-deps
22:37:29.377 | npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

I currently use --legacy-peer-deps, but this only works locally, not when deploying to Vercel (where I can't set this flag)

httpOnly flag

Hi
i have a question why on set method options there is not option for httpOnly? the nextjs cookies has it

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.