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 2.0.2 to 2.1.0

3

lib/sagas/fetchAuthUser.js
import { take, put } from 'redux-saga/effects';
import { FETCH_AUTH_USER_REQUEST } from '../actionType';
import { fetchAuthUserFailure, fetchAuthUserSuccess } from '../actions';
import { logger } from '../config';
import config from './config';

@@ -12,3 +13,3 @@

yield put(fetchAuthUserFailure(e));
throw e;
logger.error(`Failed to fetch auth user:\n`, e);
}

@@ -15,0 +16,0 @@ }

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

import { take, put, cancel, fork, takeEvery, race, all } from 'redux-saga/effects';
import { take, put, cancel, fork, takeEvery, all } from 'redux-saga/effects';
import { refreshTokens } from '../../actions';
import { SET_AUTH_TOKENS, ACCESS_TOKEN_UNAVAILABLE, AUTH_REFRESH_TOKEN_FAILURE } from '../../actionType';
import { ACCESS_TOKEN_UNAVAILABLE, SET_AUTH_TOKENS } from '../../actionType';
import { logger } from '../../config';

@@ -39,8 +39,10 @@ import config from '../config';

function* setTokensHandler({
function* setTokensHandler(refreshTokensTimeout, {
tokens
}, refreshTokensTimeout) {
}) {
clearLocaleStorageTokens(); // store tokens to a local storage
yield storeTokens(tokens);
if (tokens) {
yield storeTokens(tokens);
}

@@ -76,8 +78,3 @@ if (hasExpirationProperty(tokens)) {

});
yield all([takeEvery(SET_AUTH_TOKENS, function* setAuthTokens(action) {
yield race({
task: setTokensHandler(action, refreshTokensTimeout),
abort: take([ACCESS_TOKEN_UNAVAILABLE, AUTH_REFRESH_TOKEN_FAILURE])
});
}), takeEvery([ACCESS_TOKEN_UNAVAILABLE, AUTH_REFRESH_TOKEN_FAILURE], clearTokensHandler, refreshTokensTimeout)]);
yield all([takeEvery(SET_AUTH_TOKENS, setTokensHandler, refreshTokensTimeout), takeEvery(ACCESS_TOKEN_UNAVAILABLE, clearTokensHandler, refreshTokensTimeout)]);
}
{
"name": "ackee-redux-token-auth",
"version": "2.0.2",
"version": "2.1.0",
"description": "The library aims to handle authentication logic with token based flow.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -7,9 +7,14 @@ ## `getAuthStateChannel()`

- `ACCESS_TOKEN_AVAILABLE` - It's triggered any time access token becomes available (e.g. on successful login or on successful token refresh).
- `ACCESS_TOKEN_UNAVAILABLE` - It's triggered any time access token becomes unavailable (e.g. on logout or on failed token refresh).
- `AUTH_SESSION_START` - It's triggered once when tokens are set.
- `AUTH_SESSION_END` - It's triggered once on logout, when fetching auth. user fails or when login fails.
- `AUTH_SESSION_PAUSE` - Triggered when tokens refreshing start.
- `AUTH_SESSION_RESUME` - Triggered when tokens refreshing successfully finished.
`ACCESS_TOKEN_AVAILABLE` - It's triggered any time access token becomes available (e.g. on successful login or on successful token refresh), when `SET_AUTH_TOKENS` action occur.
`ACCESS_TOKEN_UNAVAILABLE` - It's triggered any time access token becomes unavailable, when one of following action occur: `AUTH_REFRESH_TOKEN, AUTH_LOGOUT, AUTH_LOGIN_FAILURE, FETCH_AUTH_USER_FAILURE`.
`AUTH_SESSION_START` - It's triggered once when tokens are set, when `SET_AUTH_TOKENS` action occurs.
`AUTH_SESSION_PAUSE` - Triggered when tokens refreshing start, when `AUTH_REFRESH_TOKEN` action occurs.
`AUTH_SESSION_RESUME` - Triggered when tokens refreshing successfully finished, when `AUTH_REFRESH_TOKEN_SUCCESS` action occurs.
`AUTH_SESSION_END` - It's triggered once when one of following actions occur: `AUTH_LOGOUT, AUTH_LOGIN_FAILURE, FETCH_AUTH_USER_FAILURE`.
---

@@ -16,0 +21,0 @@

@@ -5,2 +5,3 @@ import { take, put } from 'redux-saga/effects';

import { fetchAuthUserFailure, fetchAuthUserSuccess } from '../actions';
import { logger } from '../config';

@@ -16,3 +17,3 @@ import config from './config';

yield put(fetchAuthUserFailure(e));
throw e;
logger.error(`Failed to fetch auth user:\n`, e);
}

@@ -19,0 +20,0 @@ }

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

import { take, put, cancel, fork, takeEvery, race, all } from 'redux-saga/effects';
import { take, put, cancel, fork, takeEvery, all } from 'redux-saga/effects';
import { refreshTokens } from '../../actions';
import { SET_AUTH_TOKENS, ACCESS_TOKEN_UNAVAILABLE, AUTH_REFRESH_TOKEN_FAILURE } from '../../actionType';
import { ACCESS_TOKEN_UNAVAILABLE, SET_AUTH_TOKENS } from '../../actionType';
import { logger } from '../../config';

@@ -42,7 +42,9 @@

function* setTokensHandler({ tokens }, refreshTokensTimeout) {
function* setTokensHandler(refreshTokensTimeout, { tokens }) {
clearLocaleStorageTokens();
// store tokens to a local storage
yield storeTokens(tokens);
if (tokens) {
yield storeTokens(tokens);
}

@@ -82,10 +84,5 @@ if (hasExpirationProperty(tokens)) {

yield all([
takeEvery(SET_AUTH_TOKENS, function* setAuthTokens(action) {
yield race({
task: setTokensHandler(action, refreshTokensTimeout),
abort: take([ACCESS_TOKEN_UNAVAILABLE, AUTH_REFRESH_TOKEN_FAILURE]),
});
}),
takeEvery([ACCESS_TOKEN_UNAVAILABLE, AUTH_REFRESH_TOKEN_FAILURE], clearTokensHandler, refreshTokensTimeout),
takeEvery(SET_AUTH_TOKENS, setTokensHandler, refreshTokensTimeout),
takeEvery(ACCESS_TOKEN_UNAVAILABLE, clearTokensHandler, refreshTokensTimeout),
]);
}
# Tokens
This directory contains logic for **storing and retrieving tokens** to and from a local storage and **setting timeout for refreshing tokens** before they expire.
This directory contains logic for **storing and retrieving tokens** to and from a local storage (if persistance option isn't `NONE`) and **setting up timeout for refreshing access token** before it expires.

@@ -9,3 +9,3 @@ ## How does it work

- retrieve tokens from a local storage
- retrieve tokens
- if tokens exist and aren't expired

@@ -16,7 +16,7 @@ - send tokens to Redux store (dispatch `SET_AUTH_TOKENS` action)

Since this triggers auth. flow, this saga should be initialized as last one.
Since this triggers auth. session flow, this saga should be initialized as last one.
2. ### `tokens.js`
This saga stores tokens and sets timeout for their refreshing on `SET_AUTH_TOKENS`. And on `AUTH_LOGOUT`, it's going to clear the tokens tokens and the timeout.
This saga stores tokens and sets timeout for their refreshing on `SET_AUTH_TOKENS`. And on `ACCESS_TOKEN_AVAILABLE`, it's going to clear those tokens with the timeout for refreshment.

@@ -23,0 +23,0 @@ 3. ### `RefreshTokensTimeout.js`

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