redux-react-session 如何在刷新时使用户信息进入状态 [英] redux-react-session how to get user info into state on refresh

查看:56
本文介绍了redux-react-session 如何在刷新时使用户信息进入状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚反应过来.我正在尝试登录,因为我使用了 npm 中的 redux-react-session 包来存储会话.

I new to react. I am trying to do login for that i used redux-react-session package from npm to store sessions.

我能够根据登录存储会话和授权路由.但是当我刷新页面时,我想将用户会话恢复到状态.

I am able to store session and autherise routes based on login. But when i refresh page i want to restore user session into state.

根据 redux-react-session 的文档,我们可以使用sessionService.loadUser() 方法让用户返回.

As per document of redux-react-session we can user sessionService.loadUser() method to get user back.

此函数返回承诺作为响应.但我无法获得 excat 用户对象.它作为一个承诺返回用户.

This function return promise in response. But i am not able to get excat user object. Its returing user as a promise.

我在上面花了将近 10 个小时.

i have spend almost 10 hrs on it.

有人可以帮忙吗?

推荐答案

很难理解您的代码出了什么问题.你能以某种方式分享吗?你确定你在创建商店后调用这行代码吗?

It is hard to understand what is going wrong with your code. Can you share it somehow? Are you sure you call this line of code after store creation?

sessionService.initSessionService(store);

最后你可以自己实现这样的逻辑.登录后,将数据放入localStorage.创建 store 后,从 localStorage 中获取数据并将其放入您的 store 中.这是非常简单的逻辑.

And finally you can implement such logic by yourself. After login, put data to the localStorage. After store creation, get data from the localStorage and put it in your store. It is pretty easy logic.

这篇关于redux-react-session 如何在刷新时使用户信息进入状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆