Skip to content

absurd-npm/Config-Functions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Topics

Resources

License

Stars

Watchers

Forks