Deleting tickets
If you can create a ticket, you should also be allowed to delete it. We’ll now implement such a functionality in the details view and improve our RLS once more by doing so.
Go to tickets/details/[id]/page.js
. Here, we first want to identify whether we want to show a Delete ticket button or not. For that, we want to check whether the service user ID of the ticket is the same as ours. That’s why we need to fetch our own service user ID, which we do right below if (error)
:
const supabase_user_id = (await supabase.auth.getUser()).data.user.id; const { data: serviceUser } = await supabase .from("service_users") .select("id") .eq("supabase_user", supabase_user_id) .single();
We can safely assume, having previously fetched the ticket data and checked for an error, that this request will succeed. Hence,...