Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
327cc23712 | ||
|
9ec2e490a0 | ||
|
4cbd705da5 | ||
|
330f03f033 | ||
|
79708b37ae | ||
|
e85f39ebe2 | ||
|
255ee70ab6 | ||
|
1a82e350f8 | ||
|
b091e39189 | ||
|
33ed6ad156 | ||
|
e35e3398e8 | ||
|
5f49d5b7b1 | ||
|
a1748afd09 | ||
|
7a8b7134da | ||
|
828d09869d |
|
@ -185,8 +185,16 @@ import SomeProtectedPageComponent from './components/SomeProtectedPageComponent'
|
|||
import SignInPage from './components/SignInPage'
|
||||
import { generateRequireSignInWrapper } from 'redux-token-auth'
|
||||
|
||||
// In this example we set `reduxTokenAuth` as reducer key.
|
||||
// You can set other key name as you like.
|
||||
const mapStateToProps = (state) => ({
|
||||
hasVerificationBeenAttempted: state.reduxTokenAuth.currentUser.hasVerificationBeenAttempted,
|
||||
isSignedIn: state.reduxTokenAuth.currentUser.isSignedIn
|
||||
})
|
||||
|
||||
const requireSignIn = generateRequireSignInWrapper({
|
||||
redirectPathIfNotSignedIn: '/signin',
|
||||
mapStateToProps,
|
||||
})
|
||||
|
||||
const history = createBrowserHistory({})
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
machine:
|
||||
node:
|
||||
version: 8.4.0
|
||||
version: 10.17.0
|
||||
test:
|
||||
override:
|
||||
- npm test -- --coverage
|
||||
|
|
15
dist/actions.js
vendored
15
dist/actions.js
vendored
|
@ -1,9 +1,10 @@
|
|||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
|
@ -14,8 +15,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [0, t.value];
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
|
@ -34,8 +35,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
var _this = this;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.setHasVerificationBeenAttempted = exports.signOutRequestFailed = exports.signOutRequestSucceeded = exports.signOutRequestSent = exports.signInRequestFailed = exports.signInRequestSucceeded = exports.signInRequestSent = exports.verifyTokenRequestFailed = exports.verifyTokenRequestSucceeded = exports.verifyTokenRequestSent = exports.registrationRequestFailed = exports.registrationRequestSucceeded = exports.registrationRequestSent = void 0;
|
||||
var axios_1 = require("axios");
|
||||
var types_1 = require("./types");
|
||||
var AsyncLocalStorage_1 = require("./AsyncLocalStorage");
|
||||
|
@ -98,8 +99,8 @@ exports.setHasVerificationBeenAttempted = function (hasVerificationBeenAttempted
|
|||
// Async Redux Thunk actions:
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
var generateAuthActions = function (config) {
|
||||
var authUrl = config.authUrl, storage = config.storage, userAttributes = config.userAttributes, userRegistrationAttributes = config.userRegistrationAttributes;
|
||||
var Storage = Boolean(storage.flushGetRequests) ? storage : AsyncLocalStorage_1.default;
|
||||
var authUrl = config.authUrl, userAttributes = config.userAttributes, userRegistrationAttributes = config.userRegistrationAttributes;
|
||||
var Storage = AsyncLocalStorage_1.default;
|
||||
var registerUser = function (userRegistrationDetails) { return function (dispatch) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var email, password, passwordConfirmation, data, response, userAttributesToSave, error_1;
|
||||
|
@ -249,7 +250,7 @@ var generateAuthActions = function (config) {
|
|||
});
|
||||
});
|
||||
}; };
|
||||
var verifyCredentials = function (store) { return __awaiter(_this, void 0, void 0, function () {
|
||||
var verifyCredentials = function (store) { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var verificationParams, _a, _b;
|
||||
return __generator(this, function (_c) {
|
||||
switch (_c.label) {
|
||||
|
|
2
dist/actions.js.map
vendored
2
dist/actions.js.map
vendored
File diff suppressed because one or more lines are too long
41
dist/generate-require-signin-wrapper.js
vendored
41
dist/generate-require-signin-wrapper.js
vendored
|
@ -1,35 +1,46 @@
|
|||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
var __assign = (this && this.__assign) || Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var React = require("react");
|
||||
var react_redux_1 = require("react-redux");
|
||||
var generateRequireSignInWrapper = function (_a) {
|
||||
var redirectPathIfNotSignedIn = _a.redirectPathIfNotSignedIn;
|
||||
var redirectPathIfNotSignedIn = _a.redirectPathIfNotSignedIn, mapStateToProps = _a.mapStateToProps;
|
||||
var requireSignInWrapper = function (PageComponent) {
|
||||
// const mapStateToProps = (state: ReduxState) => ({
|
||||
// hasVerificationBeenAttempted: state.reduxTokenAuth.currentUser.hasVerificationBeenAttempted,
|
||||
// isSignedIn: state.reduxTokenAuth.currentUser.isSignedIn
|
||||
// })
|
||||
var connector = react_redux_1.connect(mapStateToProps);
|
||||
var GatedPage = /** @class */ (function (_super) {
|
||||
__extends(GatedPage, _super);
|
||||
function GatedPage() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
GatedPage.prototype.componentWillReceiveProps = function (nextProps) {
|
||||
var history = nextProps.history, hasVerificationBeenAttempted = nextProps.hasVerificationBeenAttempted, isSignedIn = nextProps.isSignedIn;
|
||||
GatedPage.prototype.componentDidUpdate = function () {
|
||||
var _a = this.props, history = _a.history, hasVerificationBeenAttempted = _a.hasVerificationBeenAttempted, isSignedIn = _a.isSignedIn;
|
||||
if (hasVerificationBeenAttempted && !isSignedIn) {
|
||||
history.replace(redirectPathIfNotSignedIn);
|
||||
}
|
||||
|
@ -43,10 +54,6 @@ var generateRequireSignInWrapper = function (_a) {
|
|||
};
|
||||
return GatedPage;
|
||||
}(React.Component));
|
||||
var mapStateToProps = function (state) { return ({
|
||||
hasVerificationBeenAttempted: state.reduxTokenAuth.currentUser.hasVerificationBeenAttempted,
|
||||
isSignedIn: state.reduxTokenAuth.currentUser.isSignedIn
|
||||
}); };
|
||||
return react_redux_1.connect(mapStateToProps)(GatedPage);
|
||||
};
|
||||
return requireSignInWrapper;
|
||||
|
|
2
dist/generate-require-signin-wrapper.js.map
vendored
2
dist/generate-require-signin-wrapper.js.map
vendored
|
@ -1 +1 @@
|
|||
{"version":3,"file":"generate-require-signin-wrapper.js","sourceRoot":"","sources":["../src/generate-require-signin-wrapper.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,6BAA8B;AAE9B,2CAAqC;AAOrC,IAAM,4BAA4B,GAAG,UACnC,EAAiE;QAA/D,wDAAyB;IAE3B,IAAM,oBAAoB,GAAG,UAAC,aAA6B;QASzD;YAAwB,6BAA6B;YAArD;;YAuBA,CAAC;YAtBQ,6CAAyB,GAAhC,UAAiC,SAAuB;gBAEpD,IAAA,2BAAO,EACP,qEAA4B,EAC5B,iCAAU,CACC;gBACb,IAAI,4BAA4B,IAAI,CAAC,UAAU,EAAE;oBAC/C,OAAO,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAA;iBAC3C;YACH,CAAC;YAEM,0BAAM,GAAb;gBACQ,IAAA,eAGQ,EAFZ,8DAA4B,EAC5B,0BAAU,CACE;gBAEd,OAAO,CAAC,4BAA4B,IAAI,UAAU,CAAC,CAAC,CAAC;oBACnD,oBAAC,aAAa,eAAK,IAAI,CAAC,KAAK,EAAI;oBACjC,CAAC;wBACD,gCAAW,CAAC;YAChB,CAAC;YACH,gBAAC;QAAD,CAAC,AAvBD,CAAwB,KAAK,CAAC,SAAS,GAuBtC;Q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AI,CAAC,KAAK,EAAI;oBACjC,CAAC;wBACD,gCAAW,CAAC;YAChB,CAAC;YACH,gBAAC;QAAD,CAAC,AAvBD,CAAwB,KAAK,CAAC,SAAS,GAuBtC;QAED,OAAO,qBAAO,CACZ,eAAe,CAChB,CAAC,SAAS,CAAC,CAAA;IACd,CAAC,CAAA;IAED,OAAO,oBAAoB,CAAA;AAC7B,CAAC,CAAA;AAED,kBAAe,4BAA4B,CAAA"}
|
1
dist/index.js
vendored
1
dist/index.js
vendored
|
@ -1,5 +1,6 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.reduxTokenAuthReducer = exports.generateRequireSignInWrapper = exports.generateAuthActions = void 0;
|
||||
var actions_1 = require("./actions");
|
||||
exports.generateAuthActions = actions_1.default;
|
||||
var reducers_1 = require("./reducers");
|
||||
|
|
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
|
@ -1 +1 @@
|
|||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,qCAA2C;AAKzC,8BALK,iBAAmB,CAKL;AAJrB,uCAA8C;AAM5C,gCANK,kBAAqB,CAML;AALvB,qFAA4E;AAI1E,uCAJK,yCAA4B,CAIL"}
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qCAA2C;AAKzC,8BALK,iBAAmB,CAKL;AAJrB,uCAA8C;AAM5C,gCANK,kBAAqB,CAML;AALvB,qFAA4E;AAI1E,uCAJK,yCAA4B,CAIL"}
|
35
dist/reducers/current-user/index.js
vendored
35
dist/reducers/current-user/index.js
vendored
|
@ -1,11 +1,14 @@
|
|||
"use strict";
|
||||
var __assign = (this && this.__assign) || Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var types_1 = require("../../types");
|
||||
|
@ -18,28 +21,28 @@ var currentUser = function (state, action) {
|
|||
case types_1.VERIFY_TOKEN_REQUEST_SENT:
|
||||
case types_1.SIGNIN_REQUEST_SENT:
|
||||
case types_1.SIGNOUT_REQUEST_SENT:
|
||||
return __assign({}, state, { isLoading: true });
|
||||
return __assign(__assign({}, state), { isLoading: true });
|
||||
case types_1.VERIFY_TOKEN_REQUEST_SUCCEEDED:
|
||||
return __assign({}, state, { attributes: __assign({}, action.payload.userAttributes), isLoading: false, isSignedIn: true, hasVerificationBeenAttempted: true });
|
||||
return __assign(__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:
|
||||
return __assign({}, state, { attributes: __assign({}, action.payload.userAttributes), isLoading: false, isSignedIn: true });
|
||||
return __assign(__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 });
|
||||
return __assign(__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 });
|
||||
return __assign(__assign({}, state), { isLoading: false, isSignedIn: false });
|
||||
case types_1.SIGNOUT_REQUEST_SUCCEEDED:
|
||||
var userAttributeKeys = Object.keys(state.attributes);
|
||||
var allNullUserAttributes = userAttributeKeys.reduce(function (accumulatedNullUserAttributes, currentUserAttributeKey) {
|
||||
return __assign({}, accumulatedNullUserAttributes, (_a = {}, _a[currentUserAttributeKey] = null, _a));
|
||||
var _a;
|
||||
return __assign(__assign({}, accumulatedNullUserAttributes), (_a = {}, _a[currentUserAttributeKey] = null, _a));
|
||||
}, {});
|
||||
return __assign({}, state, { attributes: allNullUserAttributes, isLoading: false, isSignedIn: false });
|
||||
return __assign(__assign({}, state), { attributes: allNullUserAttributes, isLoading: false, isSignedIn: false });
|
||||
case types_1.SIGNOUT_REQUEST_FAILED:
|
||||
return __assign({}, state, { isLoading: false });
|
||||
return __assign(__assign({}, state), { isLoading: false });
|
||||
case types_1.SET_HAS_VERIFICATION_BEEN_ATTEMPTED:
|
||||
return __assign({}, state, { hasVerificationBeenAttempted: action.payload.hasVerificationBeenAttempted });
|
||||
return __assign(__assign({}, state), { hasVerificationBeenAttempted: action.payload.hasVerificationBeenAttempted });
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
2
dist/reducers/current-user/index.js.map
vendored
2
dist/reducers/current-user/index.js.map
vendored
|
@ -1 +1 @@
|
|||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/reducers/current-user/index.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,qCAiBoB;AACpB,qDAA8C;AAG5C,IAAA,iDAAwB,CACV;AAEhB,IAAM,WAAW,GAAG,UAAC,KAAyB,EAAE,MAAmB;IAA9C,sBAAA,EAAA,mBAAyB;IAC5C,QAAQ,MAAM,CAAC,IAAI,EAAE;QACnB,KAAK,iCAAyB,CAAC;QAC/B,KAAK,iCAAyB,CAAC;QAC/B,KAAK,2BAAmB,CAAC;QACzB,KAAK,4BAAoB;YACvB,oBACK,KAAK,IACR,SAAS,EAAE,IAAI,IAChB;QACH,KAAK,sCAA8B;YACjC,oBACK,KAAK,IACR,UAAU,eAAO,MAAM,CAAC,OAAO,CAAC,cAAc,GAC9C,SAAS,EAAE,KAAK,EAChB,UAAU,EAAE,IAAI,EAChB,4BAA4B,EAAE,IAAI,IACnC;QACH,KAAK,sCAA8B,CAAC;QACpC,KAAK,gCAAwB;YAC3B,oBACK,KAAK,IACR,UAAU,eAAO,MAAM,CAAC,OAAO,CAAC,cAAc,GAC9C,SAAS,EAAE,KAAK,EAChB,UAAU,EAAE,IAAI,IACjB;QACH,KAAK,mCAA2B;YAC9B,oBACK,KAAK,IACR,SAAS,EAAE,KAAK,EAChB,UAAU,EAAE,KAAK,EACjB,4BAA4B,EAAE,IAAI,IACnC;QACH,KAAK,mCAA2B,CAAC;QACjC,KAAK,6BAAqB;YACxB,oBACK,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,oBACK,6BAA6B,eAC/B,uBAAuB,IAAG,IAAI,OAChC;;YACH,CAAC,EACD,EAAE,CACH,CAAA;YACD,oBACK,KAAK,IACR,UAAU,EAAE,qBAAqB,EACjC,SAAS,EAAE,KAAK,EAChB,UAAU,EAAE,KAAK,IAClB;QACH,KAAK,8BAAsB;YACzB,oBACK,KAAK,IACR,SAAS,EAAE,KAAK,IACjB;QACH,KAAK,2CAAmC;YACtC,oBACK,KAAK,IACR,4BAA4B,EAAE,MAAM,CAAC,OAAO,CAAC,4BAA4B,IAC1E;QACH;YACE,OAAO,KAAK,CAAA;KACf;AACH,CAAC,CAAA;AAED,kBAAe,WAAW,CAAA"}
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/reducers/current-user/index.ts"],"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UAAU,EAAE,qBAAqB,EACjC,SAAS,EAAE,KAAK,EAChB,UAAU,EAAE,KAAK,IAClB;QACH,KAAK,8BAAsB;YACzB,6BACK,KAAK,KACR,SAAS,EAAE,KAAK,IACjB;QACH,KAAK,2CAAmC;YACtC,6BACK,KAAK,KACR,4BAA4B,EAAE,MAAM,CAAC,OAAO,CAAC,4BAA4B,IAC1E;QACH;YACE,OAAO,KAAK,CAAA;KACf;AACH,CAAC,CAAA;AAED,kBAAe,WAAW,CAAA"}
|
2
dist/reducers/index.js.map
vendored
2
dist/reducers/index.js.map
vendored
|
@ -1 +1 @@
|
|||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/reducers/index.ts"],"names":[],"mappings":";;AAAA,+BAGc;AACd,+CAAwC;AAExC,IAAM,qBAAqB,GAAgB,uBAAe,CAAC;IACzD,WAAW,wBAAA;CACZ,CAAC,CAAA;AAEF,kBAAe,qBAAqB,CAAA;AAEpC,wHAAwH;AACxH,4EAA4E;AAC5E,wHAAwH;AAExH,0CAA0C;AAC1C,2DAA2D;AAC3D,wDAAwD;AACxD,EAAE;AACF,wCAAwC;AACxC,2CAA2C;AAC3C,qBAAqB;AACrB,KAAK;AAEL,4EAA4E"}
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/reducers/index.ts"],"names":[],"mappings":";;AAAA,+BAEc;AACd,+CAAwC;AAExC,IAAM,qBAAqB,GAAG,uBAAe,CAAC;IAC5C,WAAW,wBAAA;CACZ,CAAC,CAAA;AAEF,kBAAe,qBAAqB,CAAA;AAEpC,wHAAwH;AACxH,4EAA4E;AAC5E,wHAAwH;AAExH,0CAA0C;AAC1C,2DAA2D;AAC3D,wDAAwD;AACxD,EAAE;AACF,wCAAwC;AACxC,2CAA2C;AAC3C,qBAAqB;AACrB,KAAK;AAEL,4EAA4E"}
|
11
dist/services/auth.js
vendored
11
dist/services/auth.js
vendored
|
@ -1,9 +1,10 @@
|
|||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
|
@ -14,8 +15,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [0, t.value];
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
|
@ -34,8 +35,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
var _this = this;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getUserAttributesFromResponse = exports.deleteAuthHeadersFromDeviceStorage = exports.deleteAuthHeaders = exports.persistAuthHeadersInDeviceStorage = exports.setAuthHeaders = void 0;
|
||||
var axios_1 = require("axios");
|
||||
var utility_1 = require("./utility");
|
||||
var authHeaderKeys = [
|
||||
|
@ -60,7 +61,7 @@ exports.deleteAuthHeaders = function () {
|
|||
delete axios_1.default.defaults.headers.common[key];
|
||||
});
|
||||
};
|
||||
exports.deleteAuthHeadersFromDeviceStorage = function (Storage) { return __awaiter(_this, void 0, void 0, function () {
|
||||
exports.deleteAuthHeadersFromDeviceStorage = function (Storage) { return __awaiter(void 0, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
authHeaderKeys.forEach(function (key) {
|
||||
Storage.removeItem(key);
|
||||
|
|
2
dist/services/auth.js.map
vendored
2
dist/services/auth.js.map
vendored
|
@ -1 +1 @@
|
|||
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/services/auth.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBAuDA;;AAvDA,+BAAyB;AACzB,qCAAkD;AAQlD,IAAM,cAAc,GAAkB;IACpC,cAAc;IACd,YAAY;IACZ,QAAQ;IACR,QAAQ;IACR,KAAK;CACN,CAAA;AAEY,QAAA,cAAc,GAAG,UAAC,OAAoB;IACjD,cAAc,CAAC,OAAO,CAAC,UAAC,GAAW;QACjC,eAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;IACnD,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAEY,QAAA,iCAAiC,GAAG,UAAC,OAAsB,EAAE,OAAoB;IAC5F,cAAc,CAAC,OAAO,CAAC,UAAC,GAAW;QACjC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAA;IACpC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAEY,QAAA,iBAAiB,GAAG;IAC/B,cAAc,CAAC,OAAO,CAAC,UAAC,GAAW;QACjC,OAAO,eAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IAC3C,CAAC,CAAC,CAAA;AACJ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,6 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.invertMapKeysAndValues = void 0;
|
||||
exports.invertMapKeysAndValues = function (stringMap) {
|
||||
var newStringMap = {};
|
||||
for (var key in stringMap) {
|
||||
|
|
2
dist/services/utility.js.map
vendored
2
dist/services/utility.js.map
vendored
|
@ -1 +1 @@
|
|||
{"version":3,"file":"utility.js","sourceRoot":"","sources":["../../src/services/utility.ts"],"names":[],"mappings":";;AAEa,QAAA,sBAAsB,GAAG,UAAC,SAA+B;IACpE,IAAM,YAAY,GAAyB,EAAE,CAAA;IAC7C,KAAK,IAAI,GAAG,IAAI,SAAS,EAAE;QACzB,IAAM,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC,CAAA;QAC1B,YAAY,CAAC,GAAG,CAAC,GAAG,GAAG,CAAA;KACxB;IACD,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA"}
|
||||
{"version":3,"file":"utility.js","sourceRoot":"","sources":["../../src/services/utility.ts"],"names":[],"mappings":";;;AAEa,QAAA,sBAAsB,GAAG,UAAC,SAA+B;IACpE,IAAM,YAAY,GAAyB,EAAE,CAAA;IAC7C,KAAK,IAAI,GAAG,IAAI,SAAS,EAAE;QACzB,IAAM,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC,CAAA;QAC1B,YAAY,CAAC,GAAG,CAAC,GAAG,GAAG,CAAA;KACxB;IACD,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA"}
|
1
dist/types.js
vendored
1
dist/types.js
vendored
|
@ -1,5 +1,6 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SET_HAS_VERIFICATION_BEEN_ATTEMPTED = exports.SIGNOUT_REQUEST_FAILED = exports.SIGNOUT_REQUEST_SUCCEEDED = exports.SIGNOUT_REQUEST_SENT = exports.SIGNIN_REQUEST_FAILED = exports.SIGNIN_REQUEST_SUCCEEDED = exports.SIGNIN_REQUEST_SENT = exports.VERIFY_TOKEN_REQUEST_FAILED = exports.VERIFY_TOKEN_REQUEST_SUCCEEDED = exports.VERIFY_TOKEN_REQUEST_SENT = exports.REGISTRATION_REQUEST_FAILED = exports.REGISTRATION_REQUEST_SUCCEEDED = exports.REGISTRATION_REQUEST_SENT = void 0;
|
||||
exports.REGISTRATION_REQUEST_SENT = 'redux-token-auth/REGISTRATION_REQUEST_SENT';
|
||||
exports.REGISTRATION_REQUEST_SUCCEEDED = 'redux-token-auth/REGISTRATION_REQUEST_SUCCEEDED';
|
||||
exports.REGISTRATION_REQUEST_FAILED = 'redux-token-auth/REGISTRATION_REQUEST_FAILED';
|
||||
|
|
2
dist/types.js.map
vendored
2
dist/types.js.map
vendored
|
@ -1 +1 @@
|
|||
{"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"}
|
||||
{"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"}
|
12
index.d.ts
vendored
12
index.d.ts
vendored
|
@ -1,12 +1,12 @@
|
|||
import { Reducer } from 'redux'
|
||||
import {GenerateAuthActions} from './src/actions'
|
||||
import {GenerateRequireSignInWrapper} from './src/generate-require-signin-wrapper'
|
||||
import {
|
||||
ActionsGeneratorExport,
|
||||
GenerateRequireSignInWrapperConfig,
|
||||
RequireSignInWrapper,
|
||||
ReduxTokenAuthState,
|
||||
} from './src/types'
|
||||
|
||||
export const reduxTokenAuthReducer: Reducer<{}>
|
||||
export const reduxTokenAuthReducer: Reducer<ReduxTokenAuthState>
|
||||
|
||||
export const generateAuthActions: ActionsGeneratorExport
|
||||
export const generateAuthActions: GenerateAuthActions
|
||||
|
||||
export const generateRequireSignInWrapper: (config: GenerateRequireSignInWrapperConfig) => RequireSignInWrapper
|
||||
export const generateRequireSignInWrapper: GenerateRequireSignInWrapper
|
||||
|
|
5220
package-lock.json
generated
5220
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
24
package.json
24
package.json
|
@ -38,19 +38,19 @@
|
|||
"author": "Kyle Corbelli",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/jest": "^20.0.8",
|
||||
"codecov": "^2.3.0",
|
||||
"jest": "^21.0.0",
|
||||
"ts-jest": "^21.0.1",
|
||||
"typescript": "^2.5.2"
|
||||
"@types/jest": "^26.0.7",
|
||||
"@types/react": "^16.9.43",
|
||||
"@types/react-redux": "^7.1.9",
|
||||
"codecov": "^3.7.2",
|
||||
"jest": "^26.1.0",
|
||||
"ts-jest": "^26.1.3",
|
||||
"typescript": "^3.9.7"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/react": "^16.0.5",
|
||||
"@types/react-native": "^0.48.7",
|
||||
"@types/react-redux": "^5.0.9",
|
||||
"axios": "^0.16.2",
|
||||
"react": "^15.6.1",
|
||||
"react-redux": "^5.0.6",
|
||||
"redux": "^3.7.2"
|
||||
"axios": "^0.21.1",
|
||||
"react": "^16.13.1",
|
||||
"react-redux": "^7.2.0",
|
||||
"redux": "^4.0.5",
|
||||
"redux-thunk": "^2.3.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import axios from 'axios'
|
||||
import {
|
||||
Dispatch,
|
||||
Store,
|
||||
} from 'redux'
|
||||
import {
|
||||
|
@ -11,7 +10,6 @@ import {
|
|||
UserRegistrationDetails,
|
||||
UserSignInCredentials,
|
||||
UserSignOutCredentials,
|
||||
ActionsExport,
|
||||
REGISTRATION_REQUEST_SENT,
|
||||
REGISTRATION_REQUEST_SUCCEEDED,
|
||||
REGISTRATION_REQUEST_FAILED,
|
||||
|
@ -38,6 +36,8 @@ import {
|
|||
SignOutRequestSucceededAction,
|
||||
SignOutRequestFailedAction,
|
||||
SetHasVerificationBeenAttemptedAction,
|
||||
AppThunk,
|
||||
GenerateAuthActionsConfig,
|
||||
} from './types'
|
||||
import AsyncLocalStorage from './AsyncLocalStorage'
|
||||
import {
|
||||
|
@ -122,19 +122,18 @@ export const setHasVerificationBeenAttempted = (
|
|||
// Async Redux Thunk actions:
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const generateAuthActions = (config: { [key: string]: any }): ActionsExport => {
|
||||
const generateAuthActions = (config: GenerateAuthActionsConfig) => {
|
||||
const {
|
||||
authUrl,
|
||||
storage,
|
||||
userAttributes,
|
||||
userRegistrationAttributes,
|
||||
} = config
|
||||
|
||||
const Storage: DeviceStorage = Boolean(storage.flushGetRequests) ? storage : AsyncLocalStorage
|
||||
const Storage: DeviceStorage = AsyncLocalStorage
|
||||
|
||||
const registerUser = (
|
||||
userRegistrationDetails: UserRegistrationDetails,
|
||||
) => async function (dispatch: Dispatch<{}>): Promise<void> {
|
||||
): AppThunk => async function (dispatch) {
|
||||
dispatch(registrationRequestSent())
|
||||
const {
|
||||
email,
|
||||
|
@ -168,7 +167,7 @@ const generateAuthActions = (config: { [key: string]: any }): ActionsExport => {
|
|||
|
||||
const verifyToken = (
|
||||
verificationParams: VerificationParams,
|
||||
) => async function (dispatch: Dispatch<{}>): Promise<void> {
|
||||
): AppThunk => async function (dispatch) {
|
||||
dispatch(verifyTokenRequestSent())
|
||||
try {
|
||||
const response = await axios({
|
||||
|
@ -187,7 +186,7 @@ const generateAuthActions = (config: { [key: string]: any }): ActionsExport => {
|
|||
|
||||
const signInUser = (
|
||||
userSignInCredentials: UserSignInCredentials,
|
||||
) => async function (dispatch: Dispatch<{}>): Promise<void> {
|
||||
): AppThunk => async function (dispatch) {
|
||||
dispatch(signInRequestSent())
|
||||
const {
|
||||
email,
|
||||
|
@ -212,7 +211,7 @@ const generateAuthActions = (config: { [key: string]: any }): ActionsExport => {
|
|||
}
|
||||
}
|
||||
|
||||
const signOutUser = () => async function (dispatch: Dispatch<{}>): Promise<void> {
|
||||
const signOutUser = (): AppThunk => async function (dispatch) {
|
||||
const userSignOutCredentials: UserSignOutCredentials = {
|
||||
'access-token': await Storage.getItem('access-token') as string,
|
||||
client: await Storage.getItem('client') as string,
|
||||
|
@ -257,3 +256,4 @@ const generateAuthActions = (config: { [key: string]: any }): ActionsExport => {
|
|||
}
|
||||
|
||||
export default generateAuthActions
|
||||
export type GenerateAuthActions = typeof generateAuthActions
|
||||
|
|
|
@ -1,31 +1,35 @@
|
|||
import * as React from 'react'
|
||||
import { ComponentClass } from 'react'
|
||||
import { connect } from 'react-redux'
|
||||
import { connect, ConnectedProps } from 'react-redux'
|
||||
import {
|
||||
GenerateRequireSignInWrapperConfig,
|
||||
ReduxState,
|
||||
RequireSignInWrapper,
|
||||
// ReduxState,
|
||||
} from './types'
|
||||
|
||||
const generateRequireSignInWrapper = (
|
||||
{ redirectPathIfNotSignedIn }: GenerateRequireSignInWrapperConfig
|
||||
): RequireSignInWrapper => {
|
||||
const requireSignInWrapper = (PageComponent: ComponentClass): ComponentClass => {
|
||||
interface WrapperProps {
|
||||
readonly hasVerificationBeenAttempted: boolean
|
||||
readonly isSignedIn: boolean
|
||||
{ redirectPathIfNotSignedIn, mapStateToProps }: GenerateRequireSignInWrapperConfig
|
||||
) => {
|
||||
const requireSignInWrapper = (PageComponent: React.ComponentClass | React.FunctionComponent) => {
|
||||
|
||||
// const mapStateToProps = (state: ReduxState) => ({
|
||||
// hasVerificationBeenAttempted: state.reduxTokenAuth.currentUser.hasVerificationBeenAttempted,
|
||||
// isSignedIn: state.reduxTokenAuth.currentUser.isSignedIn
|
||||
// })
|
||||
|
||||
const connector = connect(mapStateToProps)
|
||||
type PropsFromRedux = ConnectedProps<typeof connector>
|
||||
|
||||
type Props = PropsFromRedux & {
|
||||
readonly history: {
|
||||
readonly replace: (path: string) => void
|
||||
}
|
||||
}
|
||||
|
||||
class GatedPage extends React.Component<WrapperProps> {
|
||||
public componentWillReceiveProps(nextProps: WrapperProps): void {
|
||||
class GatedPage extends React.Component<Props> {
|
||||
public componentDidUpdate() {
|
||||
const {
|
||||
history,
|
||||
hasVerificationBeenAttempted,
|
||||
isSignedIn,
|
||||
} = nextProps
|
||||
} = this.props
|
||||
if (hasVerificationBeenAttempted && !isSignedIn) {
|
||||
history.replace(redirectPathIfNotSignedIn)
|
||||
}
|
||||
|
@ -44,11 +48,6 @@ const generateRequireSignInWrapper = (
|
|||
}
|
||||
}
|
||||
|
||||
const mapStateToProps = (state: ReduxState) => ({
|
||||
hasVerificationBeenAttempted: state.reduxTokenAuth.currentUser.hasVerificationBeenAttempted,
|
||||
isSignedIn: state.reduxTokenAuth.currentUser.isSignedIn
|
||||
})
|
||||
|
||||
return connect(
|
||||
mapStateToProps,
|
||||
)(GatedPage)
|
||||
|
@ -58,3 +57,4 @@ const generateRequireSignInWrapper = (
|
|||
}
|
||||
|
||||
export default generateRequireSignInWrapper
|
||||
export type GenerateRequireSignInWrapper = typeof generateRequireSignInWrapper
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
import {
|
||||
combineReducers,
|
||||
Reducer,
|
||||
} from 'redux'
|
||||
import currentUser from './current-user'
|
||||
|
||||
const reduxTokenAuthReducer: Reducer<{}> = combineReducers({
|
||||
const reduxTokenAuthReducer = combineReducers({
|
||||
currentUser,
|
||||
})
|
||||
|
||||
|
|
29
src/types.ts
29
src/types.ts
|
@ -1,8 +1,8 @@
|
|||
import { ComponentClass } from 'react'
|
||||
import {
|
||||
Dispatch,
|
||||
Store,
|
||||
Action
|
||||
} from 'redux'
|
||||
import { ThunkAction } from 'redux-thunk'
|
||||
|
||||
export interface UserAttributes {
|
||||
[key: string]: string | number | null
|
||||
|
@ -19,9 +19,9 @@ export interface ReduxTokenAuthState {
|
|||
readonly currentUser: User
|
||||
}
|
||||
|
||||
export interface ReduxState {
|
||||
readonly reduxTokenAuth: ReduxTokenAuthState
|
||||
}
|
||||
// export interface ReduxState {
|
||||
// readonly reduxTokenAuth: ReduxTokenAuthState
|
||||
// }
|
||||
|
||||
export interface AuthHeaders {
|
||||
readonly 'access-token': string
|
||||
|
@ -179,7 +179,15 @@ export type ReduxAction = RegistrationRequestSentAction
|
|||
| SignOutRequestFailedAction
|
||||
| SetHasVerificationBeenAttemptedAction
|
||||
|
||||
export type ReduxAsyncAction = (input?: any) => (dispatch: Dispatch<{}>) => Promise<void>
|
||||
|
||||
export type AppThunk<ReturnType = Promise<void>> = ThunkAction<
|
||||
ReturnType,
|
||||
object,
|
||||
unknown,
|
||||
Action<string>
|
||||
>
|
||||
|
||||
export type ReduxAsyncAction = (input?: any) => AppThunk
|
||||
|
||||
export type VerifyCredentialsFunction = (store: Store<{}>) => void
|
||||
|
||||
|
@ -199,9 +207,10 @@ export interface SingleLayerStringMap {
|
|||
|
||||
export interface GenerateRequireSignInWrapperConfig {
|
||||
readonly redirectPathIfNotSignedIn: string
|
||||
readonly mapStateToProps: (state: any) => {hasVerificationBeenAttempted: boolean, isSignedIn: boolean}
|
||||
}
|
||||
|
||||
export type RequireSignInWrapper = (PageComponent: ComponentClass) => ComponentClass
|
||||
// export type RequireSignInWrapper = (PageComponent: ComponentClass) => ComponentClass
|
||||
|
||||
export interface DeviceStorage {
|
||||
readonly getItem: (key: string) => Promise<any>
|
||||
|
@ -212,3 +221,9 @@ export interface DeviceStorage {
|
|||
readonly multiGet: (keys: string[]) => Promise<any>
|
||||
readonly multiSet: (keyValuePairs: string[][]) => Promise<any>
|
||||
}
|
||||
|
||||
export interface GenerateAuthActionsConfig {
|
||||
authUrl: string
|
||||
userAttributes: {[key: string]: any}
|
||||
userRegistrationAttributes: {[key: string]: any}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,5 @@
|
|||
"jest",
|
||||
"src/setupTests.ts"
|
||||
],
|
||||
"types": [
|
||||
"typePatches"
|
||||
]
|
||||
"types": []
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user