What is the best method to fetch a specific post from supabase for showcasing in a dynamic Route with Nextjs14?

I'm currently working on a Next.js application where I am fetching posts from a Supabase database. Everything works fine when retrieving all posts, but when trying to retrieve a single post dynamically using the ID, the screen displays null. Here's a breakdown of the folder structure:

The code in app/notes/page.tsx retrieves all the posts (also referred to as bounties).

import { createServerComponentClient } from "@supabase/auth-helpers-nextjs";
import { cookies  } from "next/headers";
import { createSupabaseAppServerClient } from "@/utils/supabase/supabaseAppRouterClient";

import {createBrowserClient, createServerClient} from "@supabase/ssr";

export default async function Notes() {

    const supabase = createServerComponentClient<any, "public", any>( { cookies},
         {supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL,
         supabaseKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY});
    const { data } = await supabase.from("bounties").select();
    return( 
        <pre><code>app/pages/notes/[...id] is responsible for displaying specific notes based on their IDs, but unfortunately it returns null on the screen.

import { createServerComponentClient } from "@supabase/auth-helpers-nextjs";
import { cookies } from "next/headers";


export default async function Page(
    {params : {id}} : {params: {id: string}}
    ) {
    const supabase = createServerComponentClient<any, "public", any>( { cookies},
        {supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL,
        supabaseKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY});
    
    const { data} = await supabase.from('bounties').select().eq('id', 'bounty_id').single();
    return(
        <pre>{JSON.stringify(data, null, 2)}</pre>
    );
}

Answer №1

Make sure to include the id variable in the eq filter when querying the data from the 'bounties' table:

const { result} = await supabase.from('tasks').select().eq('task_id', id).single();

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Gamepad interference causing obstruction of `requestAnimationFrame()`

I'm currently working with the Gamepad API and finding it a bit challenging due to its limited development. It appears that there is no "gamepadbuttondown" event available, which can be frustrating. I came across a library called 'awesome-react-g ...

Resetting the selected options in AngularJS dropdown lists

Utilizing ng-repeat in my HTML code to iterate over a JavaScript array and displaying it within a selection. I am trying to achieve the functionality of clearing all selected data from these dropdown lists when a button is clicked. Snippet of HTML: <d ...

"Turn a blind eye to Restangular's setRequestInterceptor just this

When setting up my application, I utilize Restangular.setRequestInterceptor() to trigger a function that displays a loading screen whenever a request is made with Restangular. Yet, there is a specific section in my application where I do not want this fun ...

What is the process for displaying user input on the console?

How can I ensure that the server is receiving user input? What steps should I take to print this input to the console? Currently, the console.log statement only displays "About to create new room", but I require the user input as well. Client-Side: // C ...

Can TypeScript modules be designed to function in this way?

Seeking to create a versatile function / module / class that can be called in various ways: const myvar = MyModule('a parameter').methodA().methodB().methodC(); //and also this option should work const myvar = MyModule('a parameter') ...

Invoke a function or variable based on a string parameter within a JavaScript/React function dynamically

I am currently exploring ways to dynamically call a function based on a string or reference a variable using a string. For example: import React, {useState} from 'react' const array = [ { text: 'count1', setFunctionName: &apo ...

I would like guidance on how to use onClick to toggle the opening and closing of components, and also how to dispatch a close action

i use createSlice from redux toolkit to create my reducers, where I defined the states below is the code for my store in ./root/app/store.js import { configureStore } from "@reduxjs/toolkit"; import calendarReducer from '../features/calenda ...

Iterating over an object while omitting certain elements

Is there a way to insert a separator at a specific position in JSX? For example, I have a list that displays text when an item is clicked: https://i.sstatic.net/s71yE.png Here is the code: <Accordion> {items.map((item, index) => ( <Acco ...

Unable to utilize a function within a mongoose schema

I encountered an issue while attempting to access the schema methods of a mongoose schema in TypeScript. Schema const userSchema: Schema<IUser> = new Schema( { name: { type: String, required: [true, "Name is required"], ...

Supabase's nodejs implementation fetches a single row at a time

Recently joined Supabase and facing an issue. Initially, I can fetch entire arrays when visiting the root '/' for the first time. However, subsequent visits to '/' after accessing a specific restaurant route '/:id' only retu ...

Could someone help me understand this JavaScript code where a function takes an object as a formal parameter?

Within a Vue component's methods, I came across the following code snippet defining a function: methods: { onEditorChange({ editor, html, text }) { console.log('editor change!', editor, html, text) this.content = html ...

Exporting dynamic routes in Next.js for static rendering

As I work on developing a web application with Next.js that includes a CMS for updating pages, my aim is to utilize the same codebase to build native iOS and Android apps using Capacitor - a WebView container technology (refer here). The current setup inv ...

Issues with React JS and JavaScript filtering functionality not working correctly

I've been working on implementing a filter feature for a website, using an HTML range slider. However, I've encountered an issue where the values only update correctly when decreasing. For example, if I set the slider to $500, only products that ...

grab the destination URL from the embedded frame

Thank you for your attention. I am working with three iframes spread across different HTML documents. Here is how they are organized: In the file iframemain.html, there is: <iframe src="iframeparent.html" width="100%" height="600"> </iframe> ...

Using the Set function to compare distinct elements within different arrays

Update: After reviewing the link shared by faintsignal, it appears to be the most suitable answer. It not only clarifies why this behavior is happening but also provides a solution to the issue at hand. I am currently working with an array and trying to d ...

Include the window.innerWidth value in the initial GET request

When dealing with a server-side rendered app that has responsive styling based on window.innerWidth, the challenge lies in how to pass the client's screen size in the initial GET request for index.html. This is crucial so that the server can prepare a ...

Matching wildcard paths using Express

Seeking help with routing in Express. I am trying to have both /m/objectID and /m/someslug/ObjectID directed to the same function. My current setup is as follows: app.get("/m/:id", ...); app.get("/m/(.*)/:id", ...); The first route is working properly, b ...

How can CSS and JavaScript be used to strategically position two upright images next to each other within a dynamically resizing container?

Looking for a way to display two portrait images side by side within a flexible container with 100% width? The challenge I'm facing is accommodating varying widths of the images while ensuring they are the same height. <div class="container"> ...

Altering the hue of various stroke patterns

I've encountered an issue where I want to create skill bars that display my skills in percentages. Luckily, I found a great code that allows me to do this. Although I would prefer to do it myself, I haven't come across a good tutorial that teache ...

Tips for Saving JSON Response from Fetch API into a JavaScript Object

I am facing an issue trying to store a Fetch API JSON as a JavaScript object in order to use it elsewhere. The console.log test is successful, however I am unable to access the data. The Following Works: It displays console entries with three to-do items: ...