I'm new to using node-fetch and catch figure out why I am not getting any response data to print to the console.
Im using a function to generate firebase user auth tokens for testing but I'm not getting any response whereas in postman my requests with the same data are returning what I want. As you can see I've even hard coded the data into the body and still its not returning anything.
async function firebaseSetupAuth(){
const token1 = admin.auth().createCustomToken("xKdXw06u2tUVE72ETrJVwevCNQo1")
const token2 = await token1
token = token2
const url = "https://identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken?key=AIzaSyBoKaBKWe9x2LS_n5AHCIEM-5AB_dC99mg"
const fetchBody = {"token": token,"returnSecureToken":true }
console.log(JSON.stringify(fetchBody))
const response1 = fetch(url,{
method: "post",
body: fetchBody,
headers: {'Content-Type': 'application/json'}
})
const response2 = await response1
console.log(response2)
}
You need to return the result of fetch
.then((customToken) => {
return fetch(url,{ // return on this line
method: "post",
body: JSON.stringify(/*stuff*/),
headers: {'Content-Type': 'application/json'}
}
)
})