Open nickzym opened 6 years ago
you can add your token on url query .and then node can get token .
我上面写的代码的意思是,在我渲染首页的时候,可以通过localStorage获取登录过的token。但是服务端渲染的话,无法在node renderToString的时候,得到locaStorage存的东西啊。
你可以把token 放到cookie 里面,ssr服务的根域名和 你认证权限的根域名要保持一直。 通过设置cookie 的domain属性 去控制根域名下子域名之间的cookie共享 具体参见https://developer.mozilla.org/zh-CN/docs/Web/API/Document/cookie 。 有服务端数据共享的需求用locaStorage 就不能满足了。😕
感谢您的建议,我现在就是用cookie没用localstorage。
🙂
I use token to authenticate users. It just like the following code
But localStorage is not available in node environment where inside renderToString function.
Any possible solution for this?