Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions migrations/1772922678763_initial-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ CREATE INDEX idx_shared_links_token ON shared_links(share_token);
CREATE OR REPLACE FUNCTION handle_new_user()
RETURNS TRIGGER AS $$
BEGIN
INSERT INTO profiles (id, display_name, avatar_url)
INSERT INTO public.profiles (id, display_name, avatar_url)
VALUES (
NEW.id,
COALESCE(NEW.raw_user_meta_data->>'full_name', NEW.email),
NEW.raw_user_meta_data->>'avatar_url'
);
RETURN NEW;
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;
$$ LANGUAGE plpgsql SECURITY DEFINER SET search_path = public;

CREATE TRIGGER on_auth_user_created
AFTER INSERT ON auth.users
Expand Down
5 changes: 5 additions & 0 deletions src/db/saved-simulations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { supabase, isSupabaseConfigured } from '../auth/supabase-client';
import { authStore } from '../auth/auth-store';

/** Row shape for the saved_simulations table */
export interface SavedSimulation {
Expand Down Expand Up @@ -49,9 +50,13 @@ export async function saveSimulation(sim: {
}): Promise<SavedSimulation | null> {
if (!isSupabaseConfigured()) return null;

const user = authStore.getState().user;
if (!user) return null;

const { data, error } = await supabase
.from('saved_simulations')
.insert({
user_id: user.id,
title: sim.title,
description: sim.description || '',
sim_type: sim.sim_type,
Expand Down
Loading