---
title: "Comment by Mike Dabydeen on \"Your AI-built app's signup is open to anyone who calls the API\" | Hashnode"
description: "The step 6 hook works, but I'd change how it finds the duplicate before relying on it. Wrapping auth.users.email in public.normalise_email() means Postgres can'"
url: "https://hashnode.com/posts/your-ai-built-app-s-signup-is-open-to-anyone-who-calls-the-api/6ac6026a1d96f574c0c6e600/comment/6ac62b138af1e2443c07b46c"
---

[Discussion](https://hashnode.com/posts/your-ai-built-app-s-signup-is-open-to-anyone-who-calls-the-api/6ac6026a1d96f574c0c6e600)

Comment [Your AI-built app's signup is open to anyone who calls the API](https://hashnode.com/posts/your-ai-built-app-s-signup-is-open-to-anyone-who-calls-the-api/6ac6026a1d96f574c0c6e600)

[Mike Dabydeen](https://hashnode.com/@firelinks)

[Oct 7](https://hashnode.com/posts/your-ai-built-app-s-signup-is-open-to-anyone-who-calls-the-api/6ac6026a1d96f574c0c6e600/comment/6ac62b138af1e2443c07b46c)

The step 6 hook works, but I'd change how it finds the duplicate before relying on it. Wrapping auth.users.email in public.normalise\_email() means Postgres can't use the email index, so every signup scans the whole users table. Supabase gives Postgres hooks 2 seconds, so past some user count the check starts timing out and blocking real signups along with the repeats.

It also has a race. Two signups for Your.Name+a and Your.Name+b sent at the same moment both run the exists query before either user row is committed, and both get through.

A table you own fixes both. Give public.signup\_keys the normalised email as its primary key, and have the hook run insert ... on conflict do nothing and refuse when no row went in. The primary key is the index, and a second insert of the same key waits for the first and then conflicts. The trade is that a key can stay behind if account creation fails after the hook, so someone needs a way to clear it. It's your trial\_claims idea from step 4, moved one step earlier.

[Elijah Brown](https://hashnode.com/@elijahbrown)

[Oct 7](https://hashnode.com/posts/your-ai-built-app-s-signup-is-open-to-anyone-who-calls-the-api/6ac6026a1d96f574c0c6e600/comment/6ac62b138af1e2443c07b46c#reply-6ac63690a6013ae9a0e7b272)

You're right on both, thanks Mike. Wrapping the column in a function means the email index can't help, and two concurrent exists checks can both pass before either user row commits.

I'm changing step 6 to the table you describe: the normalised email as the primary key, insert on conflict do nothing in the hook, and refuse when no row went in. I'll add a backfill from existing users and a note on clearing a key when account creation fails, or when someone deletes their account and should be allowed back. The Lovable prompt gets the same change.
