Skip to content

Commit

Permalink
fix: #2274 login bug fixed (#2392)
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcvay authored Aug 18, 2020
1 parent 60e7d03 commit 049897d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ describe('Login', () => {
describe('onLoginButtonClick', () => {
it('should run correctly', () => {
const spyFn = jest.spyOn(reapitConnectBrowserSession, 'connectLoginRedirect')
const mockIsFirstTimeLogin = true
const fn = onLoginButtonClick(mockIsFirstTimeLogin)
const fn = onLoginButtonClick()
fn()
expect(spyFn).toBeCalled()
})
Expand Down
14 changes: 3 additions & 11 deletions packages/developer-portal/src/components/pages/login/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { Button, Level, FlexContainerBasic, Section } from '@reapit/elements'
import { getDefaultRoute } from '@/utils/auth-route'
import Routes from '@/constants/routes'
import messages from '@/constants/messages'
import { getCookieString, COOKIE_DEVELOPER_FIRST_TIME_LOGIN_COMPLETE } from '@/utils/cookie'
import loginStyles from '@/styles/pages/login.scss?mod'
import logoImage from '@/assets/images/reapit-graphic.jpg'
import connectImage from '@/assets/images/reapit-connect.png'
Expand All @@ -30,18 +29,16 @@ export const handleShowNotificationAfterPasswordChanged = (
}
}

export const onLoginButtonClick = (isFirtTimeLogin: boolean) => {
export const onLoginButtonClick = () => {
return () => {
const redirectRoute = getDefaultRoute(isFirtTimeLogin)
reapitConnectBrowserSession.connectLoginRedirect(redirectRoute)
reapitConnectBrowserSession.connectLoginRedirect(getDefaultRoute(true))
}
}

export const Login: React.FunctionComponent<LoginProps> = () => {
const dispatch = useDispatch()

const isPasswordChanged = localStorage.getItem('isPasswordChanged') === 'true'
const isFirtTimeLogin = Boolean(getCookieString(COOKIE_DEVELOPER_FIRST_TIME_LOGIN_COMPLETE))

React.useEffect(handleShowNotificationAfterPasswordChanged(isPasswordChanged, localStorage, dispatch), [
isPasswordChanged,
Expand All @@ -59,12 +56,7 @@ export const Login: React.FunctionComponent<LoginProps> = () => {
<p>Welcome to Reapit Foundations</p>
</Section>
<Level className={registerLevel}>
<Button
className={loginButton}
onClick={onLoginButtonClick(isFirtTimeLogin)}
fullWidth
dataTest="login-button"
>
<Button className={loginButton} onClick={onLoginButtonClick()} fullWidth dataTest="login-button">
Login
</Button>
<div className={register}>
Expand Down
6 changes: 6 additions & 0 deletions packages/developer-portal/src/core/private-route-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Redirect, useLocation } from 'react-router'
import Routes from '@/constants/routes'
import { useReapitConnect } from '@reapit/connect-session'
import { reapitConnectBrowserSession } from '@/core/connect-session'
import { getCookieString, COOKIE_DEVELOPER_FIRST_TIME_LOGIN_COMPLETE } from '@/utils/cookie'

const { Suspense } = React

Expand All @@ -30,11 +31,16 @@ export const PrivateRouteWrapper: React.FunctionComponent<PrivateRouteWrapperPro
const location = useLocation()
const currentUri = `${location.pathname}${location.search}`
const isRoot = connectInternalRedirect === '/'
const hasReadWelcome = Boolean(getCookieString(COOKIE_DEVELOPER_FIRST_TIME_LOGIN_COMPLETE))

if (!connectSession) {
return null
}

if (!hasReadWelcome && location.pathname === Routes.APPS) {
return <Redirect to={Routes.WELCOME} />
}

if (
(connectInternalRedirect && currentUri !== connectInternalRedirect) ||
(currentUri === connectInternalRedirect && isRoot)
Expand Down

0 comments on commit 049897d

Please sign in to comment.