Skip to main content

I’m seeing some unexpected behavior with an OAuth token and it’s requests. 

I’ve a Token fetch setup that works as expected. But after having recived said token and go to make API requests with it, none of them return with good data. They all return with an error of 430: invalid token. 

Below is a snippet of my user `/me` request. It returns a a 403 with a fresh token

const fetchUserData = async (token: string) => {
fetch(`https://api.figma.com/v1/me`, {
headers: {
'Authorization': `Bearer ${token}`,
}
})
.then(response => response.json())
.then(response => {
if (response.status === 403) console.log(`${response.status}: ${response.err}`)
else {
console.log(`Logged into Figma as ${response.handle}`);
setUserData(response);
}
})
.catch((error) => {
throw new Error (`API Request Failure: ${error}`);
});
};

 

UPDATE: 

This issue is intermittent. I have gotten a positive response to this code. I’ve adjusted it for better error handling. 

const fetchUserData = async (accessToken: string) => {
fetch(`https://api.figma.com/v1/me`, {
headers: {
'Authorization': `Bearer ${accessToken}`,
'Content-type': 'application/json'
}
})
.then(response => response.json())
.then(response => {
if (response.status >= 400) console.log(`${response.status}: ${response.err}`)
else {
console.log(`Logged into Figma as ${response.handle}`);
setUserData(response);
}
})
.catch((error) => {
console.error('API Request Failure:', error);
throw new Error (`API Request Failure: ${error}`);
});
};

 


Reply