Nextjs: Supabase response after inserting data is undefined
This is my function to add content:
this is the create client code:
this is the frontend call:
the console log for above call is
export async function addJournalContent(data: addJournalContentProps) {
const supabase = createClient();
try {
const { error } = await supabase.from('journal').insert([
{
uid: data.uid,
body: data.body,
},
]);
if (error) {
console.error('Error adding data to the "journal" table:', error.message);
return { status: 'error' };
}
console.log('Data added to the "journal" table');
return { status: 'success' };
} catch (error) {
console.error('Unexpected error:', error);
return { status: 'error' };
}
}this is the create client code:
import { createServerClient } from '@supabase/ssr';
import { cookies } from 'next/headers';
export function createClient() {
const cookieStore = cookies();
return createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
{
cookies: {
getAll() {
return cookieStore.getAll();
},
setAll(cookiesToSet) {
try {
cookiesToSet.forEach(({ name, value, options }) =>
cookieStore.set(name, value, options)
);
} catch {
// The setAll method was called from a Server Component.
// This can be ignored if you have middleware refreshing
// user sessions.
}
},
},
}
);
}
this is the frontend call:
const response = await addJournalContent(data)
console.log(response)
if(response.status === 'success'){
toast({
title: 'Journal Added Successfully!',
variant: 'success'
});
}
if(response.status === 'error'){
toast({
title: 'Failed to Add Journal! Please try again or wait a moment.',
variant: 'destructive'
});
}the console log for above call is
undefined. But the data is added successfully. How to fix this?