Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ackee-redux-token-auth

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ackee-redux-token-auth - npm Package Compare versions

Comparing version 1.1.2 to 1.1.3

readme-seq1.plantuml

22

.eslintrc.json
{
"env": {
"browser": true
"env": {
"browser": true
},
"extends": ["ackee"],
"parser": "babel-eslint",
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"jsx": true
},
"extends": ["ackee", "prettier"],
"parser": "babel-eslint",
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"jsx": true
},
"sourceType": "module"
}
"sourceType": "module"
}
}

@@ -1,161 +0,69 @@

"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});
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;
exports.stopTokenRefresh = exports.startTokenRefresh = exports.refreshTokens = exports.setTokens = exports.logout = exports.stopLogin = exports.login = undefined;
var _actionType = require("./actionType");
var _actionType = require('./actionType');
var login = function login(credentials) {
return {
type: _actionType.AUTH_LOGIN,
credentials: credentials
};
var login = exports.login = function login(credentials) {
return {
type: _actionType.AUTH_LOGIN,
credentials: credentials
};
};
exports.login = login;
var stopLogin = function stopLogin(error, user) {
if (error) {
var stopLogin = exports.stopLogin = function stopLogin(error, user) {
if (error) {
return {
type: _actionType.AUTH_LOGIN_FAILURE,
error: error
};
}
return {
type: _actionType.AUTH_LOGIN_FAILURE,
error: error
type: _actionType.AUTH_LOGIN_SUCCESS,
user: user
};
}
return {
type: _actionType.AUTH_LOGIN_SUCCESS,
user: user
};
};
exports.stopLogin = stopLogin;
var logout = function logout() {
return {
type: _actionType.AUTH_LOGOUT
};
var logout = exports.logout = function logout() {
return {
type: _actionType.AUTH_LOGOUT
};
};
exports.logout = logout;
var setTokens = function setTokens(tokens) {
return {
type: _actionType.SET_AUTH_TOKENS,
tokens: tokens
};
var setTokens = exports.setTokens = function setTokens(tokens) {
return {
type: _actionType.SET_AUTH_TOKENS,
tokens: tokens
};
};
exports.setTokens = setTokens;
var refreshTokens = function refreshTokens(tokens) {
return {
type: _actionType.PROCESS_TOKEN_REFRESH,
tokens: tokens
};
var refreshTokens = exports.refreshTokens = function refreshTokens() {
return {
type: _actionType.PROCESS_TOKEN_REFRESH
};
};
exports.refreshTokens = refreshTokens;
var startTokenRefresh = function startTokenRefresh(refreshToken) {
return {
type: _actionType.AUTH_REFRESH_TOKEN,
refreshToken: refreshToken
};
var startTokenRefresh = exports.startTokenRefresh = function startTokenRefresh(refreshToken) {
return {
type: _actionType.AUTH_REFRESH_TOKEN,
refreshToken: refreshToken
};
};
exports.startTokenRefresh = startTokenRefresh;
var stopTokenRefresh = exports.stopTokenRefresh = function stopTokenRefresh(error) {
var tokens = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var stopTokenRefresh = function stopTokenRefresh(error) {
var tokens = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (error) {
if (error) {
return {
type: _actionType.AUTH_REFRESH_TOKEN_FAILURE,
error: error
};
}
return {
type: _actionType.AUTH_REFRESH_TOKEN_FAILURE,
error: error
type: _actionType.AUTH_REFRESH_TOKEN_SUCCESS,
tokens: tokens
};
}
return {
type: _actionType.AUTH_REFRESH_TOKEN_SUCCESS,
tokens: tokens
};
};
exports.stopTokenRefresh = stopTokenRefresh;
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,38 +6,13 @@ Object.defineProperty(exports, "__esModule", {

});
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;
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';

@@ -1,2 +0,2 @@

"use strict";
'use strict';

@@ -6,6 +6,3 @@ Object.defineProperty(exports, "__esModule", {

});
exports.logger = exports.reducerName = void 0;
var reducerName = 'auth';
exports.reducerName = reducerName;
var logger = console;
exports.logger = logger;
var reducerName = exports.reducerName = 'auth';
var logger = exports.logger = console;

@@ -1,29 +0,64 @@

"use strict";
'use strict';
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
Object.defineProperty(exports, "__esModule", {
value: true
});
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", {
var _actionType = require('./actionType');
Object.defineProperty(exports, 'AUTH_LOGIN_SUCCESS', {
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,

@@ -34,3 +69,3 @@ get: function get() {

});
Object.defineProperty(exports, "isLoggingIn", {
Object.defineProperty(exports, 'isLoggingIn', {
enumerable: true,

@@ -41,3 +76,3 @@ get: function get() {

});
Object.defineProperty(exports, "loginErrors", {
Object.defineProperty(exports, 'loginErrors', {
enumerable: true,

@@ -48,3 +83,6 @@ get: function get() {

});
Object.defineProperty(exports, "login", {
var _actions = require('./actions');
Object.defineProperty(exports, 'login', {
enumerable: true,

@@ -55,3 +93,3 @@ get: function get() {

});
Object.defineProperty(exports, "stopLogin", {
Object.defineProperty(exports, 'stopLogin', {
enumerable: true,

@@ -62,3 +100,3 @@ get: function get() {

});
Object.defineProperty(exports, "logout", {
Object.defineProperty(exports, 'logout', {
enumerable: true,

@@ -69,3 +107,3 @@ get: function get() {

});
Object.defineProperty(exports, "setTokens", {
Object.defineProperty(exports, 'setTokens', {
enumerable: true,

@@ -76,3 +114,3 @@ get: function get() {

});
Object.defineProperty(exports, "refreshTokens", {
Object.defineProperty(exports, 'refreshTokens', {
enumerable: true,

@@ -83,3 +121,6 @@ get: function get() {

});
Object.defineProperty(exports, "reducer", {
var _reducer = require('./reducer');
Object.defineProperty(exports, 'reducer', {
enumerable: true,

@@ -89,40 +130,2 @@ 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,105 +0,82 @@

"use strict";
'use strict';
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});
exports.reducer = void 0;
exports.reducer = undefined;
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));
var _extends2 = require('babel-runtime/helpers/extends');
var _actionType = require("./actionType");
var _extends3 = _interopRequireDefault(_extends2);
var _actionType = require('./actionType');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var initialState = {
user: null,
isLoggedIn: false,
isLoggingIn: false,
loginError: null,
tokens: {},
isRefreshing: false,
isUserFetching: false
user: null,
isLoggedIn: false,
isLoggingIn: false,
loginError: null,
tokens: {},
isRefreshing: false
};
var reducer = function reducer() {
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState;
var action = arguments.length > 1 ? arguments[1] : undefined;
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, _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;
}
};
exports.reducer = reducer;
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;
}
};

@@ -1,50 +0,27 @@

"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});
exports.isUserFetching = exports.isLoggingIn = exports.loginErrors = exports.isLoggedIn = exports.authUser = exports.isRefreshing = exports.authTokens = void 0;
exports.isLoggingIn = exports.loginErrors = exports.isLoggedIn = exports.authUser = exports.isRefreshing = exports.authTokens = undefined;
var _config = require("./config");
var _config = require('./config');
var authTokens = function authTokens(state) {
return state[_config.reducerName].tokens;
var authTokens = exports.authTokens = function authTokens(state) {
return state[_config.reducerName].tokens;
};
exports.authTokens = authTokens;
var isRefreshing = function isRefreshing(state) {
return state[_config.reducerName].isRefreshing;
var isRefreshing = exports.isRefreshing = function isRefreshing(state) {
return state[_config.reducerName].isRefreshing;
};
exports.isRefreshing = isRefreshing;
var authUser = function authUser(state) {
return state[_config.reducerName].user;
var authUser = exports.authUser = function authUser(state) {
return state[_config.reducerName].user;
};
exports.authUser = authUser;
var isLoggedIn = function isLoggedIn(state) {
return state[_config.reducerName].isLoggedIn;
var isLoggedIn = exports.isLoggedIn = function isLoggedIn(state) {
return state[_config.reducerName].isLoggedIn;
};
exports.isLoggedIn = isLoggedIn;
var loginErrors = function loginErrors(state) {
return state[_config.reducerName].loginError;
var loginErrors = exports.loginErrors = function loginErrors(state) {
return state[_config.reducerName].loginError;
};
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;
var isLoggingIn = exports.isLoggingIn = function isLoggingIn(state) {
return state[_config.reducerName].isLoggingIn;
};
{
"name": "ackee-redux-token-auth",
"version": "1.1.2",
"version": "1.1.3",
"description": "Redux and redux saga logic for token authentication with an auto token refresh.",

@@ -12,4 +12,3 @@ "main": "lib/index.js",

"build": "npm run build:dist && npm run build:es && npm run build:lib",
"prepublish": "npm run build",
"start": "npm run build:es && onchange 'src/**/*.js' -- npm run build:es"
"prepublish": "npm run build"
},

@@ -19,4 +18,3 @@ "author": "Jiri Smolik <smolikjirka@gmail.com>",

"Marek Janča <marek.janca@ackee.cz>",
"Lukáš Horák <lukas.horak@ackee.cz>",
"Jiří Čermák <jiri.cermak@ackee.cz>"
"Lukáš Horák <lukas.horak@ackee.cz>"
],

@@ -29,26 +27,18 @@ "license": "ISC",

"dependencies": {
"@babel/runtime": "^7.1.5",
"localforage": "^1.7.3",
"redux-saga": "^0.16.2"
"redux-saga": "^0.15.6"
},
"devDependencies": {
"@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-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-eslint": "^9.0.0",
"babel-loader": "^8.0.4",
"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",
"cross-env": "^5.1.3",
"eslint": "^5.5.0",
"eslint-config-ackee": "^0.9.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"
"webpack": "^3.6.0"
}
}

@@ -1,94 +0,60 @@

# ackee-redux-token-auth
# token-auth
The library aims to handle authentication logic with token based flow.
The library tackles a token based communication flow between a redux app and an data resource provider.
### Main features
## Problem/solution
- **automatically refresh access token** before it becomes expired
- **persisting tokens state** in local or session storage (optional)
- automatically **fetching an authorized user** after successful tokens retrieval from a storage
- simple API for auth state management: [`getAuthStateChannel`](#get-auth-state-channel), [`withAuthSession`](#with-auth-session)
The problem: Given an token based communication schema, e.g. OAuth2, where valid **access token** is required for each request. Once access token expires, a different endpoint is called with **refresh token** to refresh the token pair. The communication then continues with the access token.
> ### Requirements
>
> The library works best with React apps that use **Redux and Redux Saga** (since the authentication logic is heavily integrated with both these libraries).
The solution: `requestFn`. A functional wrapper that does the refresh process for you and retries the wrapped function call when it failes due to an expired token.
* * *
![workflow](readme-seq1.png)
## Table of contents
## API
- [Installing](#installing)
- [Initialization](#initialization)
- [API](#api)
- [Constants](#constants)
- [Action creators](#action-creators)
- [Action types](#action-types)
- [Selectors](#selectors)
- [Utilities](#utilities)
- [Migration guides (`1.0.x` -> `1.1.x`)](#migration-guides)
### Selectors
* * *
#### `authUser(state: Object) => user:any`
## <a name="installing"></a>Installing
Gets the user returned from `authenticate` method.
Using npm:
#### `isLoggedIn(state: Object) => bool`
```bash
$ npm install ackee-redux-token-auth
```
Returns `true` whether user is logged in, `false` otherwise.
Using yarn:
#### `isLoggingIn(state: Object) => bool`
```bash
$ yarn add ackee-redux-token-auth
```
Returns `true` whether the login process is taking place, `false` otherwise.
* * *
### Initialization
## <a name="initialization"></a>Initialization
#### `configure(config: Object) => void`
#### <a name="configure"></a>`configure(config: Object, options: Object) => void`
Sets the package configuration with an config object. Following config properties are supported:
`config`:
- `authenticate: Function`,
- `refreshTokens: Function`,
- `shouldRefresh: Function`.
- `authenticate: Function` - required
- `refreshTokens: Function` - required
- `getAuthUser: Function` - required
- `shouldRefresh: Function`
`options`:
- `tokens`
- `persistence: String` - [See details](#constants-tokens-persistence)
- `requestDurationEstimate: Number`
- `minRequiredExpiration: Number`
Any of the functions can also be a saga generator.
##### `authenticate(credentials: any) => { user: any, tokens: any }`
##### `authenticate(credentials: any) => {user: any, tokens: any }`
Required. This method is called when a `login(credentials)` action is dispatched. These credentials are passed to `authenticate` method.
The method is expected to return/or resolve with an Object with props `user, tokens` or throw an error. User and tokens are then stored as is to the redux state for later use (`state.auth.user`).
The method is exepected to return/or resolve with an Object with props `user, tokens` or throw an error. User and tokens are then stored as is to the redux state for later use.
##### `refreshTokens(tokens: Object) => tokens:Object`
Required. This method is called when the timeout for refreshing tokens ends or when tokens are expired after retrieval from a local storage. This triggers the token-refresh process.
Optional. This method is called when the `requestFn` catches an error and `shouldRefresh` returns true. This triggers the token-refresh process.
Function is expected to return/or resolve with an tokens Object: (`{ [tokenName: string]: token }`)
Function is expected to return/or resolve with an tokens Object (`{ [tokenName: string]: token }`)
##### `getAuthUser(void) => user:any`
All handlers passed to `requestFn` are now blocked until the refresh process is complete. This is to prevent the refresh process to be started by simultaneous failing tasks. **Default**: no-op.
Required. This method is called when tokens are successfully retrieved from a local storage.
##### `shouldRefresh(error: Error) => boolean`
Function is expected to return/or resolve with a user object.
Optional. This function is called when the `requestFn` catches an error and should decide, whether to refresh the tokens and retry the action or not. **Default**: `() => true`.
##### [DEPRECATED]`shouldRefresh(error: Error) => boolean`
Optional. This function is called when the `requestFn` catches an error and should decide, whether to refresh the tokens and retry the action or not.
**Default**: `() => true`.
### `saga() => ReduxSaga`

@@ -102,174 +68,6 @@

### Initialization overview
### Utilities
```js
import * as ReduxAuth from 'ackee-redux-token-auth';
#### `authorizedFn(handler: Function)`
// 1. Provide autheticate, refreshTokens and getAuthUser methods
ReduxAuth.configure({
authenticate,
refreshTokens,
getAuthUser,
});
// 2. Launch ReduxAuth.saga
function*() {
yield all([ReduxAuth.saga()])
}
// 3. Add auth reducer
const rootReducer = combineReducers({
auth: ReduxAuth.reducer
});
```
* * *
## API
### <a name="constants"></a>Constants
#### `tokens`
- ##### <a name="constants-tokens-persistence"></a>`persistence`
Tokens persistence defines how and where will be tokens stored and when they will be cleared:
- `LOCAL` (default) - Tokens are stored in `IndexedDB`. The state will be persisted even when the browser window is closed. An explicit sign out is needed to clear that state.
- `SESSION` - Tokens are stored in `SessionStorage`.
- `NONE` - Tokens will only be stored in Redux Store and will be cleared when the window or activity is refreshed.
###### Example
```js
import { configure, constants } from 'ackee-redux-token-auth';
const options = {
tokens: {
persistence: constants.tokens.persistence.NONE,
},
};
configure(
{
// ...
},
options,
);
```
### <a name="action-creators"></a>Action creators
#### `login(credentials: Object) => ReduxAction`
The `credentials` object is passed to `authenticate(credentials)` method you've provided in the [`configure`](#configure) method.
#### `logout() => ReduxAction`
Triggers a user logout. This clears the state of any auth data (tokens from local storage included).
### <a name="action-types"></a>Action types
#### Access token flow
##### `ACCESS_TOKEN_AVAILABLE`
Access token becomes available when one of following events successfully finished: login, local tokens retrieval or tokens refreshment.
It's guaranteed that `ACCESS_TOKEN_UNAVAILABLE` action will be dispatched first, before another trigger of `ACCESS_TOKEN_AVAILABLE`.
##### `ACCESS_TOKEN_UNAVAILABLE`
Access token becomes unavailable on logout or when tokens refreshment start. It's also guaranteed that `ACCESS_TOKEN_AVAILABLE` action will be dispatched first, before another trigger of `ACCESS_TOKEN_UNAVAILABLE`.
#### Authentication session flow
##### `AUTH_SESSION_START`
Once the application has available valid access token, this action is dispatched. It's guaranteed that `AUTH_SESSION_END` must be triggered first before another trigger.
##### `AUTH_SESSION_PAUSE`
The action is triggered on start of access token refreshment.
##### `AUTH_SESSION_RESUME`
If access token refreshment was successful, `AUTH_SESSION_RESUME` is triggered. It's guaranteed it will be dispatched only after `AUTH_SESSION_PAUSE` action.
##### `AUTH_SESSION_END`
If access token refreshment fails or `AUTH_LOGOUT` action§ is triggered, `AUTH_SESSION_END` is triggered.
### <a name="selectors"></a>Selectors
#### `authUser(state: Object) => user:any`
Gets the user returned from `authenticate` method.
#### `isLoggedIn(state: Object) => Boolean`
Returns `true` whether user is logged in, `false` otherwise.
#### `isLoggingIn(state: Object) => Boolean`
Returns `true` whether the login process is taking place, `false` otherwise.
#### `isUserFetching(state: Object) => Boolean`
### <a name="utilities"></a>Utilities
#### <a name="with-auth-session"></a>`withAuthSession(fn: Function) => void`
A generator function that receives any function as 1st parameter. The provided function will be launched on `AUTH_SESSION_START` action and cancelled on `AUTH_SESSION_END`.
Note that `withAuthSession` is a blocking task (if you need to make it non-blocking one, use it with `fork` effect).
##### Example
```js
import { withAuthSession } from 'ackee-redux-token-auth';
function* myAuthSaga() {}
export default function*() {
yield withAuthSession(myAuthSaga);
// non-blocking version: yield fork(withAuthSession, myAuthSaga);
}
```
#### <a name="get-auth-state-channel"></a>`getAuthStateChannel(void) => channel`
A generator function that returns [action channel](https://github.com/redux-saga/redux-saga/blob/master/docs/advanced/Channels.md#using-channels) with following available actions:
- `ACCESS_TOKEN_AVAILABLE`
- `ACCESS_TOKEN_UNAVAILABLE`
- `AUTH_SESSION_START`
- `AUTH_SESSION_PAUSE`
- `AUTH_SESSION_RESUME`
- `AUTH_SESSION_END`
##### Example
```js
import { takeEvery } from 'redux-saga/effects';
import { getAuthStateChannel, actionTypes } from 'ackee-redux-token-auth';
function* logOutEveryAuthStateStep() {
const authStateChannel = yield getAuthStateChannel();
yield takeEvery(authStateChannel, function*(action) {
switch (action.type) {
case actionTypes.ACCESS_TOKEN_AVAILABLE: {
const accessToken = action.payload;
// do something with accessToken
break;
}
case actionTypes.ACCESS_TOKEN_UNAVAILABLE:
break;
}
});
}
```
#### [DEPRECATED] `authorizedFn(handler: Function)`
A saga wrapper for the given `handler` Function or a saga generator.

@@ -279,26 +77,16 @@

* * *
### Action creators
> ### Tokens management logic
>
> More detail description of the [Tokens management logic](/src/sagas/tokens/tokens.md).
#### `logout() => ReduxAction`
* * *
Triggers a user logout. This clears the state of any auth data.
## <a name="migration-guides"></a>Migration guides from `1.0.x` to `1.1.x`
#### `setTokens(tokens: Object) => ReduxAction`
The `configure` method now accept an object with following changes:
1. `refreshTokens` function is now required
2. `getAuthUser` is a required function, that returns a user object.
Sets the tokens to the state. In case you want to set them manually.
The configure method should now look like this:
*This should be used at application startup only. Using this elsewere is considered to be an anti-pattern.*
```js
import { configure } from 'ackee-redux-token-auth';
#### `refreshTokens() => ReduxAction`
configure({
autheticate,
refreshTokens, // now required
getAuthUser, // new method
});
```
Triggers the refresh-tokens process.

@@ -11,11 +11,2 @@ 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';

@@ -52,5 +43,4 @@

export const refreshTokens = tokens => ({
export const refreshTokens = () => ({
type: PROCESS_TOKEN_REFRESH,
tokens,
});

@@ -75,40 +65,1 @@

};
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,24 +0,12 @@

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_LOGIN = 'AUTH_LOGIN';
export const AUTH_LOGIN_SUCCESS = 'AUTH_LOGIN_SUCCESS';
export const AUTH_LOGIN_FAILURE = 'AUTH_LOGIN_FAILURE';
export const AUTH_LOGOUT = '@@redux-token-auth/AUTH_LOGOUT';
export const AUTH_LOGOUT = 'AUTH_LOGOUT';
export const SET_AUTH_TOKENS = '@@redux-token-auth/SET_AUTH_TOKENS';
export const SET_AUTH_TOKENS = 'SET_AUTH_TOKENS';
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';
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';

@@ -1,4 +0,5 @@

export * from './actionType';
export * as actionTypes from './actionType';
export { AUTH_LOGIN_SUCCESS, AUTH_LOGIN_FAILURE, AUTH_LOGOUT, SET_AUTH_TOKENS } from './actionType';
export { configure, authorizedFn, saga } from './saga';
export { authUser, isLoggedIn, isLoggingIn, loginErrors } from './selectors';

@@ -9,5 +10,1 @@

export { reducer } from './reducer';
export * from './sagas';
export * as constants from './constants';

@@ -10,5 +10,2 @@ import {

AUTH_REFRESH_TOKEN_SUCCESS,
FETCH_AUTH_USER_REQUEST,
FETCH_AUTH_USER_SUCCESS,
FETCH_AUTH_USER_FAILURE,
} from './actionType';

@@ -23,3 +20,2 @@

isRefreshing: false,
isUserFetching: false,
};

@@ -35,5 +31,3 @@

loginError: null,
isUserFetching: true,
};
case AUTH_LOGIN_SUCCESS:

@@ -46,5 +40,3 @@ return {

loginError: null,
isUserFetching: false,
};
case AUTH_LOGIN_FAILURE:

@@ -57,9 +49,6 @@ return {

loginError: action.error,
isUserFetching: false,
};
case SET_AUTH_TOKENS:
return {
...state,
isLoggedIn: true,
tokens: {

@@ -70,3 +59,2 @@ ...state.tokens,

};
case AUTH_LOGOUT:

@@ -79,4 +67,3 @@ return {

};
case AUTH_REFRESH_TOKEN:
case AUTH_REFRESH_TOKEN: {
return {

@@ -86,4 +73,4 @@ ...state,

};
case AUTH_REFRESH_TOKEN_SUCCESS:
}
case AUTH_REFRESH_TOKEN_SUCCESS: {
return {

@@ -97,4 +84,4 @@ ...state,

};
case AUTH_REFRESH_TOKEN_FAILURE:
}
case AUTH_REFRESH_TOKEN_FAILURE: {
return {

@@ -104,22 +91,3 @@ ...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:

@@ -126,0 +94,0 @@ return state;

@@ -21,3 +21,1 @@ import { reducerName } from './config';

};
export const isUserFetching = state => state[reducerName].isUserFetching;

@@ -21,9 +21,4 @@ const path = require('path');

options: {
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',
],
presets: ['es2015'],
plugins: [require('babel-plugin-transform-object-rest-spread'), 'transform-runtime'],
},

@@ -35,3 +30,2 @@ },

plugins: [],
mode: 'development',
};

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc