Add state to check if verification of user has been attempted

This commit is contained in:
Kyle Corbelli committed 2017-09-28 10:51:49 -07:00
1 parent a8b0351e37
commit be654581b4
4 files changed
+26 -5

No files matched your search

+1
View File
@@ -6,6 +6,7 @@ const initialState: ReduxTokenAuthState = {
currentUser: {
isSignedIn: false,
isLoading: false,
hasVerificationBeenAttempted: false,
attributes: {},
},
}
+7
View File
@@ -37,6 +37,7 @@ describe('currentUser', () => {
},
isLoading: true,
isSignedIn: false,
hasVerificationBeenAttempted: false,
}
const loggedInUser: User = {
@@ -46,6 +47,7 @@ describe('currentUser', () => {
},
isLoading: false,
isSignedIn: true,
hasVerificationBeenAttempted: false,
}
const loggedInUserWithRequestAlreadySent: User = {
@@ -72,6 +74,7 @@ describe('currentUser', () => {
attributes: newUserAttributes,
isLoading: false,
isSignedIn: true,
hasVerificationBeenAttempted: false,
}
expect(newState).toEqual(expectedNewState)
})
@@ -104,6 +107,7 @@ describe('currentUser', () => {
attributes: newUserAttributes,
isLoading: false,
isSignedIn: true,
hasVerificationBeenAttempted: true,
}
expect(newState).toEqual(expectedNewState)
})
@@ -119,6 +123,7 @@ describe('currentUser', () => {
const newState: User = currentUser(loggedInState, action)
expect(newState.isLoading).toBe(false)
expect(newState.isSignedIn).toBe(false)
expect(newState.hasVerificationBeenAttempted).toBe(true)
})
})
@@ -141,6 +146,7 @@ describe('currentUser', () => {
attributes: newUserAttributes,
isLoading: false,
isSignedIn: true,
hasVerificationBeenAttempted: false,
}
expect(newState).toEqual(expectedNewState)
})
@@ -174,6 +180,7 @@ describe('currentUser', () => {
},
isLoading: false,
isSignedIn: false,
hasVerificationBeenAttempted: false,
}
expect(newState).toEqual(expectedNewState)
})
+17 -5
View File
@@ -31,18 +31,30 @@ const currentUser = (state: User = initialUser, action: ReduxAction): User => {
...state,
isLoading: true,
}
case REGISTRATION_REQUEST_SUCCEEDED:
case VERIFY_TOKEN_REQUEST_SUCCEEDED:
case SIGNIN_REQUEST_SUCCEEDED:
const { userAttributes } = action.payload
return {
...state,
attributes: { ...userAttributes },
attributes: { ...action.payload.userAttributes },
isLoading: false,
isSignedIn: true,
hasVerificationBeenAttempted: true,
}
case REGISTRATION_REQUEST_SUCCEEDED:
case SIGNIN_REQUEST_SUCCEEDED:
return {
...state,
attributes: { ...action.payload.userAttributes },
isLoading: false,
isSignedIn: true,
}
case REGISTRATION_REQUEST_FAILED:
case VERIFY_TOKEN_REQUEST_FAILED:
return {
...state,
isLoading: false,
isSignedIn: false,
hasVerificationBeenAttempted: true,
}
case REGISTRATION_REQUEST_FAILED:
case SIGNIN_REQUEST_FAILED:
return {
...state,
+1
View File
@@ -11,6 +11,7 @@ export interface UserAttributes {
export interface User {
readonly isSignedIn: boolean
readonly isLoading: boolean
readonly hasVerificationBeenAttempted: boolean
readonly attributes: UserAttributes
}