pgadmin4/web/pgadmin/static/js/csrf.js
Aditya Toshniwal 713ddb5f62
Remove usage of jQuery in pgAdmin.
Remove usage of Bootstrap in React components. #5701
2023-02-10 10:28:39 +05:30

29 lines
728 B
JavaScript

/////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
// Copyright (C) 2013 - 2023, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////
import axios from 'axios';
export function setPGCSRFToken(header, token) {
if (!token) {
// Throw error message.
throw new Error('csrf-token meta tag has not been set');
}
// Configure axios to set 'X-CSRFToken' request header for
// every requests.
axios.interceptors.request.use(function (config) {
config.headers[header] = token;
return config;
}, function (error) {
return Promise.reject(error);
});
}