Add state to check if verification of user has been attempted
This commit is contained in:
parent
a8b0351e37
commit
be654581b4
|
@ -6,6 +6,7 @@ const initialState: ReduxTokenAuthState = {
|
||||||
currentUser: {
|
currentUser: {
|
||||||
isSignedIn: false,
|
isSignedIn: false,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
|
hasVerificationBeenAttempted: false,
|
||||||
attributes: {},
|
attributes: {},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ describe('currentUser', () => {
|
||||||
},
|
},
|
||||||
isLoading: true,
|
isLoading: true,
|
||||||
isSignedIn: false,
|
isSignedIn: false,
|
||||||
|
hasVerificationBeenAttempted: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
const loggedInUser: User = {
|
const loggedInUser: User = {
|
||||||
|
@ -46,6 +47,7 @@ describe('currentUser', () => {
|
||||||
},
|
},
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
isSignedIn: true,
|
isSignedIn: true,
|
||||||
|
hasVerificationBeenAttempted: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
const loggedInUserWithRequestAlreadySent: User = {
|
const loggedInUserWithRequestAlreadySent: User = {
|
||||||
|
@ -72,6 +74,7 @@ describe('currentUser', () => {
|
||||||
attributes: newUserAttributes,
|
attributes: newUserAttributes,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
isSignedIn: true,
|
isSignedIn: true,
|
||||||
|
hasVerificationBeenAttempted: false,
|
||||||
}
|
}
|
||||||
expect(newState).toEqual(expectedNewState)
|
expect(newState).toEqual(expectedNewState)
|
||||||
})
|
})
|
||||||
|
@ -104,6 +107,7 @@ describe('currentUser', () => {
|
||||||
attributes: newUserAttributes,
|
attributes: newUserAttributes,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
isSignedIn: true,
|
isSignedIn: true,
|
||||||
|
hasVerificationBeenAttempted: true,
|
||||||
}
|
}
|
||||||
expect(newState).toEqual(expectedNewState)
|
expect(newState).toEqual(expectedNewState)
|
||||||
})
|
})
|
||||||
|
@ -119,6 +123,7 @@ describe('currentUser', () => {
|
||||||
const newState: User = currentUser(loggedInState, action)
|
const newState: User = currentUser(loggedInState, action)
|
||||||
expect(newState.isLoading).toBe(false)
|
expect(newState.isLoading).toBe(false)
|
||||||
expect(newState.isSignedIn).toBe(false)
|
expect(newState.isSignedIn).toBe(false)
|
||||||
|
expect(newState.hasVerificationBeenAttempted).toBe(true)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -141,6 +146,7 @@ describe('currentUser', () => {
|
||||||
attributes: newUserAttributes,
|
attributes: newUserAttributes,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
isSignedIn: true,
|
isSignedIn: true,
|
||||||
|
hasVerificationBeenAttempted: false,
|
||||||
}
|
}
|
||||||
expect(newState).toEqual(expectedNewState)
|
expect(newState).toEqual(expectedNewState)
|
||||||
})
|
})
|
||||||
|
@ -174,6 +180,7 @@ describe('currentUser', () => {
|
||||||
},
|
},
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
isSignedIn: false,
|
isSignedIn: false,
|
||||||
|
hasVerificationBeenAttempted: false,
|
||||||
}
|
}
|
||||||
expect(newState).toEqual(expectedNewState)
|
expect(newState).toEqual(expectedNewState)
|
||||||
})
|
})
|
||||||
|
|
|
@ -31,18 +31,30 @@ const currentUser = (state: User = initialUser, action: ReduxAction): User => {
|
||||||
...state,
|
...state,
|
||||||
isLoading: true,
|
isLoading: true,
|
||||||
}
|
}
|
||||||
case REGISTRATION_REQUEST_SUCCEEDED:
|
|
||||||
case VERIFY_TOKEN_REQUEST_SUCCEEDED:
|
case VERIFY_TOKEN_REQUEST_SUCCEEDED:
|
||||||
case SIGNIN_REQUEST_SUCCEEDED:
|
|
||||||
const { userAttributes } = action.payload
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...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,
|
isLoading: false,
|
||||||
isSignedIn: true,
|
isSignedIn: true,
|
||||||
}
|
}
|
||||||
case REGISTRATION_REQUEST_FAILED:
|
|
||||||
case VERIFY_TOKEN_REQUEST_FAILED:
|
case VERIFY_TOKEN_REQUEST_FAILED:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
isLoading: false,
|
||||||
|
isSignedIn: false,
|
||||||
|
hasVerificationBeenAttempted: true,
|
||||||
|
}
|
||||||
|
case REGISTRATION_REQUEST_FAILED:
|
||||||
case SIGNIN_REQUEST_FAILED:
|
case SIGNIN_REQUEST_FAILED:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
|
|
@ -11,6 +11,7 @@ export interface UserAttributes {
|
||||||
export interface User {
|
export interface User {
|
||||||
readonly isSignedIn: boolean
|
readonly isSignedIn: boolean
|
||||||
readonly isLoading: boolean
|
readonly isLoading: boolean
|
||||||
|
readonly hasVerificationBeenAttempted: boolean
|
||||||
readonly attributes: UserAttributes
|
readonly attributes: UserAttributes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user