0

A Simple db query in a table with just 2 rows takes atleast 12 seconds, sometimes timeout! What is the mistake in my code? My code works so credentials are correct. I don't use Supabase auth, so I use the service role only to fetch data in the backend.

import { createClient } from "@supabase/supabase-js";
import { NextRequest, NextResponse } from "next/server";

const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL!;
const serviceRoleKey = process.env.SUPABASE_SERVICE_ROLE_KEY!;
const supabase = createClient(supabaseUrl, serviceRoleKey);

export async function GET(req: NextRequest) {
  try {
    const { data, error } = await supabase.from("formdata").select("*");

    if (error) {
      throw error;
    }

    return NextResponse.json({ how: "Using client, serviceRoleKey", data });
  } catch (err: any) {
    return NextResponse.json({ error: err.message }, { status: 500 });
  }
}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.