config-function

1.0.1 • Public • Published

Config-Functions

A utility atomic function to get config data before sending to api

Install

Install with npm:

$ npm install --save config-function

Functions It returns

configFunction()

Returns a normal config to call an api

export const configFunction = () => {
  const config = {
    headers: {
      "Content-Type": "application/json",
    },
  };
  return config;
};

tokenconfigFunction()

A config cunction which requires a bearer token with it

export const tokenconfigFunction = (userInfo) => {
  if (userInfo.token == undefined) {
    return undefined;
  }
  const { token } = userInfo;
  const config = {
    headers: {
      "Content-Type": "application/json",
      Authorization: `Bearer ${token}`,
    },
  };
  return config;
};

reduxConfigFunction()

A config cunction which requires a bearer token with it in redux

export const reduxConfigFunction = (getState) => {
  const {
    userLogin: { data },
  } = getState();
  const config = {
    "Content-Type": "application/json",
    headers: {
      Authorization: `Bearer ${data.token}`,
    },
  };
  return config;
};

Package Sidebar

Install

npm i config-function

Weekly Downloads

7

Version

1.0.1

License

ISC

Unpacked Size

2.83 kB

Total Files

3

Last publish

Collaborators

  • prasundas