I am trying to make Axios request with Bearer token.
This is my Axios function.
import axios from "axios"
import {auth} from '../../config/firebase.config'
export function createRequest(upload) {
const tenantId = localStorage.getItem("tenantId")
const isUser = auth.onAuthStateChanged((user) => {
if (user) {
return auth.currentUser
}
});
if (isUser) {
const user = auth.currentUser;
const idToken = user.getIdToken(true);
return axios.create({
baseURL: `${process.env.REACT_APP_BASE_API_URL}/${tenantId}/`,
headers: {
"Content-type": !upload ? "application/json" : "multipart/form-data",
Authorization: `Bearer ${idToken}`
}
})
}
return null
}
But the problem is my user id always returns null. I refer this link on StackOverflow and firebase doc. I did everyting according to the docs. But still not working.