Cache is still showing old data?
Unanswered
White Swiss Shepherd Dog posted this in #help-forum
White Swiss Shepherd DogOP
So I've created a form and fires a function in my action.ts file called subscribeToNewsletter, this is the function:
When I delete a row from the database it still shows when I do a console.log, it look like I'm grabbing data from the cache
export async function subscribeToNewsletter(
prevState: any,
formData: FormData
) {
const emailFormData = formData.get('email') as string;
const emailToLowerCase = emailFormData.toLowerCase();
try {
const schema = z.object({
email: z.string().email()
});
const data = schema.parse({
email: emailToLowerCase
});
const subscriber = await getSubscriber(data.email);
console.log('subscriber', subscriber);
if (subscriber) {
return {
message: 'You are already subscribed.'
};
}
const token = sign({ email: data.email }, process.env.JWT_SECRET!, {
expiresIn: '24h'
});
await sendEmailVerification({
email: data.email,
token
});
} catch (e) {
return {
message: 'Please enter a valid email address.'
};
}
redirect(`/verify?email=${emailToLowerCase}`);
}When I delete a row from the database it still shows when I do a console.log, it look like I'm grabbing data from the cache
3 Replies
White Swiss Shepherd DogOP
export const getSubscriber = async (email: string) => {
const supabase = getServiceSupabase();
const { data } = await supabase
.from('subscriber')
.select('*')
.eq('email', email)
.single();
return data;
};when I add
revalidatePath('/'); straight after the getSubscriber function the cache is correctly updated but this means it updates the path and I don't think this is the right way of doing this?I've also tried adding
export const revalidate = 0; to the page.tsx file