Skip to content

Instantly share code, notes, and snippets.

@jermsam
Created May 9, 2018 11:59
Show Gist options
  • Save jermsam/c0ace9911b2221d8ae2bb1b354ad4f2e to your computer and use it in GitHub Desktop.
Save jermsam/c0ace9911b2221d8ae2bb1b354ad4f2e to your computer and use it in GitHub Desktop.
login state stuck at SERVICES_AUTHENTICATION_AUTHENTICATE_PENDING when fed with correct credentials yet validates ok when fed invalid credentials
import { combineReducers } from 'redux';
import {reducer as formReducer} from 'redux-form'
// import sessionReducer from './session';
import {session,services} from './services';
// Configure reducers
const reducers ={
sessionState: session.reducer,
userState:services.users.reducer,
authManagementState: services.authManagement.reducer,
// postState:services.users.reducer,
// commentState:services.users.reducer,
form:formReducer
}
// combine reducers
const rootReducer = combineReducers(reducers)
export default rootReducer;
import reduxifyServices ,{ getServicesStatus as getStatus } from 'feathers-redux';
import reduxifyAuthentication from 'feathers-reduxify-authentication';
// well Configured and authenticated feathers-client
import app from './app'
// Reduxify feathers-client.authentication
const session = reduxifyAuthentication(app,
{ isUserAuthorized: (user) => user.isVerified } // WE INSIST USER IS 'verified' TO AUTHENTICATE
);
/**
// Sign in with the JWT currently in localStorage
if (localStorage['feathers-jwt']) {
store.dispatch(signin.authenticate()).catch(err => { ... });
}
// Sign in with credentials
store.dispatch(signin.authenticate({ type: 'local', email, password }))
.then(() => { ... )
.catch(err => { ... });
*/
const services = reduxifyServices(app, ['users','authManagement']);
/**
* // email addr verification with long token
// Feathers is now 100% compatible with Redux. Use just like [Feathers method calls.](#methods)
store.dispatch(services.authManagement.create({ action: 'verifySignupLong',
value: verifyToken,
}, {})
);
*/
export{
session,
services,
getStatus
}
import React,{Component} from 'react'
import PropTypes from 'prop-types'
import { compose } from 'recompose'
import {connect} from 'react-redux'
import {
withRouter,
} from 'react-router-dom';
import {
Divider, Message,Container
} from 'semantic-ui-react';
import {session} from '../services';
import PublicLayout from "./frames/PublicLayout";
import NearBottom from "./navs/NearBottom";
import Next2Footer from "./navs/Next2Footer";
import './css/nav.css'
import SigninForm from './forms/SigninForm'
class SigninPageUI extends Component{
onSubmit= (user) => {
const {history:{push},onLogin,authUser } = this.props;
console.log("PPPPPP: ",user);
onLogin(user)
.then(res=>console.log('KKKKK: ',res))
.then(()=> push(`/profile/${authUser.id}`))
.catch(() => {
console.log("PPPPPP: ",this.props.errors);
});
}
render(){
const {user,loading,errors} = this.props
const errs =(errors)? errors.message.split(","):'';
return(
<PublicLayout
className="register"
url1="/" link1="Home"
url2="/signup" link2="Sign up"
url3="/htw" link3="How It Works"
>
<Divider section hidden/>
{errors &&
<Container text textAlign='justified'>
<Message
error
header='There are some errors with your submission'
list={errs.map(e=>e)}
/>
</Container>
}
<Divider hidden />
<Divider hidden />
<SigninForm
user={user}
onSubmit={this.onSubmit}
errors={errors}
loading={loading}
/>
<NearBottom/>
<Next2Footer/>
</PublicLayout>
);
}
}
SigninPageUI.propTypes={
user:PropTypes.shape({}).isRequired,
loading:PropTypes.bool,
errors:PropTypes.shape({}),
history:PropTypes.shape({
push:PropTypes.func.isRequired
}).isRequired,
onLogin:PropTypes.func.isRequired,
// onSyncWithLocalState:PropTypes.func.isRequired,
authUser:PropTypes.shape({}),
}
SigninPageUI.defaultProps={
authUser:{},
errors:{},
loading:false
}
/**
* To use connect(), you need to define a special function called mapStateToProps
* that tells how to transform the current Redux store state into the props you want
* to pass to a presentational component you are wrapping.
*/
const mapStateToProps =(state) =>({
user: state.userState.data || {},
authUser:state.sessionState.user,
errors: state.sessionState.isError ,
loading:state.sessionState.isLoading
})
/**
* In addition to reading the state, container components can dispatch actions.
* In a similar fashion, you can define a function called mapDispatchToProps() that receives the dispatch() method
* and returns callback props that you want to inject into the presentational component.
*/
// SERVICES_MESSAGES_FIND
const mapDispatchToProps = (dispatch) => ({
// Sign in with credentials
onLogin: (user) =>dispatch(session.authenticate({ type: 'local', ...user})),
// Sign in with the JWT currently in localStorage
onSyncWithLocalState: ()=>dispatch(session.authenticate())
});
const SigninPage=compose(
withRouter,
connect(
mapStateToProps,
mapDispatchToProps
),
)(SigninPageUI)
export default SigninPage;
@jermsam
Copy link
Author

jermsam commented May 9, 2018

Actually for it to work as described in the description, had to change:
// Sign in with credentials
onLogin: (user) =>dispatch(session.authenticate({ type: 'local', ...user})),
to
// Sign in with credentials
onLogin: (user) =>dispatch(session.authenticate({ strategy: 'local', ...user})),
otherwise it could not even validate with invalid credentials fed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment