onSubmit> userAction.login>发送“SUCCESS_AUTHENTICATE”>在reducers中设置用户和套接字状态的标记> ?????那我怎么能让socket.emit(“authenticate”,{token})发生呢?
答案 0 :(得分:0)
简单地编写一个简短的中间件,工作得很好。
const socketAuthenticator = (store) => (next) => (action) =>{
if(action.type === "AUTHENTICATION_FULFILLED" || action.type === "REGISTRATION_FULFILLED") {
const token = action.payload.token;
const socket = store.getState().socket.socket
socket.emit('authenticate', { token })
}
next(action)
}