Crema React
v-4 Nextjs
v-4 Nextjs
  • About Crema Next.js
  • Overview
    • Crema Next.js Overview
    • Folder Structure
      • @crema
      • app
      • assets
      • modules
      • style
    • Package.json
    • GitHub Access
    • Slack Community
    • Figma File
  • Decelopment
    • Installation
    • Route Management
    • Auth User
    • Authentication Methods
    • Axios Config
      • APIs Calling
    • Multilingual
  • MUI
    • Theme Color
    • Sidebar Configuration
    • Navigation Style
    • Footer Configuration
    • Template Direction
    • Template Mode
  • FAQ
  • ANTD
    • About Crema Ant
    • Style Framework
  • Crema V-3 Doc
  • Servers
    • Python
    • Laravel
    • Mongoose
  • Credits
Powered by GitBook
On this page

Was this helpful?

  1. Decelopment

Axios Config

We are using the Axios to make an API call. Here is the global Axios configuration.

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

import axios from '@crema/services/axios';

const jwtAxios = axios?.create({
  baseURL: 'https://cremaapi.pythonanywhere.com/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');
      // store.dispatch({type: LOGOUT});
    }
    return Promise.reject(err);
  },
);
export const setAuthToken = (token) => {
  if (token) {
    jwtAxios.defaults.headers.common['Authorization'] = 'Bearer ' + token;
    localStorage.setItem('token', token);
  } else {
    delete jwtAxios.defaults.headers.common['Authorization'];
    localStorage.removeItem('token');
  }
};

export default jwtAxios;
import axios from '@crema/services/axios';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const MockAdapter = require('axios-mock-adapter');

export default new MockAdapter(axios, {delayResponse: 200});

Was this helpful?

We are using the mock APIs in our app, to get the fake data from the Crema fake DB. We are using to achieve this. Here is the configuration of it. you can find out this file here src/@crema/mockapi/apis/MockConfig.js

axios-mock-adapter