Answer the question
In order to leave comments, you need to log in
Basic auth in React?
Good day to all! in the component, in the componentDidMount method, I check the user authentication in the following way:
axios({
url: '/remap/1.1/entity/organization',
method: 'post', // default
baseURL: 'https://domain-test/api/',
// headers: {'X-Requested-With': 'XMLHttpRequest'},
auth: {
username: 'admin',
password: '123456'
},
responseType: 'json',
responseEncoding: 'utf8',
}).then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
Answer the question
In order to leave comments, you need to log in
You need to enable CORS for your local domain on your web server.
Express.js middleware example:
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question