Hendrixer / fullstack-app-v2-app

fullstack-app-v2-app.vercel.app
67 stars 31 forks source link

TypeError: cookies.get is not a function - getUserFromCookie #13

Closed kal93 closed 1 year ago

kal93 commented 1 year ago

Getting this error

TypeError: cks.get is not a function at getUserFromCookie (webpack-internal:///(sc_server)/./lib/auth.ts:37:21) at getData (webpack-internal:///(sc_server)/./components/Greetings.tsx:19:87) at Greetings (webpack-internal:///(sc_server)/./components/Greetings.tsx:24:24)

// Auth.ts
export const getUserFromCookie = async (cookies) => {
  const jwt = cookies.get(process.env.COOKIE_NAME);

  const { id } = await validateJWT(jwt.value);

  const user = await db.user.findUnique({
    where: {
      id: id as string,
    },
  });

  return user;
};

package.json


    "@next/font": "13.1",
    "@prisma/client": "4.6.1",
    "@types/node": "20.2.1",
    "@types/react": "18.2.6",
    "@types/react-dom": "18.2.4",
    "bcrypt": "^5.1.0",
    "class-variance-authority": "0.4.0",
    "clsx": "1.2.1",
    "cookie": "0.5.0",
    "css-reset-and-normalize": "2.3.6",
    "eslint": "8.40.0",
    "eslint-config-next": "13.4.3",
    "jose": "^4.11.1",
    "next": "13.1",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-feather": "2.0.10",
    "typescript": "5.0.4"
  },
  "devDependencies": {
    "@types/bcrypt": "^5.0.0",
    "@types/cookie": "^0.5.1",
    "autoprefixer": "^10.4.14",
    "postcss": "^8.4.23",
    "prisma": "4.6.1",
    "tailwindcss": "^3.2.4",
    "ts-node": "10.9.1",
    "tsconfig-paths": "4.1.1"
  } ```
kal93 commented 1 year ago

Ahh, I missed invoking the cookies() in Greeting.tsx.

https://nextjs.org/docs/app/api-reference/functions/cookies