Crema React
v-3
v-3
  • About Crema
  • Crema 4.x (Next version)
  • Overview
    • Crema Overview
    • Folder Structure
      • @crema
      • page
      • redux
      • shared
      • types
    • GitHub Access
    • Slack Community
    • Figma File
  • Development
    • Installation
      • Pre-Requisites
      • Installing Crema
    • Route Overview
    • Add New Route
    • Auth User
    • Authentication Methods
    • API Calls
    • Multilingual
      • Adding New Language
      • Changing Language
    • Style Framework
  • MUI
    • Theme Color
    • Sidebar Configuration
      • Adding New Menu
      • Menu Color Theme
    • Navigation Style
    • Footer Configuration
      • Footer
      • Footer Type
    • Template Mode
    • Template Direction
  • Next-Js
    • About Next.JS
    • Folder Structure
    • Installing Next jS
    • Authentication
    • Add New Route
    • Deploy to server
  • FAQ
  • React Bootstrap
    • About React-Bootstrap
    • Styled Framework
    • RTL
    • Dark Theme
  • ANT Design
    • About Crema Ant
    • Style Framework
  • Servers
    • Python
    • Laravel
    • Mongoose
  • Credits
  • Crema V-2
Powered by GitBook
On this page

Was this helpful?

  1. Development

API Calls

We are using the Axios to make an api call. Here is the global this Axios configuration. You can find it on this path src/@crema/services/auth/jwt-auth/index.js

We are using the Axios to make an api call. Here is the global this Axios configuration. You can find it on this path src/@crema/services/auth/jwt-auth/index.js

import axios from "axios";

const jwtAxios = axios.create({
  baseURL: "https://BACKEND_SERVER_ATH/api/", // YOUR_API_URL HERE
  headers: {
    "Content-Type": "application/json",
  },
});

jwtAxios.interceptors.response.use(
  (res) => res,
  (err) => {
    if (err.response && err.response.data.msg === "Token is not valid") {
      console.log("Need to logout user");
    }
    return Promise.reject(err);
  }
);
export const setAuthToken = (token) => {
  if (token) {
    jwtAxios.defaults.headers.common.Authorization = `Bearer ${token}`; 
    //You can define any header params like Authorization based on the your requirements
    localStorage.setItem("token", token);
  } else {
    delete jwtAxios.defaults.headers.common.Authorization;
    localStorage.removeItem("token");
  }
};

export default jwtAxios;

import jwtAxios from "../auth/jwt-auth";
const MockAdapter = require("axios-mock-adapter");
export default new MockAdapter(jwtAxios, { delayResponse: 100 });

Last updated 3 years ago

Was this helpful?

We are using the mock APIs in our app, to gets the fake data from the Crema fake db. We are using to achieve this. Here is the configuration of it.

axios-mock-adapter