Next.js Discord

Discord Forum

NEXTJS ECOMMERCE CMS DASHBOARD WITH SUPABASE

Unanswered
Japanese pilchard posted this in #help-forum
Open in Discord
Japanese pilchardOP
Hi good day, please I would need help on debugging a db response error I get when trying to use an rpc donation I created in my SUPABASE project that I would use to get the name of any enum_type I create.

So, I created an enum_type called categories and this will be an enum list of values for a column in the products table called category.

I want to fetch the values I have stored in the enum_type in the client side(CMS DASHBOARD THAT CAN BE USED TO ADD PRODUCTS) and use them in a drop-down. Upon writing my route.ts:

import { NextResponse, NextRequest } from "next/server";
import { supabase } from "@/utils/supabase";

export async function GET() {
    try {
        const { data, error } = await supabase.rpc('get_enum_values', {
            enum_type: 'categories'
        });

        if (error) throw error;

        // Handle array return type
        const categories = Array.isArray(data) ? data : [];

        return NextResponse.json({
            success: true,
            categories
        });
    } catch (error: any) {
        console.error("Error fetching categories:", error.message);
        return NextResponse.json({
            success: false,
            error: error.message
        }, { status: 500 });
    }
}

I get this response:
{
"success": "false",
"error": "Could not find the function public.get_enum_values(enum_type) in the schema cache"
}

0 Replies