From fd79f3292308441596696f0d577f5b20fc6a17bf Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Thu, 14 Sep 2017 09:46:20 +0300 Subject: [PATCH] Ensure current user, add docs --- .../AuthenticationPage/AuthenticationPage.js | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/containers/AuthenticationPage/AuthenticationPage.js b/src/containers/AuthenticationPage/AuthenticationPage.js index 58663fca..0ffd899b 100644 --- a/src/containers/AuthenticationPage/AuthenticationPage.js +++ b/src/containers/AuthenticationPage/AuthenticationPage.js @@ -5,6 +5,7 @@ import { withRouter, Redirect } from 'react-router-dom'; import { FormattedMessage, injectIntl, intlShape } from 'react-intl'; import classNames from 'classnames'; import * as propTypes from '../../util/propTypes'; +import { ensureCurrentUser } from '../../util/data'; import { PageLayout, NamedLink, @@ -69,12 +70,19 @@ export const AuthenticationPageComponent = props => { const isLogin = tab === 'login'; const from = location.state && location.state.from ? location.state.from : null; - const showEmailVerification = !isLogin && currentUser && !currentUser.attributes.emailVerified; + const user = ensureCurrentUser(currentUser); + const currentUserLoaded = !!user.id; + + // We only want to show the email verification dialog in the signup + // tab if the user isn't being redirected somewhere else + // (i.e. `from` is present). We must also check the `emailVerified` + // flag only when the current user is fully loaded. + const showEmailVerification = !isLogin && currentUserLoaded && !user.attributes.emailVerified; // Already authenticated, redirect away from auth page if (isAuthenticated && from) { return ; - } else if (isAuthenticated && currentUser && !showEmailVerification) { + } else if (isAuthenticated && currentUserLoaded && !showEmailVerification) { return ; } @@ -144,13 +152,8 @@ export const AuthenticationPageComponent = props => { ); - const currentUserHasAttributes = currentUser && currentUser.attributes; - const name = currentUserHasAttributes && currentUser.attributes.profile - ? currentUser.attributes.profile.displayName - : ''; - const email = currentUserHasAttributes - ? {currentUser.attributes.email} - : ''; + const name = user.attributes.profile.displayName; + const email = {user.attributes.email}; const resendEmailLink = (