NextJS 未定义 localStorage

Art*_*hur 5 html javascript local-storage reactjs next.js

我想使用 来获取数据getInitialProps。我用的是isomorphic-unfetchlib.

import fetch from 'isomorphic-unfetch'

...My Component Page...

Component.getInitialProps = async () => {
  const res = await fetch(<path>, {method: 'GET', headers: {
    'Authorization': `bearer ${typeof Storage !== 'undefined' && localStorage.getItem('my_token')}`,
  }})
  const data = await res.data
  return {stuff: data}
}
Run Code Online (Sandbox Code Playgroud)

它在客户端准确运行,但在服务器端返回 401。我认为问题出在本地存储上。无法从服务器访问 LocalStorage。据我了解,我需要等到页面安装完毕。如何解决这个问题呢?

补充问题,我可以用 theaxios代替 吗isomophic-unfetch