axios.defaults.withcredentials code example

Example 1: Axios withCredentials

import axios from 'axios'

axios.post(API_SERVER + '/login', { email, password }, { withCredentials: true })

Example 2: axios.defaults.withcredentials = true

const corsConfig = {
  origin: true,
  credentials: true,
};

app.use(cors(corsConfig));
app.options('*', cors(corsConfig));

Example 3: axios httponly cookie

server: 
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:3000');
res.setHeader('Access-Control-Allow-Credentials',true);

client(axios):
axios.defaults.withCredentials = true;

Tags:

Css Example