Hi everyone! I'm encountering a strange issue where my API endpoint works perfectly fine outside of useQuery but fails when used within it. I'm using "next": "14.2.5"
What's strange is:
The endpoint works perfectly when called directly or in a normal fetch
Within useQuery, I get a 200 status code
But response.json() fails with: SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON
Console logs show the token is available and response status is 200
Here's my code:
const { data, isLoading, isError } = useQuery({
queryKey: ["verifications"],
queryFn: async () => {
const response = await fetch(
`${API_URL}/verifications`,
{
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${session?.user?.accessToken}`,
},
}
);
return response.json();
},
});