diff --git a/dist/Storage.js b/dist/Storage.js new file mode 100644 index 0000000..a4fd20a --- /dev/null +++ b/dist/Storage.js @@ -0,0 +1,79 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var react_native_1 = require("react-native"); +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Rip this out into its own npm package: +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +var AsyncLocalStorage = { + getItem: function (key) { return new Promise(function (resolve, reject) { + try { + var value = window.localStorage.getItem(key); + resolve(value); + } + catch (error) { + reject(error); + } + }); }, + setItem: function (key, value) { return new Promise(function (resolve, reject) { + try { + window.localStorage.setItem(key, value); + resolve(value); + } + catch (error) { + reject(error); + } + }); }, + removeItem: function (key) { return new Promise(function (resolve, reject) { + try { + var value = window.localStorage.getItem(key); + window.localStorage.removeItem(key); + resolve(value); + } + catch (error) { + reject(error); + } + }); }, + clear: function () { return new Promise(function (resolve, reject) { + try { + window.localStorage.clear(); + resolve(true); + } + catch (error) { + reject(error); + } + }); }, + getAllKeys: function () { return new Promise(function (resolve, reject) { + try { + var allKeys = Object.keys(window.localStorage); + resolve(allKeys); + } + catch (error) { + reject(error); + } + }); }, + multiGet: function (keys) { return new Promise(function (resolve, reject) { + try { + var values = keys.map(function (key) { return [key, window.localStorage.getItem(key)]; }); + resolve(values); + } + catch (error) { + reject(error); + } + }); }, + multiSet: function (keyValuePairs) { return new Promise(function (resolve, reject) { + try { + keyValuePairs.forEach(function (keyValuePair) { return window.localStorage.setItem(keyValuePair[0], keyValuePair[1]); }); + var newKeyValuePairs = keyValuePairs.map(function (keyValuePair) { return [keyValuePair[0], window.localStorage.getItem(keyValuePair[0])]; }); + resolve(newKeyValuePairs); + } + catch (error) { + reject(error); + } + }); }, +}; +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// ^ Rip this out into its own npm package +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +var Storage = window.localStorage ? AsyncLocalStorage : react_native_1.AsyncStorage; +exports.default = Storage; +//# sourceMappingURL=Storage.js.map \ No newline at end of file diff --git a/dist/Storage.js.map b/dist/Storage.js.map new file mode 100644 index 0000000..63c4aa9 --- /dev/null +++ b/dist/Storage.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Storage.js","sourceRoot":"","sources":["../src/Storage.ts"],"names":[],"mappings":";;AAAA,6CAA2C;AAE3C,sIAAsI;AACtI,yCAAyC;AACzC,sIAAsI;AAEtI,IAAM,iBAAiB,GAAG;IACxB,OAAO,EAAE,UAAC,GAAW,IAAmB,OAAA,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;QAClE,IAAI,CAAC;YACH,IAAM,KAAK,GAAkB,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;YAC7D,OAAO,CAAC,KAAK,CAAC,CAAA;QAChB,CAAC;QAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,CAAA;QACf,CAAC;IACH,CAAC,CAAC,EAPsC,CAOtC;IAEF,OAAO,EAAE,UAAC,GAAW,EAAE,KAAa,IAAK,OAAA,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;QACnE,IAAI,CAAC;YACH,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;YACvC,OAAO,CAAC,KAAK,CAAC,CAAA;QAChB,CAAC;QAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,CAAA;QACf,CAAC;IACH,CAAC,CAAC,EAPuC,CAOvC;IAEF,UAAU,EAAE,UAAC,GAAW,IAAmB,OAAA,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;QACrE,IAAI,CAAC;YACH,IAAM,KAAK,GAAkB,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;YAC7D,MAAM,CAAC,YAA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f,MAAM,CAAC,KAAK,CAAC,CAAA;QACf,CAAC;IACH,CAAC,CAAC,EAP4B,CAO5B;IAEF,QAAQ,EAAE,UAAC,aAAyB,IAAK,OAAA,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;QACnE,IAAI,CAAC;YACH,aAAa,CAAC,OAAO,CAAC,UAAA,YAAY,IAAI,OAAA,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,EAA7D,CAA6D,CAAC,CAAA;YACpG,IAAM,gBAAgB,GAAG,aAAa,CAAC,GAAG,CAAC,UAAA,YAAY,IAAI,OAAA,CAAE,YAAY,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAE,EAAjE,CAAiE,CAAC,CAAA;YAC7H,OAAO,CAAC,gBAAgB,CAAC,CAAA;QAC3B,CAAC;QAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,CAAA;QACf,CAAC;IACH,CAAC,CAAC,EARuC,CAQvC;CACH,CAAA;AAED,sIAAsI;AACtI,0CAA0C;AAC1C,sIAAsI;AAEtI,IAAM,OAAO,GAAG,MAAM,CAAC,YAAY,GAAG,iBAAiB,GAAG,2BAAY,CAAA;AACtE,kBAAe,OAAO,CAAA"} \ No newline at end of file diff --git a/dist/actions.js b/dist/actions.js index c66a776..ffb4a02 100644 --- a/dist/actions.js +++ b/dist/actions.js @@ -34,9 +34,11 @@ 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 }); var axios_1 = require("axios"); var types_1 = require("./types"); +var Storage_1 = require("./Storage"); var auth_1 = require("./services/auth"); // <- maybe this is where you pass in the platform paramter, specifying if it is for a browser or for React Native //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Pure Redux actions: @@ -215,51 +217,72 @@ var generateAuthActions = function (config) { }; }; var signOutUser = function () { return function (dispatch) { return __awaiter(this, void 0, void 0, function () { - var userSignOutCredentials, error_4; - return __generator(this, function (_a) { - switch (_a.label) { + var userSignOutCredentials, _a, _b, error_4; + return __generator(this, function (_c) { + switch (_c.label) { case 0: - userSignOutCredentials = { - 'access-token': localStorage.getItem('access-token'), - client: localStorage.getItem('client'), - uid: localStorage.getItem('uid'), - }; - dispatch(exports.signOutRequestSent()); - _a.label = 1; + _a = {}; + _b = 'access-token'; + return [4 /*yield*/, Storage_1.default.getItem('access-token')]; case 1: - _a.trys.push([1, 3, , 4]); + _a[_b] = (_c.sent()); + return [4 /*yield*/, Storage_1.default.getItem('client')]; + case 2: + _a.client = (_c.sent()); + return [4 /*yield*/, Storage_1.default.getItem('uid')]; + case 3: + userSignOutCredentials = (_a.uid = (_c.sent()), + _a); + dispatch(exports.signOutRequestSent()); + _c.label = 4; + case 4: + _c.trys.push([4, 6, , 7]); return [4 /*yield*/, axios_1.default({ method: 'DELETE', url: authUrl + "/sign_out", data: userSignOutCredentials, })]; - case 2: - _a.sent(); + case 5: + _c.sent(); auth_1.deleteAuthHeaders(); // Have to check what type of platform it is, depending on the key provided by the end-user... like "browser", "iphone", or "android", etc.: auth_1.deleteAuthHeadersFromLocalStorage(); dispatch(exports.signOutRequestSucceeded()); - return [3 /*break*/, 4]; - case 3: - error_4 = _a.sent(); + return [3 /*break*/, 7]; + case 6: + error_4 = _c.sent(); dispatch(exports.signOutRequestFailed()); throw error_4; - case 4: return [2 /*return*/]; + case 7: return [2 /*return*/]; } }); }); }; }; - var verifyCredentials = function (store) { - // Gotta check what the platform is: - if (localStorage.getItem('access-token')) { - var verificationParams = { - 'access-token': localStorage.getItem('access-token'), - client: localStorage.getItem('client'), - uid: localStorage.getItem('uid'), - }; - store.dispatch(verifyToken(verificationParams)); - } - }; + var verifyCredentials = function (store) { return __awaiter(_this, void 0, void 0, function () { + var verificationParams, _a, _b; + return __generator(this, function (_c) { + switch (_c.label) { + case 0: return [4 /*yield*/, Storage_1.default.getItem('access-token')]; + case 1: + if (!_c.sent()) return [3 /*break*/, 5]; + _a = {}; + _b = 'access-token'; + return [4 /*yield*/, Storage_1.default.getItem('access-token')]; + case 2: + _a[_b] = (_c.sent()); + return [4 /*yield*/, Storage_1.default.getItem('client')]; + case 3: + _a.client = (_c.sent()); + return [4 /*yield*/, Storage_1.default.getItem('uid')]; + case 4: + verificationParams = (_a.uid = (_c.sent()), + _a); + store.dispatch(verifyToken(verificationParams)); + _c.label = 5; + case 5: return [2 /*return*/]; + } + }); + }); }; return { registerUser: registerUser, verifyToken: verifyToken, diff --git a/dist/actions.js.map b/dist/actions.js.map index 33aa3d3..1ffc7ce 100644 --- a/dist/actions.js.map +++ b/dist/actions.js.map @@ -1 +1 @@ -{"version":3,"file":"actions.js","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAyB;AAKzB,iCAgCgB;AAChB,wCAMwB,CAAC,kHAAkH;AAE3I,wHAAwH;AACxH,sBAAsB;AACtB,wHAAwH;AAE3G,QAAA,uBAAuB,GAAG,cAAqC,OAAA,CAAC;IAC3E,IAAI,EAAE,iCAAyB;CAChC,CAAC,EAF0E,CAE1E,CAAA;AAEW,QAAA,4BAA4B,GAAG,UAAC,cAA8B,IAAyC,OAAA,CAAC;IACnH,IAAI,EAAE,sCAA8B;IACpC,OAAO,EAAE;QACP,cAAc,gBAAA;KACf;CACF,CAAC,EALkH,CAKlH,CAAA;AAEW,QAAA,yBAAyB,GAAG,cAAuC,OAAA,CAAC;IAC/E,IAAI,EAAE,mCAA2B;CAClC,CAAC,EAF8E,CAE9E,CAAA;AAEW,QAAA,sBAAsB,GAAG,cAAoC,OAAA,CAAC;IACzE,IAAI,EAAE,iCAAyB;CAChC,CAAC,EAFwE,CA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5B,qBAAM,eAAK,CAAC;gCACV,MAAM,EAAE,QAAQ;gCAChB,GAAG,EAAK,OAAO,cAAW;gCAC1B,IAAI,EAAE,sBAAsB;6BAC7B,CAAC,EAAA;;wBAJF,SAIE,CAAA;wBACF,wBAAiB,EAAE,CAAA;wBACnB,4IAA4I;wBAC5I,wCAAiC,EAAE,CAAA;wBACnC,QAAQ,CAAC,+BAAuB,EAAE,CAAC,CAAA;;;;wBAEnC,QAAQ,CAAC,4BAAoB,EAAE,CAAC,CAAA;wBAChC,MAAM,OAAK,CAAA;;;;;KAEd,EArByB,CAqBzB,CAAA;IAED,IAAM,iBAAiB,GAAG,UAAO,KAAgB;;;;wBAE3C,qBAAM,iBAAO,CAAC,OAAO,CAAC,cAAc,CAAC,EAAA;;yBAArC,SAAqC,EAArC,wBAAqC;;oBAErC,KAAA,cAAc,CAAA;oBAAE,qBAAM,iBAAO,CAAC,OAAO,CAAC,cAAc,CAAC,EAAA;;oBAArD,MAAc,IAAE,SAA+C,CAAA;oBACvD,qBAAM,iBAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAA;;oBAAvC,SAAM,IAAE,SAAyC,CAAA;oBAC5C,qBAAM,iBAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAA;;oBAH7B,kBAAkB,IAGtB,MAAG,IAAE,SAAsC,CAAA;2BAC5C;oBACD,KAAK,CAAC,QAAQ,CAAM,WAAW,CAAC,kBAAkB,CAAC,CAAC,CAAA;;;;;SAEvD,CAAA;IAED,MAAM,CAAC;QACL,YAAY,cAAA;QACZ,WAAW,aAAA;QACX,UAAU,YAAA;QACV,WAAW,aAAA;QACX,iBAAiB,mBAAA;KAClB,CAAA;AACH,CAAC,CAAA;AAED,kBAAe,mBAAmB,CAAA"} \ No newline at end of file diff --git a/dist/services/auth.js b/dist/services/auth.js index 6c5d715..3bb52ff 100644 --- a/dist/services/auth.js +++ b/dist/services/auth.js @@ -38,81 +38,7 @@ var _this = this; Object.defineProperty(exports, "__esModule", { value: true }); var axios_1 = require("axios"); var utility_1 = require("./utility"); -var react_native_1 = require("react-native"); -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Rip this out into its own npm package: -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -var AsyncLocalStorage = { - getItem: function (key) { return new Promise(function (resolve, reject) { - try { - var value = window.localStorage.getItem(key); - resolve(value); - } - catch (error) { - reject(error); - } - }); }, - setItem: function (key, value) { return new Promise(function (resolve, reject) { - try { - window.localStorage.setItem(key, value); - resolve(value); - } - catch (error) { - reject(error); - } - }); }, - removeItem: function (key) { return new Promise(function (resolve, reject) { - try { - var value = window.localStorage.getItem(key); - window.localStorage.removeItem(key); - resolve(value); - } - catch (error) { - reject(error); - } - }); }, - clear: function () { return new Promise(function (resolve, reject) { - try { - window.localStorage.clear(); - resolve(true); - } - catch (error) { - reject(error); - } - }); }, - getAllKeys: function () { return new Promise(function (resolve, reject) { - try { - var allKeys = Object.keys(window.localStorage); - resolve(allKeys); - } - catch (error) { - reject(error); - } - }); }, - multiGet: function (keys) { return new Promise(function (resolve, reject) { - try { - var values = keys.map(function (key) { return [key, window.localStorage.getItem(key)]; }); - resolve(values); - } - catch (error) { - reject(error); - } - }); }, - multiSet: function (keyValuePairs) { return new Promise(function (resolve, reject) { - try { - keyValuePairs.forEach(function (keyValuePair) { return window.localStorage.setItem(keyValuePair[0], keyValuePair[1]); }); - var newKeyValuePairs = keyValuePairs.map(function (keyValuePair) { return [keyValuePair[0], window.localStorage.getItem(keyValuePair[0])]; }); - resolve(newKeyValuePairs); - } - catch (error) { - reject(error); - } - }); }, -}; -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// ^ Rip this out into its own npm package -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -var Storage = window.localStorage ? AsyncLocalStorage : react_native_1.AsyncStorage; +var Storage_1 = require("../Storage"); // try { // Storage = AsyncStorage // } catch (e) { @@ -134,7 +60,7 @@ exports.setAuthHeaders = function (headers) { exports.persistAuthHeadersInLocalStorage = function (headers) { // use multiSet: authHeaderKeys.forEach(function (key) { - Storage.setItem(key, headers[key]); + Storage_1.default.setItem(key, headers[key]); }); }; exports.deleteAuthHeaders = function () { @@ -147,7 +73,7 @@ exports.deleteAuthHeadersFromLocalStorage = function () { return __awaiter(_this return __generator(this, function (_a) { // can use multiRemove once you've written it: authHeaderKeys.forEach(function (key) { - Storage.removeItem(key); + Storage_1.default.removeItem(key); // localStorage.removeItem(key) }); return [2 /*return*/]; diff --git a/dist/services/auth.js.map b/dist/services/auth.js.map index a5b1f70..b8c9fd2 100644 --- a/dist/services/auth.js.map +++ b/dist/services/auth.js.map @@ -1 +1 @@ -{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/services/auth.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBA+IA;;AA/IA,+BAAyB;AACzB,qCAAkD;AAMlD,6CAA2C;AAE3C,sIAAsI;AACtI,yCAAyC;AACzC,sIAAsI;AAEtI,IAAM,iBAAiB,GAAG;IACxB,OAAO,EAAE,UAAC,GAAW,IAAmB,OAAA,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;QAClE,IAAI,CAAC;YACH,IAAM,KAAK,GAAkB,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;YAC7D,OAAO,CAAC,KAAK,CAAC,CAAA;QAChB,CAAC;QAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,CAAA;QACf,CAAC;IACH,CAAC,CAAC,EAPsC,CAOtC;IAEF,OAAO,EAAE,UAAC,GAAW,EAAE,KAAa,IAAK,OAAA,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;QACnE,IAAI,CAAC;YACH,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;YACvC,OAAO,CAAC,KAA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AC/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,CAAC,CAAA;AAED,iHAAiH;AACpG,QAAA,iCAAiC,GAAG;;QAC/C,8CAA8C;QAC9C,cAAc,CAAC,OAAO,CAAC,UAAC,GAAW;YACjC,iBAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;YACvB,+BAA+B;QACjC,CAAC,CAAC,CAAA;;;KACH,CAAA;AAEY,QAAA,6BAA6B,GAAG,UAC3C,cAAoC,EACpC,QAAsB;IAEtB,IAAM,sBAAsB,GAAyB,gCAAsB,CAAC,cAAc,CAAC,CAAA;IAC3F,IAAM,yBAAyB,GAAa,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAA;IAC/E,IAAM,sBAAsB,GAAyB,EAAE,CAAA;IACvD,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,UAAC,GAAW;QAClD,EAAE,CAAC,CAAC,yBAAyB,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YAClD,sBAAsB,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAC/E,CAAC;IACH,CAAC,CAAC,CAAA;IACF,MAAM,CAAC,sBAAsB,CAAA;AAC/B,CAAC,CAAA"} \ No newline at end of file diff --git a/src/Storage.ts b/src/Storage.ts new file mode 100644 index 0000000..0902f49 --- /dev/null +++ b/src/Storage.ts @@ -0,0 +1,79 @@ +import { AsyncStorage } from 'react-native' + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Rip this out into its own npm package: +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +const AsyncLocalStorage = { + getItem: (key: string): Promise => new Promise((resolve, reject) => { + try { + const value: string | null = window.localStorage.getItem(key) + resolve(value) + } catch (error) { + reject(error) + } + }), + + setItem: (key: string, value: string) => new Promise((resolve, reject) => { + try { + window.localStorage.setItem(key, value) + resolve(value) + } catch (error) { + reject(error) + } + }), + + removeItem: (key: string): Promise => new Promise((resolve, reject) => { + try { + const value: string | null = window.localStorage.getItem(key) + window.localStorage.removeItem(key) + resolve(value) + } catch (error) { + reject(error) + } + }), + + clear: () => new Promise((resolve, reject) => { + try { + window.localStorage.clear() + resolve(true) + } catch (error) { + reject(error) + } + }), + + getAllKeys: () => new Promise((resolve, reject) => { + try { + const allKeys = Object.keys(window.localStorage) + resolve(allKeys) + } catch (error) { + reject(error) + } + }), + + multiGet: (keys: string[]) => new Promise((resolve, reject) => { + try { + const values = keys.map(key => [ key, window.localStorage.getItem(key) ]) + resolve(values) + } catch (error) { + reject(error) + } + }), + + multiSet: (keyValuePairs: string[][]) => new Promise((resolve, reject) => { + try { + keyValuePairs.forEach(keyValuePair => window.localStorage.setItem(keyValuePair[0], keyValuePair[1])) + const newKeyValuePairs = keyValuePairs.map(keyValuePair => [ keyValuePair[0], window.localStorage.getItem(keyValuePair[0]) ]) + resolve(newKeyValuePairs) + } catch (error) { + reject(error) + } + }), +} + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// ^ Rip this out into its own npm package +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +const Storage = window.localStorage ? AsyncLocalStorage : AsyncStorage +export default Storage diff --git a/src/actions.ts b/src/actions.ts index 808f930..52a3e3f 100644 --- a/src/actions.ts +++ b/src/actions.ts @@ -36,6 +36,7 @@ import { SignOutRequestSucceededAction, SignOutRequestFailedAction, } from './types' +import Storage from './Storage' import { deleteAuthHeaders, deleteAuthHeadersFromLocalStorage, @@ -214,9 +215,9 @@ const generateAuthActions = (config: { [key: string]: any }): ActionsExport => { const signOutUser = () => async function (dispatch: Dispatch<{}>): Promise { const userSignOutCredentials: UserSignOutCredentials = { - 'access-token': localStorage.getItem('access-token') as string, - client: localStorage.getItem('client') as string, - uid: localStorage.getItem('uid') as string, + 'access-token': await Storage.getItem('access-token') as string, + client: await Storage.getItem('client') as string, + uid: await Storage.getItem('uid') as string, } dispatch(signOutRequestSent()) try { @@ -235,13 +236,13 @@ const generateAuthActions = (config: { [key: string]: any }): ActionsExport => { } } - const verifyCredentials = (store: Store<{}>): void => { + const verifyCredentials = async (store: Store<{}>): Promise => { // Gotta check what the platform is: - if (localStorage.getItem('access-token')) { + if (await Storage.getItem('access-token')) { const verificationParams: VerificationParams = { - 'access-token': localStorage.getItem('access-token') as string, - client: localStorage.getItem('client') as string, - uid: localStorage.getItem('uid') as string, + 'access-token': await Storage.getItem('access-token') as string, + client: await Storage.getItem('client') as string, + uid: await Storage.getItem('uid') as string, } store.dispatch(verifyToken(verificationParams)) } diff --git a/src/services/auth.ts b/src/services/auth.ts index 464bcf5..49842c8 100644 --- a/src/services/auth.ts +++ b/src/services/auth.ts @@ -5,84 +5,7 @@ import { AuthResponse, SingleLayerStringMap, } from '../types' -import { AsyncStorage } from 'react-native' - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Rip this out into its own npm package: -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -const AsyncLocalStorage = { - getItem: (key: string): Promise => new Promise((resolve, reject) => { - try { - const value: string | null = window.localStorage.getItem(key) - resolve(value) - } catch (error) { - reject(error) - } - }), - - setItem: (key: string, value: string) => new Promise((resolve, reject) => { - try { - window.localStorage.setItem(key, value) - resolve(value) - } catch (error) { - reject(error) - } - }), - - removeItem: (key: string): Promise => new Promise((resolve, reject) => { - try { - const value: string | null = window.localStorage.getItem(key) - window.localStorage.removeItem(key) - resolve(value) - } catch (error) { - reject(error) - } - }), - - clear: () => new Promise((resolve, reject) => { - try { - window.localStorage.clear() - resolve(true) - } catch (error) { - reject(error) - } - }), - - getAllKeys: () => new Promise((resolve, reject) => { - try { - const allKeys = Object.keys(window.localStorage) - resolve(allKeys) - } catch (error) { - reject(error) - } - }), - - multiGet: (keys: string[]) => new Promise((resolve, reject) => { - try { - const values = keys.map(key => [ key, window.localStorage.getItem(key) ]) - resolve(values) - } catch (error) { - reject(error) - } - }), - - multiSet: (keyValuePairs: string[][]) => new Promise((resolve, reject) => { - try { - keyValuePairs.forEach(keyValuePair => window.localStorage.setItem(keyValuePair[0], keyValuePair[1])) - const newKeyValuePairs = keyValuePairs.map(keyValuePair => [ keyValuePair[0], window.localStorage.getItem(keyValuePair[0]) ]) - resolve(newKeyValuePairs) - } catch (error) { - reject(error) - } - }), -} - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// ^ Rip this out into its own npm package -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -let Storage = window.localStorage ? AsyncLocalStorage : AsyncStorage +import Storage from '../Storage' // try { // Storage = AsyncStorage