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

apax-react-core

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apax-react-core - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

7

CHANGELOG.md

@@ -7,2 +7,9 @@ ## Changelog

## [1.1.0] - 2020-08-28
### Added
- SET_USER_TOKEN action now triggers a call to load user.
- Changes to support persistent login for non-web apps
## [1.0.0] - 2020-08-18

@@ -9,0 +16,0 @@

93

dist/index.es.js

@@ -695,3 +695,4 @@ import Cookies from 'universal-cookie';

function loadUser(token) {
function loadUser() {
var token = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
var user, tokenName;

@@ -718,20 +719,37 @@ return regeneratorRuntime.wrap(function loadUser$(_context3) {

_context3.next = 8;
return select(getToken);
case 8:
if (!_context3.sent) {
_context3.next = 16;
break;
}
_context3.next = 11;
return minDelayCall(api.loadUser);
case 8:
case 11:
user = _context3.sent;
_context3.next = 11;
_context3.next = 14;
return put({ type: LOAD_USER_SUCCESS, user: user });
case 11:
_context3.next = 21;
case 14:
_context3.next = 18;
break;
case 13:
_context3.prev = 13;
case 16:
_context3.next = 18;
return put({ type: LOAD_USER_ERROR });
case 18:
_context3.next = 28;
break;
case 20:
_context3.prev = 20;
_context3.t0 = _context3['catch'](2);
_context3.next = 17;
_context3.next = 24;
return select(getTokenName);
case 17:
case 24:
tokenName = _context3.sent;

@@ -741,6 +759,6 @@

_context3.next = 21;
_context3.next = 28;
return put({ type: LOAD_USER_ERROR });
case 21:
case 28:
case 'end':

@@ -750,3 +768,3 @@ return _context3.stop();

}
}, _marked3$1, this, [[2, 13]]);
}, _marked3$1, this, [[2, 20]]);
}

@@ -818,3 +836,3 @@

if (_context5.sent) {
_context5.next = 21;
_context5.next = 25;
break;

@@ -824,41 +842,46 @@ }

_context5.next = 13;
return take([LOGIN, SIGNUP]);
return take([LOGIN, SIGNUP, SET_USER_TOKEN]);
case 13:
action$$1 = _context5.sent;
_context5.t0 = action$$1.type;
_context5.next = _context5.t0 === LOGIN ? 17 : _context5.t0 === SIGNUP ? 20 : _context5.t0 === SET_USER_TOKEN ? 23 : 25;
break;
if (!(action$$1.type === LOGIN)) {
_context5.next = 19;
break;
}
_context5.next = 17;
case 17:
_context5.next = 19;
return call(doLogin, action$$1);
case 17:
_context5.next = 21;
break;
case 19:
return _context5.abrupt('break', 25);
case 19:
_context5.next = 21;
case 20:
_context5.next = 22;
return call(doSignup, action$$1);
case 21:
_context5.next = 23;
case 22:
return _context5.abrupt('break', 25);
case 23:
_context5.next = 25;
return call(loadUser);
case 25:
_context5.next = 27;
return select(getUser);
case 23:
case 27:
if (!_context5.sent) {
_context5.next = 30;
_context5.next = 34;
break;
}
_context5.next = 26;
_context5.next = 30;
return take(LOGOUT);
case 26:
_context5.next = 28;
case 30:
_context5.next = 32;
return select(getTokenName);
case 28:
case 32:
_tokenName = _context5.sent;

@@ -868,7 +891,7 @@

case 30:
case 34:
_context5.next = 0;
break;
case 32:
case 36:
case 'end':

@@ -875,0 +898,0 @@ return _context5.stop();

@@ -701,3 +701,4 @@ 'use strict';

function loadUser(token) {
function loadUser() {
var token = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
var user, tokenName;

@@ -724,20 +725,37 @@ return regeneratorRuntime.wrap(function loadUser$(_context3) {

_context3.next = 8;
return effects.select(getToken);
case 8:
if (!_context3.sent) {
_context3.next = 16;
break;
}
_context3.next = 11;
return minDelayCall(api.loadUser);
case 8:
case 11:
user = _context3.sent;
_context3.next = 11;
_context3.next = 14;
return effects.put({ type: LOAD_USER_SUCCESS, user: user });
case 11:
_context3.next = 21;
case 14:
_context3.next = 18;
break;
case 13:
_context3.prev = 13;
case 16:
_context3.next = 18;
return effects.put({ type: LOAD_USER_ERROR });
case 18:
_context3.next = 28;
break;
case 20:
_context3.prev = 20;
_context3.t0 = _context3['catch'](2);
_context3.next = 17;
_context3.next = 24;
return effects.select(getTokenName);
case 17:
case 24:
tokenName = _context3.sent;

@@ -747,6 +765,6 @@

_context3.next = 21;
_context3.next = 28;
return effects.put({ type: LOAD_USER_ERROR });
case 21:
case 28:
case 'end':

@@ -756,3 +774,3 @@ return _context3.stop();

}
}, _marked3$1, this, [[2, 13]]);
}, _marked3$1, this, [[2, 20]]);
}

@@ -824,3 +842,3 @@

if (_context5.sent) {
_context5.next = 21;
_context5.next = 25;
break;

@@ -830,41 +848,46 @@ }

_context5.next = 13;
return effects.take([LOGIN, SIGNUP]);
return effects.take([LOGIN, SIGNUP, SET_USER_TOKEN]);
case 13:
action$$1 = _context5.sent;
_context5.t0 = action$$1.type;
_context5.next = _context5.t0 === LOGIN ? 17 : _context5.t0 === SIGNUP ? 20 : _context5.t0 === SET_USER_TOKEN ? 23 : 25;
break;
if (!(action$$1.type === LOGIN)) {
_context5.next = 19;
break;
}
_context5.next = 17;
case 17:
_context5.next = 19;
return effects.call(doLogin, action$$1);
case 17:
_context5.next = 21;
break;
case 19:
return _context5.abrupt('break', 25);
case 19:
_context5.next = 21;
case 20:
_context5.next = 22;
return effects.call(doSignup, action$$1);
case 21:
_context5.next = 23;
case 22:
return _context5.abrupt('break', 25);
case 23:
_context5.next = 25;
return effects.call(loadUser);
case 25:
_context5.next = 27;
return effects.select(getUser);
case 23:
case 27:
if (!_context5.sent) {
_context5.next = 30;
_context5.next = 34;
break;
}
_context5.next = 26;
_context5.next = 30;
return effects.take(LOGOUT);
case 26:
_context5.next = 28;
case 30:
_context5.next = 32;
return effects.select(getTokenName);
case 28:
case 32:
_tokenName = _context5.sent;

@@ -874,7 +897,7 @@

case 30:
case 34:
_context5.next = 0;
break;
case 32:
case 36:
case 'end':

@@ -881,0 +904,0 @@ return _context5.stop();

{
"name": "apax-react-core",
"version": "1.0.0",
"version": "1.1.0",
"description": "Contains core react functionality developed by Apax Software LLC",

@@ -5,0 +5,0 @@ "author": "apaxsoftware",

@@ -164,2 +164,32 @@ # apax-react-core

### Persistent Login
By default `apax-react-core` will store the users token as a cookie after login. However, there may be some cases where
cookie storage is unavailable (such as React-Native environments) and so users logged in state will not persist between app loads.
This can be solved by storing the user token in the app (returned as `key` from `LOGIN_SUCCESS` or `SIGNUP_SUCCESS`) and then
triggering a `SET_USER_TOKEN` action when the app first loads. This action will set the user token and trigger a call to `LOAD_USER`,
effectively logging in the user.
#### Example
```
function* persistLogin() {
const user = yield select(getUser);
if (!user) {
const token = yield AsyncStorage.getItem(USER_TOKEN_KEY);
if (token) {
yield put(setUserToken(token));
} else {
// Wait for login or signup and store the token in local storage
const { key } = yield take([LOGIN_SUCCESS, SIGNUP_SUCCESS]);
yield AsyncStorage.setItem(USER_TOKEN_KEY, key);
}
}
}
```
### API

@@ -166,0 +196,0 @@

Sorry, the diff of this file is not supported yet

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