Make SIGNOUT_REQUEST_SUCCEEDED null all user attributes
This commit is contained in:
parent
319c98bcc9
commit
996c004f74
|
@ -42,6 +42,7 @@ describe('currentUser', () => {
|
|||
const loggedInUser: User = {
|
||||
attributes: {
|
||||
firstName: 'Snowball',
|
||||
imageUrl: 'http://some.url',
|
||||
},
|
||||
isLoading: false,
|
||||
isLoggedIn: true,
|
||||
|
@ -169,6 +170,7 @@ describe('currentUser', () => {
|
|||
const expectedNewState: User = {
|
||||
attributes: {
|
||||
firstName: null,
|
||||
imageUrl: null,
|
||||
},
|
||||
isLoading: false,
|
||||
isLoggedIn: false,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import {
|
||||
User,
|
||||
UserAttributes,
|
||||
ReduxAction,
|
||||
REGISTRATION_REQUEST_SENT,
|
||||
REGISTRATION_REQUEST_SUCCEEDED,
|
||||
|
@ -49,12 +50,19 @@ const currentUser = (state: User = initialUser, action: ReduxAction): User => {
|
|||
isLoggedIn: false,
|
||||
}
|
||||
case SIGNOUT_REQUEST_SUCCEEDED:
|
||||
const userAttributeKeys: string[] = Object.keys(state.attributes)
|
||||
const allNullUserAttributes: UserAttributes = userAttributeKeys.reduce(
|
||||
(accumulatedNullUserAttributes: UserAttributes, curentUserAttributeKey: string): UserAttributes => {
|
||||
return {
|
||||
...accumulatedNullUserAttributes,
|
||||
[curentUserAttributeKey]: null,
|
||||
}
|
||||
},
|
||||
{},
|
||||
)
|
||||
return {
|
||||
...state,
|
||||
attributes: {
|
||||
...state.attributes,
|
||||
firstName: null,
|
||||
},
|
||||
attributes: allNullUserAttributes,
|
||||
isLoading: false,
|
||||
isLoggedIn: false,
|
||||
}
|
||||
|
|
|
@ -3,7 +3,9 @@ import {
|
|||
Store,
|
||||
} from 'redux'
|
||||
|
||||
export interface UserAttributes {}
|
||||
export interface UserAttributes {
|
||||
[key: string]: string | number | null
|
||||
}
|
||||
|
||||
export interface User {
|
||||
readonly isLoggedIn: boolean
|
||||
|
|
Loading…
Reference in New Issue
Block a user