Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const mapStateToProps = state => {
- return {
- profile: state.profileReducer.profile
- }
- }
- const mapDispatchToProps = dispatch => {
- return {
- dispatch: action => {
- dispatch(action)
- }
- }
- }
- ...
- handleConnection = () => {
- const { profile } = this.props
- this.props.dispatch({ type: 'CONNECT_USER' })
- }
- ...
- export default connect(mapStateToProps, mapDispatchToProps)(LoginPage)
- import io from 'socket.io-client'
- const host = [SERVER_URL]
- const socketConnection = io.connect(host, {path: [PATH], secure: true})
- const initialState = {
- profile: {
- token: null,
- username: '',
- password: ''
- }
- }
- function profileReducer(state = initialState, action) {
- switch(action.type) {
- ...
- case 'CONNECT_USER':
- let tempProfile = {...state.profile}
- socketConnection.emit('login', tempProfile.username + ';' + tempProfile.password)
- socketConnection.on('check', msg => {
- if (msg !== null && msg !== '')
- tempProfile.token = msg
- return {
- ...state,
- profile: tempProfile
- }
- })
- return state
- ...
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement