Error with webpack
Unanswered
Hackberry nipple gall parasitoid posted this in #help-forum
Hackberry nipple gall parasitoidOP
Hi guys, im developing a project with nextjs, prisma and supabase and im creating a system for publish a project into the website, it put the data in database and storage if contain a file, but then i encounter this problem
Error:
attached
Code:
Error:
attached
Code:
'use server'
import { createClient } from '@/utils/supabase/server'
import { redirect } from 'next/navigation'
import prisma from '@/lib/prisma';
export async function publish(formData: FormData) {
const supabase = await createClient()
const { data: { user }, error: userError } = await supabase.auth.getUser();
if (userError || !user) {
console.error('Error while retrieving user:', userError?.message);
throw new Error('User not authenticated');
}
// type-casting here for convenience
// in practice, you should validate your inputs
const name = formData.get('name')?.toString() || '';
const description = formData.get('description')?.toString() || '';
const file = formData.get('file') as File | null;
if(file){
console.log(file.name)
console.log(file)
const timestamp = Date.now();
const { data, error } = await supabase.storage
.from('projects')
.upload(`projects/${timestamp}_${file.name}`, file);
if (error) {
console.error('Errore while uploading the file:', error.message);
throw new Error('Errore while uploading the file');
}
const fileUrl = `${process.env.NEXT_PUBLIC_SUPABASE_URL}/storage/v1/object/public/projects/${data.path}`;
console.log(name)
console.log(description)
const project = await prisma.project.create({
data: {
nome: name,
descrizione: description,
file: fileUrl,
creator_id: user.id,
},
});
redirect('/');
} else {
throw new Error('No file uploaded');
}
}