Skip to content
This repository has been archived by the owner on Sep 19, 2021. It is now read-only.

Commit

Permalink
Merge pull request #485 from 18F/cached-data-on-master
Browse files Browse the repository at this point in the history
Cherry-pick "clear state on logout"
  • Loading branch information
ryanhofdotgov authored Jun 29, 2018
2 parents d29c858 + b11434b commit e32ab21
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 25 deletions.
9 changes: 0 additions & 9 deletions src/reducers/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,6 @@ const authentication = function (state = defaultState, action) {
error: action.error
}

case AuthConstants.LOGOUT:
return {
...state,
authenticated: false,
twofactor: false,
token: null,
qrcode: null
}

default:
return state
}
Expand Down
15 changes: 0 additions & 15 deletions src/reducers/authentication.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,6 @@ describe('Authentication Reducer', function () {
expect(authentication(defaultState, action)).toEqual(expectedState)
})

it('should handle logout', function () {
const expectedState = {
authenticated: false,
token: null,
twofactor: false,
qrcode: null
}

const action = {
type: AuthConstants.LOGOUT
}

expect(authentication(defaultState, action)).toEqual(expectedState)
})

it('should handle login error', function () {
const expectedState = {
authenticated: false,
Expand Down
13 changes: 12 additions & 1 deletion src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@ import { combineReducers } from 'redux'
import authentication from './authentication'
import section from './section'
import application from './application'
import AuthConstants from '../actions/AuthConstants'

const rootReducer = combineReducers({
const appReducer = combineReducers({
authentication: authentication,
section: section,
application: application
})

const rootReducer = (state, action) => {
// clear data on logout
// https://netbasal.com/how-to-secure-your-users-data-after-logout-in-redux-30468c6848e8
if (action.type === AuthConstants.LOGOUT) {
state = undefined
}

return appReducer(state, action)
}

export default rootReducer
58 changes: 58 additions & 0 deletions src/reducers/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import rootReducer from './index'
import AuthConstants from '../actions/AuthConstants'

describe('Root Reducer', function () {
const defaultState = {
application: {
AddressBooks: { },
Citizenship: { },
Completed: { },
Errors: { },
Financial: { },
Foreign: { },
History: { },
Identification: { },
Legal: { },
Military: { },
Psychological: { },
Relationships: { },
Settings: { },
Submission: { },
Substance: { },
TBD: { }
},
authentication: {
authenticated: false,
token: null
},
section: {
section: 'identification',
subsection: ''
}
}

it('should populate the state', function () {
const startState = {}
const action = { type: 'unknown' }
expect(rootReducer(startState, action)).toEqual(defaultState)
})

it('should handle logout', function () {
const startState = {
application: {
AddressBooks: { foo: 'bar' }
},
authentication: {
authenticated: true,
token: 'dummytoken'
},
section: {
section: 'identification',
subsection: ''
}
}

const action = { type: AuthConstants.LOGOUT }
expect(rootReducer(startState, action)).toEqual(defaultState)
})
})

0 comments on commit e32ab21

Please sign in to comment.