ackee-redux-token-auth
Advanced tools
Comparing version 1.0.1 to 1.1.0
{ | ||
"env": { | ||
"browser": true | ||
}, | ||
"extends": ["ackee"], | ||
"parser": "babel-eslint", | ||
"parserOptions": { | ||
"ecmaFeatures": { | ||
"experimentalObjectRestSpread": true, | ||
"jsx": true | ||
"env": { | ||
"browser": true | ||
}, | ||
"sourceType": "module" | ||
} | ||
"extends": ["ackee", "prettier"], | ||
"parser": "babel-eslint", | ||
"parserOptions": { | ||
"ecmaFeatures": { | ||
"experimentalObjectRestSpread": true, | ||
"jsx": true | ||
}, | ||
"sourceType": "module" | ||
} | ||
} |
@@ -1,69 +0,161 @@ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
exports.stopTokenRefresh = exports.startTokenRefresh = exports.refreshTokens = exports.setTokens = exports.logout = exports.stopLogin = exports.login = undefined; | ||
exports.authSessionResume = exports.authSessionPause = exports.authSessionEnd = exports.authSessionStart = exports.accessTokenUnavailable = exports.accessTokenAvailable = exports.fetchAuthUserFailure = exports.fetchAuthUserSuccess = exports.fetchAuthUserRequest = exports.stopTokenRefresh = exports.startTokenRefresh = exports.refreshTokens = exports.setTokens = exports.logout = exports.stopLogin = exports.login = void 0; | ||
var _actionType = require('./actionType'); | ||
var _actionType = require("./actionType"); | ||
var login = exports.login = function login(credentials) { | ||
return { | ||
type: _actionType.AUTH_LOGIN, | ||
credentials: credentials | ||
}; | ||
var login = function login(credentials) { | ||
return { | ||
type: _actionType.AUTH_LOGIN, | ||
credentials: credentials | ||
}; | ||
}; | ||
var stopLogin = exports.stopLogin = function stopLogin(error, user) { | ||
if (error) { | ||
return { | ||
type: _actionType.AUTH_LOGIN_FAILURE, | ||
error: error | ||
}; | ||
} | ||
exports.login = login; | ||
var stopLogin = function stopLogin(error, user) { | ||
if (error) { | ||
return { | ||
type: _actionType.AUTH_LOGIN_SUCCESS, | ||
user: user | ||
type: _actionType.AUTH_LOGIN_FAILURE, | ||
error: error | ||
}; | ||
} | ||
return { | ||
type: _actionType.AUTH_LOGIN_SUCCESS, | ||
user: user | ||
}; | ||
}; | ||
var logout = exports.logout = function logout() { | ||
return { | ||
type: _actionType.AUTH_LOGOUT | ||
}; | ||
exports.stopLogin = stopLogin; | ||
var logout = function logout() { | ||
return { | ||
type: _actionType.AUTH_LOGOUT | ||
}; | ||
}; | ||
var setTokens = exports.setTokens = function setTokens(tokens) { | ||
return { | ||
type: _actionType.SET_AUTH_TOKENS, | ||
tokens: tokens | ||
}; | ||
exports.logout = logout; | ||
var setTokens = function setTokens(tokens) { | ||
return { | ||
type: _actionType.SET_AUTH_TOKENS, | ||
tokens: tokens | ||
}; | ||
}; | ||
var refreshTokens = exports.refreshTokens = function refreshTokens() { | ||
return { | ||
type: _actionType.PROCESS_TOKEN_REFRESH | ||
}; | ||
exports.setTokens = setTokens; | ||
var refreshTokens = function refreshTokens(tokens) { | ||
return { | ||
type: _actionType.PROCESS_TOKEN_REFRESH, | ||
tokens: tokens | ||
}; | ||
}; | ||
var startTokenRefresh = exports.startTokenRefresh = function startTokenRefresh(refreshToken) { | ||
exports.refreshTokens = refreshTokens; | ||
var startTokenRefresh = function startTokenRefresh(refreshToken) { | ||
return { | ||
type: _actionType.AUTH_REFRESH_TOKEN, | ||
refreshToken: refreshToken | ||
}; | ||
}; | ||
exports.startTokenRefresh = startTokenRefresh; | ||
var stopTokenRefresh = function stopTokenRefresh(error) { | ||
var tokens = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (error) { | ||
return { | ||
type: _actionType.AUTH_REFRESH_TOKEN, | ||
refreshToken: refreshToken | ||
type: _actionType.AUTH_REFRESH_TOKEN_FAILURE, | ||
error: error | ||
}; | ||
} | ||
return { | ||
type: _actionType.AUTH_REFRESH_TOKEN_SUCCESS, | ||
tokens: tokens | ||
}; | ||
}; | ||
var stopTokenRefresh = exports.stopTokenRefresh = function stopTokenRefresh(error) { | ||
var tokens = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
exports.stopTokenRefresh = stopTokenRefresh; | ||
if (error) { | ||
return { | ||
type: _actionType.AUTH_REFRESH_TOKEN_FAILURE, | ||
error: error | ||
}; | ||
} | ||
return { | ||
type: _actionType.AUTH_REFRESH_TOKEN_SUCCESS, | ||
tokens: tokens | ||
}; | ||
}; | ||
var fetchAuthUserRequest = function fetchAuthUserRequest() { | ||
return { | ||
type: _actionType.FETCH_AUTH_USER_REQUEST | ||
}; | ||
}; | ||
exports.fetchAuthUserRequest = fetchAuthUserRequest; | ||
var fetchAuthUserSuccess = function fetchAuthUserSuccess(user) { | ||
return { | ||
type: _actionType.FETCH_AUTH_USER_SUCCESS, | ||
user: user | ||
}; | ||
}; | ||
exports.fetchAuthUserSuccess = fetchAuthUserSuccess; | ||
var fetchAuthUserFailure = function fetchAuthUserFailure(error) { | ||
return { | ||
type: _actionType.FETCH_AUTH_USER_FAILURE, | ||
error: error | ||
}; | ||
}; | ||
exports.fetchAuthUserFailure = fetchAuthUserFailure; | ||
var accessTokenAvailable = function accessTokenAvailable(accessToken) { | ||
return { | ||
type: _actionType.ACCESS_TOKEN_AVAILABLE, | ||
payload: accessToken | ||
}; | ||
}; | ||
exports.accessTokenAvailable = accessTokenAvailable; | ||
var accessTokenUnavailable = function accessTokenUnavailable() { | ||
return { | ||
type: _actionType.ACCESS_TOKEN_UNAVAILABLE | ||
}; | ||
}; | ||
exports.accessTokenUnavailable = accessTokenUnavailable; | ||
var authSessionStart = function authSessionStart() { | ||
return { | ||
type: _actionType.AUTH_SESSION_START | ||
}; | ||
}; | ||
exports.authSessionStart = authSessionStart; | ||
var authSessionEnd = function authSessionEnd() { | ||
return { | ||
type: _actionType.AUTH_SESSION_END | ||
}; | ||
}; | ||
exports.authSessionEnd = authSessionEnd; | ||
var authSessionPause = function authSessionPause() { | ||
return { | ||
type: _actionType.AUTH_SESSION_PAUSE | ||
}; | ||
}; | ||
exports.authSessionPause = authSessionPause; | ||
var authSessionResume = function authSessionResume() { | ||
return { | ||
type: _actionType.AUTH_SESSION_RESUME | ||
}; | ||
}; | ||
exports.authSessionResume = authSessionResume; |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,13 +6,38 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
var AUTH_LOGIN = exports.AUTH_LOGIN = 'AUTH_LOGIN'; | ||
var AUTH_LOGIN_SUCCESS = exports.AUTH_LOGIN_SUCCESS = 'AUTH_LOGIN_SUCCESS'; | ||
var AUTH_LOGIN_FAILURE = exports.AUTH_LOGIN_FAILURE = 'AUTH_LOGIN_FAILURE'; | ||
var AUTH_LOGOUT = exports.AUTH_LOGOUT = 'AUTH_LOGOUT'; | ||
var SET_AUTH_TOKENS = exports.SET_AUTH_TOKENS = 'SET_AUTH_TOKENS'; | ||
var AUTH_REFRESH_TOKEN = exports.AUTH_REFRESH_TOKEN = 'AUTH_REFRESH_TOKEN'; | ||
var AUTH_REFRESH_TOKEN_SUCCESS = exports.AUTH_REFRESH_TOKEN_SUCCESS = 'AUTH_REFRESH_TOKEN_SUCCESS'; | ||
var AUTH_REFRESH_TOKEN_FAILURE = exports.AUTH_REFRESH_TOKEN_FAILURE = 'AUTH_REFRESH_TOKEN_FAILURE'; | ||
var PROCESS_TOKEN_REFRESH = exports.PROCESS_TOKEN_REFRESH = 'PROCESS_TOKEN_REFRESH'; | ||
exports.AUTH_SESSION_RESUME = exports.AUTH_SESSION_PAUSE = exports.AUTH_SESSION_END = exports.AUTH_SESSION_START = exports.ACCESS_TOKEN_UNAVAILABLE = exports.ACCESS_TOKEN_AVAILABLE = exports.FETCH_AUTH_USER_FAILURE = exports.FETCH_AUTH_USER_SUCCESS = exports.FETCH_AUTH_USER_REQUEST = exports.PROCESS_TOKEN_REFRESH = exports.AUTH_REFRESH_TOKEN_FAILURE = exports.AUTH_REFRESH_TOKEN_SUCCESS = exports.AUTH_REFRESH_TOKEN = exports.SET_AUTH_TOKENS = exports.AUTH_LOGOUT = exports.AUTH_LOGIN_FAILURE = exports.AUTH_LOGIN_SUCCESS = exports.AUTH_LOGIN = void 0; | ||
var AUTH_LOGIN = '@@redux-token-auth/AUTH_LOGIN'; | ||
exports.AUTH_LOGIN = AUTH_LOGIN; | ||
var AUTH_LOGIN_SUCCESS = '@@redux-token-auth/AUTH_LOGIN_SUCCESS'; | ||
exports.AUTH_LOGIN_SUCCESS = AUTH_LOGIN_SUCCESS; | ||
var AUTH_LOGIN_FAILURE = '@@redux-token-auth/AUTH_LOGIN_FAILURE'; | ||
exports.AUTH_LOGIN_FAILURE = AUTH_LOGIN_FAILURE; | ||
var AUTH_LOGOUT = '@@redux-token-auth/AUTH_LOGOUT'; | ||
exports.AUTH_LOGOUT = AUTH_LOGOUT; | ||
var SET_AUTH_TOKENS = '@@redux-token-auth/SET_AUTH_TOKENS'; | ||
exports.SET_AUTH_TOKENS = SET_AUTH_TOKENS; | ||
var AUTH_REFRESH_TOKEN = '@@redux-token-auth/AUTH_REFRESH_TOKEN'; | ||
exports.AUTH_REFRESH_TOKEN = AUTH_REFRESH_TOKEN; | ||
var AUTH_REFRESH_TOKEN_SUCCESS = '@@redux-token-auth/AUTH_REFRESH_TOKEN_SUCCESS'; | ||
exports.AUTH_REFRESH_TOKEN_SUCCESS = AUTH_REFRESH_TOKEN_SUCCESS; | ||
var AUTH_REFRESH_TOKEN_FAILURE = '@@redux-token-auth/AUTH_REFRESH_TOKEN_FAILURE'; | ||
exports.AUTH_REFRESH_TOKEN_FAILURE = AUTH_REFRESH_TOKEN_FAILURE; | ||
var PROCESS_TOKEN_REFRESH = '@@redux-token-auth/PROCESS_TOKEN_REFRESH'; | ||
exports.PROCESS_TOKEN_REFRESH = PROCESS_TOKEN_REFRESH; | ||
var FETCH_AUTH_USER_REQUEST = '@@redux-token-auth/FETCH_AUTH_USER_REQUEST'; | ||
exports.FETCH_AUTH_USER_REQUEST = FETCH_AUTH_USER_REQUEST; | ||
var FETCH_AUTH_USER_SUCCESS = '@@redux-token-auth/FETCH_AUTH_USER_SUCCESS'; | ||
exports.FETCH_AUTH_USER_SUCCESS = FETCH_AUTH_USER_SUCCESS; | ||
var FETCH_AUTH_USER_FAILURE = '@@redux-token-auth/FETCH_AUTH_USER_FAILURE'; | ||
exports.FETCH_AUTH_USER_FAILURE = FETCH_AUTH_USER_FAILURE; | ||
var ACCESS_TOKEN_AVAILABLE = '@@redux-token-auth/ACCESS_TOKEN_AVAILABLE'; | ||
exports.ACCESS_TOKEN_AVAILABLE = ACCESS_TOKEN_AVAILABLE; | ||
var ACCESS_TOKEN_UNAVAILABLE = '@@redux-token-auth/ACCESS_TOKEN_UNAVAILABLE'; | ||
exports.ACCESS_TOKEN_UNAVAILABLE = ACCESS_TOKEN_UNAVAILABLE; | ||
var AUTH_SESSION_START = '@@redux-token-auth/AUTH_SESSION_START'; | ||
exports.AUTH_SESSION_START = AUTH_SESSION_START; | ||
var AUTH_SESSION_END = '@@redux-token-auth/AUTH_SESSION_END'; | ||
exports.AUTH_SESSION_END = AUTH_SESSION_END; | ||
var AUTH_SESSION_PAUSE = '@@redux-token-auth/AUTH_SESSION_PAUSE'; | ||
exports.AUTH_SESSION_PAUSE = AUTH_SESSION_PAUSE; | ||
var AUTH_SESSION_RESUME = '@@redux-token-auth/AUTH_SESSION_RESUME'; | ||
exports.AUTH_SESSION_RESUME = AUTH_SESSION_RESUME; |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,3 +6,6 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
var reducerName = exports.reducerName = 'auth'; | ||
var logger = exports.logger = console; | ||
exports.logger = exports.reducerName = void 0; | ||
var reducerName = 'auth'; | ||
exports.reducerName = reducerName; | ||
var logger = console; | ||
exports.logger = logger; |
135
lib/index.js
@@ -1,64 +0,29 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _actionType = require('./actionType'); | ||
Object.defineProperty(exports, 'AUTH_LOGIN_SUCCESS', { | ||
var _exportNames = { | ||
actionTypes: true, | ||
authUser: true, | ||
isLoggedIn: true, | ||
isLoggingIn: true, | ||
loginErrors: true, | ||
login: true, | ||
stopLogin: true, | ||
logout: true, | ||
setTokens: true, | ||
refreshTokens: true, | ||
reducer: true, | ||
constants: true | ||
}; | ||
Object.defineProperty(exports, "authUser", { | ||
enumerable: true, | ||
get: function get() { | ||
return _actionType.AUTH_LOGIN_SUCCESS; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'AUTH_LOGIN_FAILURE', { | ||
enumerable: true, | ||
get: function get() { | ||
return _actionType.AUTH_LOGIN_FAILURE; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'AUTH_LOGOUT', { | ||
enumerable: true, | ||
get: function get() { | ||
return _actionType.AUTH_LOGOUT; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'SET_AUTH_TOKENS', { | ||
enumerable: true, | ||
get: function get() { | ||
return _actionType.SET_AUTH_TOKENS; | ||
} | ||
}); | ||
var _saga = require('./saga'); | ||
Object.defineProperty(exports, 'configure', { | ||
enumerable: true, | ||
get: function get() { | ||
return _saga.configure; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'authorizedFn', { | ||
enumerable: true, | ||
get: function get() { | ||
return _saga.authorizedFn; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'saga', { | ||
enumerable: true, | ||
get: function get() { | ||
return _saga.saga; | ||
} | ||
}); | ||
var _selectors = require('./selectors'); | ||
Object.defineProperty(exports, 'authUser', { | ||
enumerable: true, | ||
get: function get() { | ||
return _selectors.authUser; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'isLoggedIn', { | ||
Object.defineProperty(exports, "isLoggedIn", { | ||
enumerable: true, | ||
@@ -69,3 +34,3 @@ get: function get() { | ||
}); | ||
Object.defineProperty(exports, 'isLoggingIn', { | ||
Object.defineProperty(exports, "isLoggingIn", { | ||
enumerable: true, | ||
@@ -76,3 +41,3 @@ get: function get() { | ||
}); | ||
Object.defineProperty(exports, 'loginErrors', { | ||
Object.defineProperty(exports, "loginErrors", { | ||
enumerable: true, | ||
@@ -83,6 +48,3 @@ get: function get() { | ||
}); | ||
var _actions = require('./actions'); | ||
Object.defineProperty(exports, 'login', { | ||
Object.defineProperty(exports, "login", { | ||
enumerable: true, | ||
@@ -93,3 +55,3 @@ get: function get() { | ||
}); | ||
Object.defineProperty(exports, 'stopLogin', { | ||
Object.defineProperty(exports, "stopLogin", { | ||
enumerable: true, | ||
@@ -100,3 +62,3 @@ get: function get() { | ||
}); | ||
Object.defineProperty(exports, 'logout', { | ||
Object.defineProperty(exports, "logout", { | ||
enumerable: true, | ||
@@ -107,3 +69,3 @@ get: function get() { | ||
}); | ||
Object.defineProperty(exports, 'setTokens', { | ||
Object.defineProperty(exports, "setTokens", { | ||
enumerable: true, | ||
@@ -114,3 +76,3 @@ get: function get() { | ||
}); | ||
Object.defineProperty(exports, 'refreshTokens', { | ||
Object.defineProperty(exports, "refreshTokens", { | ||
enumerable: true, | ||
@@ -121,6 +83,3 @@ get: function get() { | ||
}); | ||
var _reducer = require('./reducer'); | ||
Object.defineProperty(exports, 'reducer', { | ||
Object.defineProperty(exports, "reducer", { | ||
enumerable: true, | ||
@@ -130,2 +89,40 @@ get: function get() { | ||
} | ||
}); | ||
}); | ||
exports.constants = exports.actionTypes = void 0; | ||
var _actionTypes = _interopRequireWildcard(require("./actionType")); | ||
exports.actionTypes = _actionTypes; | ||
Object.keys(_actionTypes).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _actionTypes[key]; | ||
} | ||
}); | ||
}); | ||
var _selectors = require("./selectors"); | ||
var _actions = require("./actions"); | ||
var _reducer = require("./reducer"); | ||
var _sagas = require("./sagas"); | ||
Object.keys(_sagas).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _sagas[key]; | ||
} | ||
}); | ||
}); | ||
var _constants = _interopRequireWildcard(require("./constants")); | ||
exports.constants = _constants; |
@@ -1,82 +0,105 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
exports.reducer = undefined; | ||
exports.reducer = void 0; | ||
var _extends2 = require('babel-runtime/helpers/extends'); | ||
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread")); | ||
var _extends3 = _interopRequireDefault(_extends2); | ||
var _actionType = require("./actionType"); | ||
var _actionType = require('./actionType'); | ||
var initialState = { | ||
user: null, | ||
isLoggedIn: false, | ||
isLoggingIn: false, | ||
loginError: null, | ||
tokens: {}, | ||
isRefreshing: false, | ||
isUserFetching: false | ||
}; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var reducer = function reducer() { | ||
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState; | ||
var action = arguments.length > 1 ? arguments[1] : undefined; | ||
var initialState = { | ||
user: null, | ||
isLoggedIn: false, | ||
isLoggingIn: false, | ||
loginError: null, | ||
tokens: {}, | ||
isRefreshing: false | ||
switch (action.type) { | ||
case _actionType.AUTH_LOGIN: | ||
return (0, _objectSpread2.default)({}, state, { | ||
isLoggedIn: false, | ||
isLoggingIn: true, | ||
loginError: null, | ||
isUserFetching: true | ||
}); | ||
case _actionType.AUTH_LOGIN_SUCCESS: | ||
return (0, _objectSpread2.default)({}, state, { | ||
isLoggedIn: true, | ||
isLoggingIn: false, | ||
user: action.user, | ||
loginError: null, | ||
isUserFetching: false | ||
}); | ||
case _actionType.AUTH_LOGIN_FAILURE: | ||
return (0, _objectSpread2.default)({}, state, { | ||
isLoggedIn: false, | ||
isLoggingIn: false, | ||
user: null, | ||
loginError: action.error, | ||
isUserFetching: false | ||
}); | ||
case _actionType.SET_AUTH_TOKENS: | ||
return (0, _objectSpread2.default)({}, state, { | ||
isLoggedIn: true, | ||
tokens: (0, _objectSpread2.default)({}, state.tokens, action.tokens) | ||
}); | ||
case _actionType.AUTH_LOGOUT: | ||
return (0, _objectSpread2.default)({}, state, { | ||
isLoggedIn: false, | ||
user: null, | ||
tokens: {} | ||
}); | ||
case _actionType.AUTH_REFRESH_TOKEN: | ||
return (0, _objectSpread2.default)({}, state, { | ||
isRefreshing: true | ||
}); | ||
case _actionType.AUTH_REFRESH_TOKEN_SUCCESS: | ||
return (0, _objectSpread2.default)({}, state, { | ||
isRefreshing: false, | ||
tokens: (0, _objectSpread2.default)({}, state.tokens, action.tokens) | ||
}); | ||
case _actionType.AUTH_REFRESH_TOKEN_FAILURE: | ||
return (0, _objectSpread2.default)({}, state, { | ||
isRefreshing: false | ||
}); | ||
case _actionType.FETCH_AUTH_USER_REQUEST: | ||
return (0, _objectSpread2.default)({}, state, { | ||
isUserFetching: true | ||
}); | ||
case _actionType.FETCH_AUTH_USER_SUCCESS: | ||
return (0, _objectSpread2.default)({}, state, { | ||
user: action.user, | ||
isUserFetching: false | ||
}); | ||
case _actionType.FETCH_AUTH_USER_FAILURE: | ||
return (0, _objectSpread2.default)({}, state, { | ||
isUserFetching: false | ||
}); | ||
default: | ||
return state; | ||
} | ||
}; | ||
var reducer = exports.reducer = function reducer() { | ||
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState; | ||
var action = arguments[1]; | ||
switch (action.type) { | ||
case _actionType.AUTH_LOGIN: | ||
return (0, _extends3.default)({}, state, { | ||
isLoggedIn: false, | ||
isLoggingIn: true, | ||
loginError: null | ||
}); | ||
case _actionType.AUTH_LOGIN_SUCCESS: | ||
return (0, _extends3.default)({}, state, { | ||
isLoggedIn: true, | ||
isLoggingIn: false, | ||
user: action.user, | ||
loginError: null | ||
}); | ||
case _actionType.AUTH_LOGIN_FAILURE: | ||
return (0, _extends3.default)({}, state, { | ||
isLoggedIn: false, | ||
isLoggingIn: false, | ||
user: null, | ||
loginError: action.error | ||
}); | ||
case _actionType.SET_AUTH_TOKENS: | ||
return (0, _extends3.default)({}, state, { | ||
tokens: (0, _extends3.default)({}, state.tokens, action.tokens) | ||
}); | ||
case _actionType.AUTH_LOGOUT: | ||
return (0, _extends3.default)({}, state, { | ||
isLoggedIn: false, | ||
user: null, | ||
tokens: {} | ||
}); | ||
case _actionType.AUTH_REFRESH_TOKEN: | ||
{ | ||
return (0, _extends3.default)({}, state, { | ||
isRefreshing: true | ||
}); | ||
} | ||
case _actionType.AUTH_REFRESH_TOKEN_SUCCESS: | ||
{ | ||
return (0, _extends3.default)({}, state, { | ||
isRefreshing: false, | ||
tokens: (0, _extends3.default)({}, state.tokens, action.tokens) | ||
}); | ||
} | ||
case _actionType.AUTH_REFRESH_TOKEN_FAILURE: | ||
{ | ||
return (0, _extends3.default)({}, state, { | ||
isRefreshing: false | ||
}); | ||
} | ||
default: | ||
return state; | ||
} | ||
}; | ||
exports.reducer = reducer; |
@@ -1,27 +0,50 @@ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
exports.isLoggingIn = exports.loginErrors = exports.isLoggedIn = exports.authUser = exports.isRefreshing = exports.authTokens = undefined; | ||
exports.isUserFetching = exports.isLoggingIn = exports.loginErrors = exports.isLoggedIn = exports.authUser = exports.isRefreshing = exports.authTokens = void 0; | ||
var _config = require('./config'); | ||
var _config = require("./config"); | ||
var authTokens = exports.authTokens = function authTokens(state) { | ||
return state[_config.reducerName].tokens; | ||
var authTokens = function authTokens(state) { | ||
return state[_config.reducerName].tokens; | ||
}; | ||
var isRefreshing = exports.isRefreshing = function isRefreshing(state) { | ||
return state[_config.reducerName].isRefreshing; | ||
exports.authTokens = authTokens; | ||
var isRefreshing = function isRefreshing(state) { | ||
return state[_config.reducerName].isRefreshing; | ||
}; | ||
var authUser = exports.authUser = function authUser(state) { | ||
return state[_config.reducerName].user; | ||
exports.isRefreshing = isRefreshing; | ||
var authUser = function authUser(state) { | ||
return state[_config.reducerName].user; | ||
}; | ||
var isLoggedIn = exports.isLoggedIn = function isLoggedIn(state) { | ||
return state[_config.reducerName].isLoggedIn; | ||
exports.authUser = authUser; | ||
var isLoggedIn = function isLoggedIn(state) { | ||
return state[_config.reducerName].isLoggedIn; | ||
}; | ||
var loginErrors = exports.loginErrors = function loginErrors(state) { | ||
return state[_config.reducerName].loginError; | ||
exports.isLoggedIn = isLoggedIn; | ||
var loginErrors = function loginErrors(state) { | ||
return state[_config.reducerName].loginError; | ||
}; | ||
var isLoggingIn = exports.isLoggingIn = function isLoggingIn(state) { | ||
return state[_config.reducerName].isLoggingIn; | ||
}; | ||
exports.loginErrors = loginErrors; | ||
var isLoggingIn = function isLoggingIn(state) { | ||
return state[_config.reducerName].isLoggingIn; | ||
}; | ||
exports.isLoggingIn = isLoggingIn; | ||
var isUserFetching = function isUserFetching(state) { | ||
return state[_config.reducerName].isUserFetching; | ||
}; | ||
exports.isUserFetching = isUserFetching; |
{ | ||
"name": "ackee-redux-token-auth", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Redux and redux saga logic for token authentication with an auto token refresh.", | ||
@@ -12,3 +12,4 @@ "main": "lib/index.js", | ||
"build": "npm run build:dist && npm run build:es && npm run build:lib", | ||
"prepublish": "npm run build" | ||
"prepublish": "npm run build", | ||
"start": "npm run build:es && onchange 'src/**/*.js' -- npm run build:es" | ||
}, | ||
@@ -18,3 +19,4 @@ "author": "Jiri Smolik <smolikjirka@gmail.com>", | ||
"Marek Janča <marek.janca@ackee.cz>", | ||
"Lukáš Horák <lukas.horak@ackee.cz>" | ||
"Lukáš Horák <lukas.horak@ackee.cz>", | ||
"Jiří Čermák <jiri.cermak@ackee.cz>" | ||
], | ||
@@ -27,18 +29,26 @@ "license": "ISC", | ||
"dependencies": { | ||
"redux-saga": "^0.15.6" | ||
"@babel/runtime": "^7.1.5", | ||
"localforage": "^1.7.3", | ||
"redux-saga": "^0.16.2" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"babel-core": "^6.26.0", | ||
"@babel/cli": "^7.0.0", | ||
"@babel/core": "^7.0.0", | ||
"@babel/plugin-proposal-class-properties": "^7.1.0", | ||
"@babel/plugin-proposal-export-namespace-from": "^7.0.0", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.0.0", | ||
"@babel/plugin-transform-runtime": "^7.0.0", | ||
"@babel/preset-env": "^7.0.0", | ||
"babel-eslint": "^9.0.0", | ||
"babel-loader": "^7.1.2", | ||
"babel-plugin-transform-object-rest-spread": "^6.26.0", | ||
"babel-plugin-transform-runtime": "^6.23.0", | ||
"babel-preset-env": "^1.6.0", | ||
"babel-preset-es2015": "^6.24.1", | ||
"babel-loader": "^8.0.4", | ||
"cross-env": "^5.1.3", | ||
"eslint": "^5.5.0", | ||
"eslint-config-ackee": "^0.9.0", | ||
"webpack": "^3.6.0" | ||
"eslint-config-prettier": "^3.3.0", | ||
"onchange": "^5.1.0", | ||
"prettier": "^1.15.2", | ||
"prettier-config-ackee": "0.0.4", | ||
"webpack": "^4.25.1", | ||
"webpack-cli": "^3.1.2" | ||
} | ||
} |
@@ -11,2 +11,11 @@ import { | ||
AUTH_REFRESH_TOKEN_SUCCESS, | ||
FETCH_AUTH_USER_REQUEST, | ||
FETCH_AUTH_USER_SUCCESS, | ||
FETCH_AUTH_USER_FAILURE, | ||
AUTH_SESSION_START, | ||
AUTH_SESSION_PAUSE, | ||
AUTH_SESSION_RESUME, | ||
AUTH_SESSION_END, | ||
ACCESS_TOKEN_AVAILABLE, | ||
ACCESS_TOKEN_UNAVAILABLE, | ||
} from './actionType'; | ||
@@ -43,4 +52,5 @@ | ||
export const refreshTokens = () => ({ | ||
export const refreshTokens = tokens => ({ | ||
type: PROCESS_TOKEN_REFRESH, | ||
tokens, | ||
}); | ||
@@ -65,1 +75,40 @@ | ||
}; | ||
export const fetchAuthUserRequest = () => ({ | ||
type: FETCH_AUTH_USER_REQUEST, | ||
}); | ||
export const fetchAuthUserSuccess = user => ({ | ||
type: FETCH_AUTH_USER_SUCCESS, | ||
user, | ||
}); | ||
export const fetchAuthUserFailure = error => ({ | ||
type: FETCH_AUTH_USER_FAILURE, | ||
error, | ||
}); | ||
export const accessTokenAvailable = accessToken => ({ | ||
type: ACCESS_TOKEN_AVAILABLE, | ||
payload: accessToken, | ||
}); | ||
export const accessTokenUnavailable = () => ({ | ||
type: ACCESS_TOKEN_UNAVAILABLE, | ||
}); | ||
export const authSessionStart = () => ({ | ||
type: AUTH_SESSION_START, | ||
}); | ||
export const authSessionEnd = () => ({ | ||
type: AUTH_SESSION_END, | ||
}); | ||
export const authSessionPause = () => ({ | ||
type: AUTH_SESSION_PAUSE, | ||
}); | ||
export const authSessionResume = () => ({ | ||
type: AUTH_SESSION_RESUME, | ||
}); |
@@ -1,12 +0,24 @@ | ||
export const AUTH_LOGIN = 'AUTH_LOGIN'; | ||
export const AUTH_LOGIN_SUCCESS = 'AUTH_LOGIN_SUCCESS'; | ||
export const AUTH_LOGIN_FAILURE = 'AUTH_LOGIN_FAILURE'; | ||
export const AUTH_LOGIN = '@@redux-token-auth/AUTH_LOGIN'; | ||
export const AUTH_LOGIN_SUCCESS = '@@redux-token-auth/AUTH_LOGIN_SUCCESS'; | ||
export const AUTH_LOGIN_FAILURE = '@@redux-token-auth/AUTH_LOGIN_FAILURE'; | ||
export const AUTH_LOGOUT = 'AUTH_LOGOUT'; | ||
export const AUTH_LOGOUT = '@@redux-token-auth/AUTH_LOGOUT'; | ||
export const SET_AUTH_TOKENS = 'SET_AUTH_TOKENS'; | ||
export const SET_AUTH_TOKENS = '@@redux-token-auth/SET_AUTH_TOKENS'; | ||
export const AUTH_REFRESH_TOKEN = 'AUTH_REFRESH_TOKEN'; | ||
export const AUTH_REFRESH_TOKEN_SUCCESS = 'AUTH_REFRESH_TOKEN_SUCCESS'; | ||
export const AUTH_REFRESH_TOKEN_FAILURE = 'AUTH_REFRESH_TOKEN_FAILURE'; | ||
export const PROCESS_TOKEN_REFRESH = 'PROCESS_TOKEN_REFRESH'; | ||
export const AUTH_REFRESH_TOKEN = '@@redux-token-auth/AUTH_REFRESH_TOKEN'; | ||
export const AUTH_REFRESH_TOKEN_SUCCESS = '@@redux-token-auth/AUTH_REFRESH_TOKEN_SUCCESS'; | ||
export const AUTH_REFRESH_TOKEN_FAILURE = '@@redux-token-auth/AUTH_REFRESH_TOKEN_FAILURE'; | ||
export const PROCESS_TOKEN_REFRESH = '@@redux-token-auth/PROCESS_TOKEN_REFRESH'; | ||
export const FETCH_AUTH_USER_REQUEST = '@@redux-token-auth/FETCH_AUTH_USER_REQUEST'; | ||
export const FETCH_AUTH_USER_SUCCESS = '@@redux-token-auth/FETCH_AUTH_USER_SUCCESS'; | ||
export const FETCH_AUTH_USER_FAILURE = '@@redux-token-auth/FETCH_AUTH_USER_FAILURE'; | ||
export const ACCESS_TOKEN_AVAILABLE = '@@redux-token-auth/ACCESS_TOKEN_AVAILABLE'; | ||
export const ACCESS_TOKEN_UNAVAILABLE = '@@redux-token-auth/ACCESS_TOKEN_UNAVAILABLE'; | ||
export const AUTH_SESSION_START = '@@redux-token-auth/AUTH_SESSION_START'; | ||
export const AUTH_SESSION_END = '@@redux-token-auth/AUTH_SESSION_END'; | ||
export const AUTH_SESSION_PAUSE = '@@redux-token-auth/AUTH_SESSION_PAUSE'; | ||
export const AUTH_SESSION_RESUME = '@@redux-token-auth/AUTH_SESSION_RESUME'; |
@@ -1,5 +0,4 @@ | ||
export { AUTH_LOGIN_SUCCESS, AUTH_LOGIN_FAILURE, AUTH_LOGOUT, SET_AUTH_TOKENS } from './actionType'; | ||
export * from './actionType'; | ||
export * as actionTypes from './actionType'; | ||
export { configure, authorizedFn, saga } from './saga'; | ||
export { authUser, isLoggedIn, isLoggingIn, loginErrors } from './selectors'; | ||
@@ -10,1 +9,5 @@ | ||
export { reducer } from './reducer'; | ||
export * from './sagas'; | ||
export * as constants from './constants'; |
@@ -10,2 +10,5 @@ import { | ||
AUTH_REFRESH_TOKEN_SUCCESS, | ||
FETCH_AUTH_USER_REQUEST, | ||
FETCH_AUTH_USER_SUCCESS, | ||
FETCH_AUTH_USER_FAILURE, | ||
} from './actionType'; | ||
@@ -20,2 +23,3 @@ | ||
isRefreshing: false, | ||
isUserFetching: false, | ||
}; | ||
@@ -31,3 +35,5 @@ | ||
loginError: null, | ||
isUserFetching: true, | ||
}; | ||
case AUTH_LOGIN_SUCCESS: | ||
@@ -40,3 +46,5 @@ return { | ||
loginError: null, | ||
isUserFetching: false, | ||
}; | ||
case AUTH_LOGIN_FAILURE: | ||
@@ -49,6 +57,9 @@ return { | ||
loginError: action.error, | ||
isUserFetching: false, | ||
}; | ||
case SET_AUTH_TOKENS: | ||
return { | ||
...state, | ||
isLoggedIn: true, | ||
tokens: { | ||
@@ -59,2 +70,3 @@ ...state.tokens, | ||
}; | ||
case AUTH_LOGOUT: | ||
@@ -67,3 +79,4 @@ return { | ||
}; | ||
case AUTH_REFRESH_TOKEN: { | ||
case AUTH_REFRESH_TOKEN: | ||
return { | ||
@@ -73,4 +86,4 @@ ...state, | ||
}; | ||
} | ||
case AUTH_REFRESH_TOKEN_SUCCESS: { | ||
case AUTH_REFRESH_TOKEN_SUCCESS: | ||
return { | ||
@@ -84,4 +97,4 @@ ...state, | ||
}; | ||
} | ||
case AUTH_REFRESH_TOKEN_FAILURE: { | ||
case AUTH_REFRESH_TOKEN_FAILURE: | ||
return { | ||
@@ -91,3 +104,22 @@ ...state, | ||
}; | ||
} | ||
case FETCH_AUTH_USER_REQUEST: | ||
return { | ||
...state, | ||
isUserFetching: true, | ||
}; | ||
case FETCH_AUTH_USER_SUCCESS: | ||
return { | ||
...state, | ||
user: action.user, | ||
isUserFetching: false, | ||
}; | ||
case FETCH_AUTH_USER_FAILURE: | ||
return { | ||
...state, | ||
isUserFetching: false, | ||
}; | ||
default: | ||
@@ -94,0 +126,0 @@ return state; |
@@ -21,1 +21,3 @@ import { reducerName } from './config'; | ||
}; | ||
export const isUserFetching = state => state[reducerName].isUserFetching; |
@@ -21,4 +21,9 @@ const path = require('path'); | ||
options: { | ||
presets: ['es2015'], | ||
plugins: [require('babel-plugin-transform-object-rest-spread'), 'transform-runtime'], | ||
presets: ['@babel/preset-env'], | ||
plugins: [ | ||
'@babel/plugin-proposal-object-rest-spread', | ||
'@babel/plugin-proposal-class-properties', | ||
'@babel/plugin-proposal-export-namespace-from', | ||
'@babel/plugin-transform-runtime', | ||
], | ||
}, | ||
@@ -30,2 +35,3 @@ }, | ||
plugins: [], | ||
mode: 'development', | ||
}; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
176727
71
3557
3
18
1
1
+ Added@babel/runtime@^7.1.5
+ Addedlocalforage@^1.7.3
+ Added@babel/runtime@7.26.0(transitive)
+ Addedimmediate@3.0.6(transitive)
+ Addedlie@3.1.1(transitive)
+ Addedlocalforage@1.10.0(transitive)
+ Addedredux-saga@0.16.2(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)
- Removedredux-saga@0.15.6(transitive)
Updatedredux-saga@^0.16.2