Comparing version 0.3.3 to 0.3.4
@@ -25,2 +25,10 @@ 'use strict'; | ||
var noopStorageBackend = { | ||
getItem: function getItem() { | ||
return null; | ||
}, | ||
setItem: function setItem() {}, | ||
removeItem: function removeItem() {} | ||
}; | ||
var makeAuth = function makeAuth(_ref) { | ||
@@ -52,2 +60,3 @@ var _marked = /*#__PURE__*/_regenerator2.default.mark(ls), | ||
refreshTokenCall = _ref.refreshTokenCall, | ||
storageBackend = _ref.storageBackend, | ||
_ref$reduxMountPoint = _ref.reduxMountPoint, | ||
@@ -61,3 +70,17 @@ reduxMountPoint = _ref$reduxMountPoint === undefined ? 'auth' : _ref$reduxMountPoint, | ||
// redux saga helpers for Local Storage | ||
var choosedStoageBackend = void 0; | ||
if (typeof storageBackend === 'undefined' || storageBackend === null) { | ||
if (typeof window !== 'undefined' && typeof window.localStorage !== 'undefined') { | ||
// If provided by environment use local storage | ||
choosedStoageBackend = window.localStorage; | ||
} else { | ||
// Use a noop storage backend (don't store anything) | ||
choosedStoageBackend = noopStorageBackend; | ||
} | ||
} else { | ||
// When given use provided storage backend | ||
choosedStoageBackend = storageBackend; | ||
} | ||
// redux saga helpers for Stroage Backend | ||
function ls(method) { | ||
@@ -80,3 +103,3 @@ var _len, | ||
_context.next = 4; | ||
return _effects.call.apply(undefined, [[window.localStorage, method]].concat(args)); | ||
return _effects.call.apply(undefined, [[choosedStoageBackend, method]].concat(args)); | ||
@@ -83,0 +106,0 @@ case 4: |
{ | ||
"name": "eazy-auth", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"description": "Easy auth stuff with redux", | ||
@@ -36,2 +36,3 @@ "main": "lib/index.js", | ||
"redux-saga": "^0.16.0", | ||
"reselect": "^3.0.1", | ||
"rimraf": "^2.6.2", | ||
@@ -49,5 +50,5 @@ "style-loader": "^0.20.1", | ||
"react-redux": "^4.3.0 || ^5.0.0", | ||
"react-router-dom": "^4.1.x", | ||
"redux": "^3.0.0", | ||
"redux-saga": ">=0.15.0", | ||
"react-router-dom": "^4.1.x" | ||
"redux-saga": ">=0.15.0" | ||
}, | ||
@@ -54,0 +55,0 @@ "keywords": [ |
@@ -18,2 +18,8 @@ import { take, call, put, select, fork, cancel } from 'redux-saga/effects' | ||
const noopStorageBackend = { | ||
getItem: () => null, | ||
setItem: () => {}, | ||
removeItem: () => {}, | ||
} | ||
const makeAuth = ({ | ||
@@ -24,2 +30,3 @@ // Do the me call using after login to get | ||
refreshTokenCall, | ||
storageBackend, | ||
reduxMountPoint = 'auth', | ||
@@ -30,6 +37,23 @@ localStorageNamespace = 'auth', | ||
// redux saga helpers for Local Storage | ||
let choosedStoageBackend | ||
if (typeof storageBackend === 'undefined' || storageBackend === null) { | ||
if ( | ||
typeof window !== 'undefined' && | ||
typeof window.localStorage !== 'undefined' | ||
) { | ||
// If provided by environment use local storage | ||
choosedStoageBackend = window.localStorage | ||
} else { | ||
// Use a noop storage backend (don't store anything) | ||
choosedStoageBackend = noopStorageBackend | ||
} | ||
} else { | ||
// When given use provided storage backend | ||
choosedStoageBackend = storageBackend | ||
} | ||
// redux saga helpers for Stroage Backend | ||
function *ls(method, ...args) { | ||
try { | ||
return yield call([window.localStorage, method], ...args) | ||
return yield call([choosedStoageBackend, method], ...args) | ||
} catch (e) { | ||
@@ -36,0 +60,0 @@ // Such shitty friend like mobile safari anonymous navigaton |
Sorry, the diff of this file is not supported yet
348447
3926
25