Skip to content

Commit

Permalink
fix: #231 switch to use localStorage after password changed and logout (
Browse files Browse the repository at this point in the history
  • Loading branch information
duong-se authored Feb 14, 2020
1 parent dc15cfc commit 57c7e94
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
13 changes: 12 additions & 1 deletion packages/marketplace/src/components/pages/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ import logoImage from '@/assets/images/reapit-graphic.jpg'
import { getLoginTypeByPath, getDefaultPathByLoginType, getDefaultRouteByLoginType } from '@/utils/auth-route'
import { getCookieString, COOKIE_FIRST_TIME_LOGIN } from '@/utils/cookie'
import connectImage from '@/assets/images/reapit-connect.png'
import { showNotificationMessage } from '@/actions/notification-message'
import messages from '@/constants/messages'

export interface LoginMappedActions {
showNotiAfterPasswordChanged: () => void
authChangeLoginType: (loginType: string) => void
}

Expand Down Expand Up @@ -47,14 +50,20 @@ export const tabConfigs = ({ loginType, history }: LoginProps): TabConfig[] => [
export const Login: React.FunctionComponent<LoginProps> = (props: LoginProps) => {
const reapitEnv = process.env.REAPIT_ENV || 'LOCAL'
const isReapitEnvProd = reapitEnv === 'PROD'
const { hasSession, loginType, location, authChangeLoginType } = props
const isPasswordChanged = localStorage.getItem('isPasswordChanged') === 'true'
const { hasSession, loginType, location, authChangeLoginType, showNotiAfterPasswordChanged } = props
const { wrapper, container, image, tabsContainer /* , register */ } = loginStyles

const currentLoginType = getLoginTypeByPath(location.pathname)
authChangeLoginType(currentLoginType)

const firstLoginCookie = getCookieString(COOKIE_FIRST_TIME_LOGIN)

if (isPasswordChanged) {
showNotiAfterPasswordChanged()
localStorage.removeItem('isPasswordChanged')
}

if (hasSession) {
const redirectRoute = getDefaultPathByLoginType(loginType, firstLoginCookie)
return <Redirect to={redirectRoute} />
Expand Down Expand Up @@ -103,6 +112,8 @@ export const mapStateToProps = (state: ReduxState): LoginMappedProps => ({
})

export const mapDispatchToProps = (dispatch: Dispatch): LoginMappedActions => ({
showNotiAfterPasswordChanged: () =>
dispatch(showNotificationMessage({ variant: 'info', message: messages.PASSWORD_CHANGED_SUCCESSFULLY })),
authChangeLoginType: (loginType: string) => dispatch(authChangeLoginType(loginType as LoginType)),
})

Expand Down
1 change: 1 addition & 0 deletions packages/marketplace/src/constants/messages.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const messages = {
CHANGE_SAVE_SUCCESSFULLY: 'Changes saved successfully.',
PASSWORD_CHANGED_SUCCESSFULLY: 'Password changed successfully.',
}

export default messages
10 changes: 1 addition & 9 deletions packages/marketplace/src/sagas/__tests__/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,7 @@ describe('settings', () => {
cognitoClientId: process.env.COGNITO_CLIENT_ID_MARKETPLACE || '',
}),
)
expect(clone.next('SUCCESS').value).toEqual(
put(
showNotificationMessage({
variant: 'info',
message: messages.CHANGE_SAVE_SUCCESSFULLY,
}),
),
)
expect(clone.next().value).toEqual(call(removeSession))
expect(clone.next('SUCCESS').value).toEqual(call(removeSession))
expect(clone.next().value).toEqual(put(authLogout()))
expect(clone.next().value).toEqual(put(settingShowLoading(false)))
expect(clone.next().done).toEqual(true)
Expand Down
7 changes: 1 addition & 6 deletions packages/marketplace/src/sagas/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,7 @@ export const developerPasswordChange = function*({ data }: Action<ChangePassword
if (!isCallAPISuccess) {
throw new Error('Server error')
}
yield put(
showNotificationMessage({
variant: 'info',
message: messages.CHANGE_SAVE_SUCCESSFULLY,
}),
)
localStorage.setItem('isPasswordChanged', 'true')
yield call(removeSession)
yield put(authLogout())
} catch (error) {
Expand Down

0 comments on commit 57c7e94

Please sign in to comment.