From 9c40ee1245512e14ce4920adc84c3cd09e14c3d9 Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Fri, 20 Jan 2017 19:35:31 -0300 Subject: [PATCH] Login sign In back on! :tada: --- client/coral-embed-stream/src/Embed.js | 15 +++++--------- .../src/graphql/queries/streamQuery.graphql | 4 ---- client/coral-framework/actions/auth.js | 20 ++++++++----------- .../containers/SignInContainer.js | 7 +------ 4 files changed, 14 insertions(+), 32 deletions(-) diff --git a/client/coral-embed-stream/src/Embed.js b/client/coral-embed-stream/src/Embed.js index 87da4271c..0231ad1b8 100644 --- a/client/coral-embed-stream/src/Embed.js +++ b/client/coral-embed-stream/src/Embed.js @@ -97,17 +97,16 @@ class Embed extends Component { } render () { - console.log(this.props) // const rootItemId = this.props.items.assets && Object.keys(this.props.items.assets)[0]; // const rootItem = this.props.items.assets && this.props.items.assets[rootItemId]; // const {actions, users, comments} = this.props.items; - const {isAdmin, showSignInDialog, loggedIn} = this.props.auth; + const {loggedIn, isAdmin, user, showSignInDialog, signInOffset} = this.props.auth; const {activeTab} = this.state; // const banned = (this.props.userData.status === 'banned'); - const {loading, asset, currentUser, refetch} = this.props.data; + const {loading, asset, refetch} = this.props.data; // const {status, moderation, closedMessage, charCount, charCountEnable} = asset.settings; @@ -124,7 +123,7 @@ class Embed extends Component { Settings Configure Stream - {currentUser && } + {loggedIn && } { asset.closedAt === null @@ -144,17 +143,13 @@ class Embed extends Component { reply={false} currentUser={this.props.auth.user} banned={false} - author={currentUser} + author={user} charCount={asset.settings.charCountEnable && asset.settings.charCount}/> :

{asset.settings.closedMessage}

} - { - !currentUser && - } + {!loggedIn && } ({type: actions.CLEAN_STATE}); // Sign In Actions const signInRequest = () => ({type: actions.FETCH_SIGNIN_REQUEST}); - const signInSuccess = (user, isAdmin) => ({type: actions.FETCH_SIGNIN_SUCCESS, user, isAdmin}); const signInFailure = error => ({type: actions.FETCH_SIGNIN_FAILURE, error}); export const fetchSignIn = (formData) => (dispatch) => { dispatch(signInRequest()); - return coralApi('/auth/local', {method: 'POST', body: formData}) - .then((user) => { - + coralApi('/auth/local', {method: 'POST', body: formData}) + .then(({user}) => { const isAdmin = !!user.roles.filter(i => i === 'admin').length; dispatch(signInSuccess(user, isAdmin)); - - // dispatch(hideSignInDialog()); - - // dispatch(addItem(user, 'users')); + dispatch(hideSignInDialog()); + dispatch(addItem(user, 'users')); }) .catch(() => dispatch(signInFailure(lang.t('error.emailPasswordError')))); }; @@ -79,7 +75,7 @@ const signUpFailure = error => ({type: actions.FETCH_SIGNUP_FAILURE, error}); export const fetchSignUp = formData => (dispatch) => { dispatch(signUpRequest()); - return coralApi('/users', {method: 'POST', body: formData}) + coralApi('/users', {method: 'POST', body: formData}) .then(({user}) => { dispatch(signUpSuccess(user)); setTimeout(() =>{ @@ -99,7 +95,7 @@ const forgotPassowordFailure = () => ({type: actions.FETCH_FORGOT_PASSWORD_FAILU export const fetchForgotPassword = email => (dispatch) => { dispatch(forgotPassowordRequest(email)); - return coralApi('/account/password/reset', {method: 'POST', body: {email}}) + coralApi('/account/password/reset', {method: 'POST', body: {email}}) .then(() => dispatch(forgotPassowordSuccess())) .catch(error => dispatch(forgotPassowordFailure(error))); }; @@ -112,7 +108,7 @@ const logOutFailure = () => ({type: actions.LOGOUT_FAILURE}); export const logout = () => dispatch => { dispatch(logOutRequest()); - return coralApi('/auth', {method: 'DELETE'}) + coralApi('/auth', {method: 'DELETE'}) .then(() => dispatch(logOutSuccess())) .catch(error => dispatch(logOutFailure(error))); }; @@ -130,7 +126,7 @@ const checkLoginFailure = error => ({type: actions.CHECK_LOGIN_FAILURE, error}); export const checkLogin = () => dispatch => { dispatch(checkLoginRequest()); - return coralApi('/auth') + coralApi('/auth') .then((result) => { if (!result.user) { throw new Error('Not logged in'); diff --git a/client/coral-sign-in/containers/SignInContainer.js b/client/coral-sign-in/containers/SignInContainer.js index 9f97a14c7..07f82a849 100644 --- a/client/coral-sign-in/containers/SignInContainer.js +++ b/client/coral-sign-in/containers/SignInContainer.js @@ -121,12 +121,7 @@ class SignInContainer extends Component { handleSignIn(e) { e.preventDefault(); - this.props.fetchSignIn(this.state.formData) - - // Using refetch to get data after the user has logged in. - // This is the equivalent of a page reload, we may want to use a more speficic mustation here. - // Also, we may want to find a way for this logic to live elsewhere. - .then(() => this.props.refetch()); + this.props.fetchSignIn(this.state.formData); } handleClose() {