Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
apax-react-core
Advanced tools
Contains core react functionality developed by Apax Software LLC
Available functionality includes handling user account signup and login to DRF backends.
To connect to this repository locally, go to the root directory for apax-react-core:
yarn link
Then go to the project you want to connect (at the root level) and enter:
yarn link apax-react-core
To separate the projects again:
yarn unlink
inside apax-react-core level terminal.
This library requires a bit of configuration before it can be used. To do this, dispatch the following action early on in your application startup:
setEnv({app_evironment})
./redux/sagas.js
import { put } from 'react-saga/effects';
import { setEnv } from 'apax-react-core';
function* rootSaga () {
...
yield put(setEnv({
api_domain: process.env.REACT_APP_API_DOMAIN,
api_root: process.env.REACT_APP_API_ROOT,
token_name: process.env.REACT_APP_TOKEN_NAME,
}));
...
}
./redux/index.js
...
import { envReducer as env } from 'apax-react-core';
...
export const rootReducer = combineReducers({
env,
...
})
{
// Domain name of backing server
api_domain: 'localhost:8000',
// Root URL of the api (do not include the '/api')
api_root: 'http://localhost:8000',
// Name to give the cookie when storing the user token
token_name: 'react_core_app'
}
This library provides signup and login functionality for DRF backends. To use this functionality
add the account
sagas and reducers to you application:
./redux/index.js
import { accountReducer as account } from 'apax-react-core';
export const rootReducer = combineReducer({
account,
...
});
./redux/sagas.js
import { accountSagas } from 'apax-react-core';
function* rootSaga () {
...
yield call(accountSagas);
}
export default rootSaga;
./pages/auth/Signup.js
import { useDispatch } from 'react-redux';
import { useHistory } from 'react-router-dom';
import { signup } from 'apax-react-core';
...
export default function Signup() {
const history = useHistory();
const dispatch = useDispatch();
...
const onFormSubmit = (formData) => {
dispatch(signup(formData, history));
}
...
}
./pages/auth/Login.js
import { useDispatch } from 'react-redux';
import { useHistory } from 'react-router-dom';
import { login } from 'apax-react-core';
...
export default function Signup() {
const history = useHistory();
const dispatch = useDispatch();
...
const onFormSubmit = (creds) => {
dispatch(login(creds, history));
}
...
}
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.
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);
}
}
}
The following API methods are available:
apiGet(path, data|options)
apiPost(path, data|options)
apiPut(path, data|options)
apiPatch(path, data|options)
apiDelete(path, authenticationRequired = true)
Default options for the apiGet
, apiPost
, apiPut
, and apiPatch
methods can be overridden using
the format below (all fields are optional):
Note: When overriding options, request data
must be passed along inside of options
.
{
/*
Request data
default: null
*/
data: object,
/*
Extra headers to include with the request (key/value pairs)
default: undefined
*/
headers: object,
/*
Should request include authentication headers
default: true
*/
authenticationRequired: boolean,
}
import {
apiGet
} from 'apax-react-core';
...
const response = yield apiGet('api/mypath/');
MIT License
Copyright (c) 2020 Apax Software LLC
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Contains core react functionality developed by Apax Software LLC
The npm package apax-react-core receives a total of 2 weekly downloads. As such, apax-react-core popularity was classified as not popular.
We found that apax-react-core demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.