在fluxible中,如何在页面刷新时在用户存储中保持登录会话信息

时间:2016-08-11 13:39:19

标签: javascript reactjs-flux fluxible

我无法在页面刷新时使用fluxible将经过身份验证的会话持久保存到UserStore。在我的情况下,我在登录时更新用户存储,一切都很好,因为他们点击页面 - 但如果他们刷新页面 - 它失去了用户状态 - 我看到水合物/再水化不是在页面刷新触发 - 在那种情况下应该在用户存储上触发吗?

在这种情况下,我应该如何向用户区初始化/注入服务器端req.session,以便在浏览器刷新时使用正确的登录用户状态加载用户区?

class UserStore extends BaseStore {

    constructor(dispatcher) {
        super(dispatcher);
        this.reset();
        this.userInfo = {
            emailPreferences: {}
        };
        this.registrationState = {
            isLoading: false
        };
        this.resetPasswordState = {};
        this.userAddressInfo = {
            isLoading: false,
            addNew: false
        };

    }


    reset() {
        // this.loginState = {};
        console.log('resetting user');
        console.log(this.loginState);
        this.loginState = {
            loginStatus: false,
            isLoading: false,
            errorMessage: ''
        };

        this.currentUser = null;
        this.registrationStatus = REQUEST_STATUS.NONE;
        this.registrationErrorMessage = null;
        this.resetPasswordState = {};
        this.loginState.loginStatus = false;

        this.profile = null;
        this.getProfileStatus = REQUEST_STATUS.NONE;
        this.getProfileErrorMessage = null;
    }
}

在client.js

const dehydratedState = window.App; // Sent from the server

window.React = ReactDOM; // For chrome dev tool support

// expose debug object to browser, so that it can be enabled/disabled from browser:
// https://github.com/visionmedia/debug#browser-support
window.fluxibleDebug = debug;

debugClient('rehydrating app');

// pass in the dehydrated server state from server.js
app.rehydrate(dehydratedState, (err, context) => {
    if (err) {
        throw err;
    }
    window.context = context;
    const mountNode = document.getElementById('app');

    debugClient('React Rendering');
    ReactDOM.render(
        createElementWithContext(context),
        mountNode,
        () => debugClient('React Rendered')
    );
});

我应该以某种方式在client.js中触发usertore / state的补液吗?

0 个答案:

没有答案