Next.js Discord

Discord Forum

missing_connection_string

Answered
Australian Freshwater Crocodile posted this in #help-forum
Open in Discord
Australian Freshwater CrocodileOP
Hi, I'm getting a lot of these errors on console for one specific component. I don't understand it because it is returning the correct data from the db and the Select is populating with the correct options.

import { HouseSearch } from '../forms/search';
import { fetchNationalities } from '@/lib/data';
import './filters.scss';

export default async function HouseFilter() {
    const nationalities = await fetchNationalities();
    console.log(nationalities);

    return (
        <div className="filter-bar">
            <HouseSearch />
            <div className="filter-filters">
                {
                    nationalities &&
                    <select name="houseNationality" className="filter-dropdown" aria-label="Select Nationality">
                        <option value="">Please select nationality</option>
                        {nationalities.map(nationality => (
                            <option key={nationality.id} value={nationality.id}>{nationality.name}</option>
                        ))}
                    </select>
                }
            </div>
        </div>
    )
}


export async function fetchNationalities() {
    noStore();

    try {
        const data = await sql<Nationality>`SELECT * FROM nationalities`;
        console.log(data);
        return data.rows;
    } catch (error) {
        console.error('Database Error:', error);
        throw new Error('Failed to fetch nationalities data.');
    }
}
Answered by Ray
is the parent a server or client component?
View full answer

11 Replies

Australian Freshwater CrocodileOP
I do, in .env file
where are you rendering <HouseFilter />?
is the parent a server or client component?
Answer
Australian Freshwater CrocodileOP
client component...which might be the cause
POSTGRES_URL is not accessable in client component
and you shouldn't use db query in client component
if you import the component to a client component, it will become a client component
Australian Freshwater CrocodileOP
thanks for this, i'll have a think around some better structure...