I am trying to make a view counter which saves the ip once per day
"use server";
import { ArticleSchemaType } from "@/validations/types";
export async function AddView(
articleData: ArticleSchemaType,
userIP: string | null
) {
if (!userIP) return;
const view = await fetch(`${process.env.NEXT_PUBLIC_PAYLOAD_URL}/api/view`, {
method: "POST",
credentials: "include",
headers: {
"Content-Type": "application/json",
Authorization: `users API-Key ${process.env.API_KEY}`,
},
body: JSON.stringify({
ip: userIP,
article: articleData.id,
timestamp: new Date().toISOString(),
}),
cache: "force-cache",
next: {
//1 day
revalidate: 86400,
},
});
console.log(view);
}
Why is it that everytime i do a refresh, a new view is added in the backend? I have the cache headers set correctly