#Error invalid JSON format WITH html

1 messages · Page 1 of 1 (latest)

weary cloud
#

import { createClient } from "../../../../utils/supabase/server";
import { NextResponse } from "next/server";

export async function GET() {
const supabase = createClient();

const { data: { user }, error: authError } = await supabase.auth.getUser();

if (authError) {
console.error("Auth error:", authError.message);
return NextResponse.json({ error: authError.message }, { status: 500 });
}

const { data: userProfileData, error: queryError } = await supabase
.from("profiles")
.select()
.eq("id", user?.id)
.single();

if (queryError) {
console.error("Query error:", queryError.message);
return NextResponse.json({ error: queryError.message }, { status: 500 });
}

return NextResponse.json({ data: userProfileData }, { status: 200 });
}

se faccio il fetch dei dati mi dice che html non è un formato valido

nocturne mulchBOT
#

Hi @weary cloud. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the code you provided, it seems like you're trying to fetch user profile data from Supabase and return it as a JSON response. If you're getting an error that HTML is not a valid format, it might be due to the server returning an HTML response instead of a JSON response. This could happen if there's an error on the server side and it's returning an HTML error page.

One thing you could do is to check the response you're getting from the server. If it's not a JSON, it might be an HTML error page. You can do this by logging the response you get from the server.

Also, it's worth noting that the NextResponse.json() function is used to create a new NextResponse object with a JSON body. If you're getting an error with this function, it might be due to the data you're passing to it not being a valid JSON. Make sure that the data you're passing to NextResponse.json() is a valid JSON.

If you're still having issues, you might want to check the Next.js documentation (https://nextjs.org/docs/app/api-reference/file-conventions/error) or the Supabase GitHub org (https://github.com/supabase/supabase/issues/new/choose) for more information or to report an issue.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: