Feat: Implement Audit Logging and integrate into Reservation actions

This commit is contained in:
2025-12-03 22:32:34 +03:00
parent eb4fedef2a
commit 9538107a13
4 changed files with 115 additions and 24 deletions

View File

@@ -95,3 +95,28 @@ $$ language plpgsql security definer;
create trigger on_auth_user_created
after insert on auth.users
for each row execute procedure public.handle_new_user();
-- Create Audit Logs Table
create table audit_logs (
id uuid default uuid_generate_v4() primary key,
user_id uuid references auth.users(id),
action text not null,
entity_type text not null,
entity_id uuid,
details jsonb,
created_at timestamp with time zone default timezone('utc'::text, now()) not null
);
-- RLS for Audit Logs
alter table audit_logs enable row level security;
create policy "Admins can read all logs" on audit_logs
for select using (
exists (
select 1 from profiles
where profiles.id = auth.uid() and profiles.role = 'admin'
)
);
create policy "Users can insert logs" on audit_logs
for insert with check (auth.uid() = user_id);