I am currently developing an application using Next.js and I have a file called actions.ts
where all my functions for fetching and adding data from my Vercel Postgres store are stored. After these functions, I want to revalidate the data so I included export const revalidate = 1
in order to achieve this. However, it seems that setting it to use server
is also necessary because without it, @vercel/postgres
cannot locate the CONNECTION_URL
. The issue is that the revalidate
variable does not work with use server
.
What steps should I take?
Below is my code:
"use server"
import { sql } from "@vercel/postgres";
import { revalidatePath } from "next/cache";
export const revalidate = 1;
export async function fetchProjects() {
const { rows } = await sql`SELECT * FROM projects`
return rows
}
export async function fetchProjectById(id: string) {
const { rows } = await sql`SELECT * FROM projects WHERE id = ${id}`
return rows[0]
}
// Other functions omitted for brevity
export async function deleteMilestone(id: string, project_id: string) {
await sql`DELETE FROM milestones WHERE id = ${id};`
revalidatePath("/projects/[slug]")
}
An error occurs when trying to export constants while using use server
. I am unsure of what actions to take as I require both functionalities in my code.