最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How im get cookies on a Server side component in Next.js 13 - Stack Overflow

programmeradmin5浏览0评论
import axios from "axios";

const Api = axios.create({
  baseURL: "http://127.0.0.1:5000",
});

axios.defaults.headersmon["Authorization"] = cookie; 

document.cookie doesn't work in server side.

Some way to get cookie or passing cookies by props

import axios from "axios";

const Api = axios.create({
  baseURL: "http://127.0.0.1:5000",
});

axios.defaults.headers.mon["Authorization"] = cookie; 

document.cookie doesn't work in server side.

Some way to get cookie or passing cookies by props

Share Improve this question edited May 12, 2023 at 16:55 José Lisboa asked May 12, 2023 at 16:42 José LisboaJosé Lisboa 1091 silver badge8 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

I found a simple way to do it in Server Components with cookies from next:

import { cookies } from "next/headers";

const myCookie = cookies().get("cookieName").value;
发布评论

评论列表(0)

  1. 暂无评论