【问题标题】:How to access cookies from the server in Next.js [duplicate]如何在 Next.js 中从服务器访问 cookie
【发布时间】:2021-08-18 16:32:47
【问题描述】:

在 Next.js 中呈现页面之前,我需要从服务器端访问 cookie 以获取令牌

【问题讨论】:

标签: reactjs cookies next.js


【解决方案1】:

类风格

class SomePage extends Component {
    static async getInitialProps(ctx) {
        console.log(ctx.req.headers.cookie)
    }

render() {
    return (
        <SomePageComponent />
   )}}

功能样式

const SomePage = () => { return (<SomePage />) }

SomePage.getInitialProps = async (ctx) => { console.log(ctx.req.headers.cookie) }

【讨论】:

  • 这好像是TypeScript,如何在JS中实现
  • 纯 JavaScript)
  • 扩展答案
猜你喜欢
  • 2022-11-14
  • 1970-01-01
  • 2021-11-02
  • 1970-01-01
  • 1970-01-01
  • 2022-08-16
  • 2017-05-28
  • 2021-03-17
  • 2021-09-26
相关资源
最近更新 更多