Merge pull request #17 from kylecorbelli/indicate-user-has-been-checked

Indicate user has been checked
This commit is contained in:
Kyle Corbelli 2017-09-28 15:16:24 -07:00 committed by GitHub
commit 8c5a8fe573
13 changed files with 94 additions and 15 deletions

13
dist/actions.js vendored
View File

@ -88,6 +88,12 @@ exports.signOutRequestSucceeded = function () { return ({
exports.signOutRequestFailed = function () { return ({
type: types_1.SIGNOUT_REQUEST_FAILED,
}); };
exports.setHasVerificationBeenAttempted = function (hasVerificationBeenAttempted) { return ({
type: types_1.SET_HAS_VERIFICATION_BEEN_ATTEMPTED,
payload: {
hasVerificationBeenAttempted: hasVerificationBeenAttempted,
},
}); };
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Async Redux Thunk actions:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -263,8 +269,11 @@ var generateAuthActions = function (config) {
verificationParams = (_a.uid = (_c.sent()),
_a);
store.dispatch(verifyToken(verificationParams));
_c.label = 5;
case 5: return [2 /*return*/];
return [3 /*break*/, 6];
case 5:
store.dispatch(exports.setHasVerificationBeenAttempted(true));
_c.label = 6;
case 6: return [2 /*return*/];
}
});
}); };

2
dist/actions.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -4,6 +4,7 @@ var initialState = {
currentUser: {
isSignedIn: false,
isLoading: false,
hasVerificationBeenAttempted: false,
attributes: {},
},
};

View File

@ -1 +1 @@
{"version":3,"file":"initial-state.js","sourceRoot":"","sources":["../src/initial-state.ts"],"names":[],"mappings":";;AAIA,IAAM,YAAY,GAAwB;IACxC,WAAW,EAAE;QACX,UAAU,EAAE,KAAK;QACjB,SAAS,EAAE,KAAK;QAChB,UAAU,EAAE,EAAE;KACf;CACF,CAAA;AAED,kBAAe,YAAY,CAAA"}
{"version":3,"file":"initial-state.js","sourceRoot":"","sources":["../src/initial-state.ts"],"names":[],"mappings":";;AAIA,IAAM,YAAY,GAAwB;IACxC,WAAW,EAAE;QACX,UAAU,EAAE,KAAK;QACjB,SAAS,EAAE,KAAK;QAChB,4BAA4B,EAAE,KAAK;QACnC,UAAU,EAAE,EAAE;KACf;CACF,CAAA;AAED,kBAAe,YAAY,CAAA"}

View File

@ -19,13 +19,14 @@ var currentUser = function (state, action) {
case types_1.SIGNIN_REQUEST_SENT:
case types_1.SIGNOUT_REQUEST_SENT:
return __assign({}, state, { isLoading: true });
case types_1.REGISTRATION_REQUEST_SUCCEEDED:
case types_1.VERIFY_TOKEN_REQUEST_SUCCEEDED:
return __assign({}, state, { attributes: __assign({}, action.payload.userAttributes), isLoading: false, isSignedIn: true, hasVerificationBeenAttempted: true });
case types_1.REGISTRATION_REQUEST_SUCCEEDED:
case types_1.SIGNIN_REQUEST_SUCCEEDED:
var userAttributes = action.payload.userAttributes;
return __assign({}, state, { attributes: __assign({}, userAttributes), isLoading: false, isSignedIn: true });
case types_1.REGISTRATION_REQUEST_FAILED:
return __assign({}, state, { attributes: __assign({}, action.payload.userAttributes), isLoading: false, isSignedIn: true });
case types_1.VERIFY_TOKEN_REQUEST_FAILED:
return __assign({}, state, { isLoading: false, isSignedIn: false, hasVerificationBeenAttempted: true });
case types_1.REGISTRATION_REQUEST_FAILED:
case types_1.SIGNIN_REQUEST_FAILED:
return __assign({}, state, { isLoading: false, isSignedIn: false });
case types_1.SIGNOUT_REQUEST_SUCCEEDED:
@ -37,6 +38,8 @@ var currentUser = function (state, action) {
return __assign({}, state, { attributes: allNullUserAttributes, isLoading: false, isSignedIn: false });
case types_1.SIGNOUT_REQUEST_FAILED:
return __assign({}, state, { isLoading: false });
case types_1.SET_HAS_VERIFICATION_BEEN_ATTEMPTED:
return __assign({}, state, { hasVerificationBeenAttempted: action.payload.hasVerificationBeenAttempted });
default:
return state;
}

View File

@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/reducers/current-user/index.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,qCAgBoB;AACpB,qDAA8C;AAG5C,IAAA,iDAAwB,CACV;AAEhB,IAAM,WAAW,GAAG,UAAC,KAAyB,EAAE,MAAmB;IAA9C,sBAAA,EAAA,mBAAyB;IAC5C,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QACpB,KAAK,iCAAyB,CAAC;QAC/B,KAAK,iCAAyB,CAAC;QAC/B,KAAK,2BAAmB,CAAC;QACzB,KAAK,4BAAoB;YACvB,MAAM,cACD,KAAK,IACR,SAAS,EAAE,IAAI,IAChB;QACH,KAAK,sCAA8B,CAAC;QACpC,KAAK,sCAA8B,CAAC;QACpC,KAAK,gCAAwB;YACnB,IAAA,8CAAc,CAAmB;YACzC,MAAM,cACD,KAAK,IACR,UAAU,eAAO,cAAc,GAC/B,SAAS,EAAE,KAAK,EAChB,UAAU,EAAE,IAAI,IACjB;QACH,KAAK,mCAA2B,CAAC;QACjC,KAAK,mCAA2B,CAAC;QACjC,KAAK,6BAAqB;YACxB,MAAM,cACD,KAAK,IACR,SAAS,EAAE,KAAK,EAChB,UAAU,EAAE,KAAK,IAClB;QACH,KAAK,iCAAyB;YAC5B,IAAM,iBAAiB,GAAa,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;YACjE,IAAM,qBAAqB,GAAmB,iBAAiB,CAAC,MAAM,CACpE,UAAC,6BAA6C,EAAE,uBAA+B;gBAC7E,MAAM,cACD,6BAA6B,eAC/B,uBAAuB,IAAG,IAAI,OAChC;;YACH,CAAC,EACD,EAAE,CACH,CAAA;YACD,MAAM,cACD,KAAK,IACR,UAAU,EAAE,qBAAqB,EACjC,SAAS,EAAE,KAAK,EAChB,UAAU,EAAE,KAAK,IAClB;QACH,KAAK,8BAAsB;YACzB,MAAM,cACD,KAAK,IACR,SAAS,EAAE,KAAK,IACjB;QACH;YACE,MAAM,CAAC,KAAK,CAAA;IAChB,CAAC;AACH,CAAC,CAAA;AAED,kBAAe,WAAW,CAAA"}
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/reducers/current-user/index.ts"],"names":[],"mappings":";;;;;;;;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cACD,KAAK,IACR,UAAU,EAAE,qBAAqB,EACjC,SAAS,EAAE,KAAK,EAChB,UAAU,EAAE,KAAK,IAClB;QACH,KAAK,8BAAsB;YACzB,MAAM,cACD,KAAK,IACR,SAAS,EAAE,KAAK,IACjB;QACH,KAAK,2CAAmC;YACtC,MAAM,cACD,KAAK,IACR,4BAA4B,EAAE,MAAM,CAAC,OAAO,CAAC,4BAA4B,IAC1E;QACH;YACE,MAAM,CAAC,KAAK,CAAA;IAChB,CAAC;AACH,CAAC,CAAA;AAED,kBAAe,WAAW,CAAA"}

1
dist/types.js vendored
View File

@ -12,4 +12,5 @@ exports.SIGNIN_REQUEST_FAILED = 'redux-token-auth/SIGNIN_REQUEST_FAILED';
exports.SIGNOUT_REQUEST_SENT = 'redux-token-auth/SIGNOUT_REQUEST_SENT';
exports.SIGNOUT_REQUEST_SUCCEEDED = 'redux-token-auth/SIGNOUT_REQUEST_SUCCEEDED';
exports.SIGNOUT_REQUEST_FAILED = 'redux-token-auth/SIGNOUT_REQUEST_FAILED';
exports.SET_HAS_VERIFICATION_BEEN_ATTEMPTED = 'redux-token-auth/SET_HAS_VERIFICATION_BEEN_ATTEMPTED';
//# sourceMappingURL=types.js.map

2
dist/types.js.map vendored
View File

@ -1 +1 @@
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;AA8Ca,QAAA,yBAAyB,GAA8B,4CAA4C,CAAA;AAGnG,QAAA,8BAA8B,GAAmC,iDAAiD,CAAA;AAGlH,QAAA,2BAA2B,GAAgC,8CAA8C,CAAA;AAGzG,QAAA,yBAAyB,GAA8B,4CAA4C,CAAA;AAGnG,QAAA,8BAA8B,GAAmC,iDAAiD,CAAA;AAGlH,QAAA,2BAA2B,GAAgC,8CAA8C,CAAA;AAGzG,QAAA,mBAAmB,GAAwB,sCAAsC,CAAA;AAGjF,QAAA,wBAAwB,GAA6B,2CAA2C,CAAA;AAGhG,QAAA,qBAAqB,GAA0B,wCAAwC,CAAA;AAGvF,QAAA,oBAAoB,GAAyB,uCAAuC,CAAA;AAGpF,QAAA,yBAAyB,GAA8B,4CAA4C,CAAA;AAGnG,QAAA,sBAAsB,GAA2B,yCAAyC,CAAA"}
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;AA+Ca,QAAA,yBAAyB,GAA8B,4CAA4C,CAAA;AAGnG,QAAA,8BAA8B,GAAmC,iDAAiD,CAAA;AAGlH,QAAA,2BAA2B,GAAgC,8CAA8C,CAAA;AAGzG,QAAA,yBAAyB,GAA8B,4CAA4C,CAAA;AAGnG,QAAA,8BAA8B,GAAmC,iDAAiD,CAAA;AAGlH,QAAA,2BAA2B,GAAgC,8CAA8C,CAAA;AAGzG,QAAA,mBAAmB,GAAwB,sCAAsC,CAAA;AAGjF,QAAA,wBAAwB,GAA6B,2CAA2C,CAAA;AAGhG,QAAA,qBAAqB,GAA0B,wCAAwC,CAAA;AAGvF,QAAA,oBAAoB,GAAyB,uCAAuC,CAAA;AAGpF,QAAA,yBAAyB,GAA8B,4CAA4C,CAAA;AAGnG,QAAA,sBAAsB,GAA2B,yCAAyC,CAAA;AAG1F,QAAA,mCAAmC,GAAwC,sDAAsD,CAAA"}

View File

@ -24,6 +24,7 @@ import {
SIGNOUT_REQUEST_SENT,
SIGNOUT_REQUEST_SUCCEEDED,
SIGNOUT_REQUEST_FAILED,
SET_HAS_VERIFICATION_BEEN_ATTEMPTED,
RegistrationRequestSentAction,
RegistrationRequestSucceededAction,
RegistrationRequestFailedAction,
@ -36,6 +37,7 @@ import {
SignOutRequestSentAction,
SignOutRequestSucceededAction,
SignOutRequestFailedAction,
SetHasVerificationBeenAttemptedAction,
} from './types'
import AsyncLocalStorage from './AsyncLocalStorage'
import {
@ -107,6 +109,15 @@ export const signOutRequestFailed = (): SignOutRequestFailedAction => ({
type: SIGNOUT_REQUEST_FAILED,
})
export const setHasVerificationBeenAttempted = (
hasVerificationBeenAttempted: boolean
): SetHasVerificationBeenAttemptedAction => ({
type: SET_HAS_VERIFICATION_BEEN_ATTEMPTED,
payload: {
hasVerificationBeenAttempted,
},
})
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Async Redux Thunk actions:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -231,6 +242,8 @@ const generateAuthActions = (config: { [key: string]: any }): ActionsExport => {
uid: await Storage.getItem('uid') as string,
}
store.dispatch<any>(verifyToken(verificationParams))
} else {
store.dispatch(setHasVerificationBeenAttempted(true))
}
}

View File

@ -6,6 +6,7 @@ const initialState: ReduxTokenAuthState = {
currentUser: {
isSignedIn: false,
isLoading: false,
hasVerificationBeenAttempted: false,
attributes: {},
},
}

View File

@ -14,6 +14,7 @@ import {
SignOutRequestFailedAction,
User,
UserAttributes,
SetHasVerificationBeenAttemptedAction,
} from '../../types'
import {
registrationRequestSent,
@ -28,6 +29,7 @@ import {
signOutRequestSent,
signOutRequestSucceeded,
signOutRequestFailed,
setHasVerificationBeenAttempted,
} from '../../actions'
describe('currentUser', () => {
@ -37,6 +39,7 @@ describe('currentUser', () => {
},
isLoading: true,
isSignedIn: false,
hasVerificationBeenAttempted: false,
}
const loggedInUser: User = {
@ -46,6 +49,7 @@ describe('currentUser', () => {
},
isLoading: false,
isSignedIn: true,
hasVerificationBeenAttempted: false,
}
const loggedInUserWithRequestAlreadySent: User = {
@ -72,6 +76,7 @@ describe('currentUser', () => {
attributes: newUserAttributes,
isLoading: false,
isSignedIn: true,
hasVerificationBeenAttempted: false,
}
expect(newState).toEqual(expectedNewState)
})
@ -104,6 +109,7 @@ describe('currentUser', () => {
attributes: newUserAttributes,
isLoading: false,
isSignedIn: true,
hasVerificationBeenAttempted: true,
}
expect(newState).toEqual(expectedNewState)
})
@ -119,6 +125,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 +148,7 @@ describe('currentUser', () => {
attributes: newUserAttributes,
isLoading: false,
isSignedIn: true,
hasVerificationBeenAttempted: false,
}
expect(newState).toEqual(expectedNewState)
})
@ -174,6 +182,7 @@ describe('currentUser', () => {
},
isLoading: false,
isSignedIn: false,
hasVerificationBeenAttempted: false,
}
expect(newState).toEqual(expectedNewState)
})
@ -190,4 +199,16 @@ describe('currentUser', () => {
expect(newState).toEqual(expectedNewState)
})
})
describe('SET_HAS_VERIFICATION_BEEN_ATTEMPTED', () => {
it('sets hasVerificationBeenAttempted', () => {
const action: SetHasVerificationBeenAttemptedAction = setHasVerificationBeenAttempted(true)
const initialState: User = {
...alreadyLoadingState,
hasVerificationBeenAttempted: false,
}
const newState: User = currentUser(alreadyLoadingState, action)
expect(newState.hasVerificationBeenAttempted).toBe(true)
})
})
})

View File

@ -14,6 +14,7 @@ import {
SIGNOUT_REQUEST_SENT,
SIGNOUT_REQUEST_SUCCEEDED,
SIGNOUT_REQUEST_FAILED,
SET_HAS_VERIFICATION_BEEN_ATTEMPTED,
} from '../../types'
import initialState from '../../initial-state'
@ -31,18 +32,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,
@ -71,6 +84,11 @@ const currentUser = (state: User = initialUser, action: ReduxAction): User => {
...state,
isLoading: false,
}
case SET_HAS_VERIFICATION_BEEN_ATTEMPTED:
return {
...state,
hasVerificationBeenAttempted: action.payload.hasVerificationBeenAttempted,
}
default:
return state
}

View File

@ -11,6 +11,7 @@ export interface UserAttributes {
export interface User {
readonly isSignedIn: boolean
readonly isLoading: boolean
readonly hasVerificationBeenAttempted: boolean
readonly attributes: UserAttributes
}
@ -79,6 +80,9 @@ export const SIGNOUT_REQUEST_SUCCEEDED: SIGNOUT_REQUEST_SUCCEEDED = 'redux-token
export type SIGNOUT_REQUEST_FAILED = 'redux-token-auth/SIGNOUT_REQUEST_FAILED'
export const SIGNOUT_REQUEST_FAILED: SIGNOUT_REQUEST_FAILED = 'redux-token-auth/SIGNOUT_REQUEST_FAILED'
export type SET_HAS_VERIFICATION_BEEN_ATTEMPTED = 'redux-token-auth/SET_HAS_VERIFICATION_BEEN_ATTEMPTED'
export const SET_HAS_VERIFICATION_BEEN_ATTEMPTED: SET_HAS_VERIFICATION_BEEN_ATTEMPTED = 'redux-token-auth/SET_HAS_VERIFICATION_BEEN_ATTEMPTED'
export interface UserRegistrationDetails {
readonly email: string
readonly password: string
@ -154,6 +158,13 @@ export interface SignOutRequestFailedAction {
readonly type: SIGNOUT_REQUEST_FAILED
}
export interface SetHasVerificationBeenAttemptedAction {
readonly type: SET_HAS_VERIFICATION_BEEN_ATTEMPTED
readonly payload: {
readonly hasVerificationBeenAttempted: boolean
}
}
export type ReduxAction = RegistrationRequestSentAction
| RegistrationRequestSucceededAction
| RegistrationRequestFailedAction
@ -166,6 +177,7 @@ export type ReduxAction = RegistrationRequestSentAction
| SignOutRequestSentAction
| SignOutRequestSucceededAction
| SignOutRequestFailedAction
| SetHasVerificationBeenAttemptedAction
export type ReduxAsyncAction = (input?: any) => (dispatch: Dispatch<{}>) => Promise<void>