Answer the question
In order to leave comments, you need to log in
How to implement tokens in react?
Good afternoon! What is the best way to implement tokens in react using something like this:
const instance = axios.create({
baseURL: "http://.../api/",
timeout: 1000,
headers: {Authorization: 'Bearer '}
});
Answer the question
In order to leave comments, you need to log in
You can write a function that will write the token to the default headers and call it when the token is received.
import Axios from 'axios';
const setupAxios = token =>
(Axios.defaults.headers = {
Authorization: `Bearer ${token}`,
});
export default setupAxios;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question