diff --git a/apps/supabase/migrations/20260827214553_restore_profile_email_on_signup.sql b/apps/supabase/migrations/20260827214553_restore_profile_email_on_signup.sql new file mode 100644 index 0000000..dcbf912 --- /dev/null +++ b/apps/supabase/migrations/20260827214553_restore_profile_email_on_signup.sql @@ -0,0 +1,35 @@ +-- A production schema sync replaced the signup trigger function without +-- copying auth.users.email. Redemption by email and admin user lookup both +-- depend on profiles.email being populated. +CREATE OR REPLACE FUNCTION public.handle_new_user() +RETURNS trigger +LANGUAGE plpgsql +SECURITY DEFINER +SET search_path TO '' +AS $function$ +BEGIN + INSERT INTO public.profiles ( + id, + email, + created_at, + updated_at, + onboarding_completed + ) + VALUES ( + NEW.id, + NEW.email, + NOW(), + NOW(), + false + ); + RETURN NEW; +END; +$function$; + +UPDATE public.profiles AS profile +SET email = auth_user.email, + updated_at = NOW() +FROM auth.users AS auth_user +WHERE profile.id = auth_user.id + AND profile.email IS NULL + AND auth_user.email IS NOT NULL; diff --git a/apps/supabase/tests/redeem-code.test.ts b/apps/supabase/tests/redeem-code.test.ts index 4cf89d6..b3ead62 100644 --- a/apps/supabase/tests/redeem-code.test.ts +++ b/apps/supabase/tests/redeem-code.test.ts @@ -34,7 +34,7 @@ Deno.test("redeem-code: successfully redeems code for user", async () => { }); const data = await res.json(); - assertEquals(res.status, 200); + assertEquals(res.status, 200, JSON.stringify(data)); assertEquals(data.success, true); // 4. Verify Profile is Premium