Authentication patterns for AI-generated apps
How to choose an access model, put permission rules on the server, and test them before your app holds anyone else's data.
What authentication for AI-generated apps actually requires
An AI-generated app often gets the sign-in screen right and the data behind it wrong. The page looks protected, the admin buttons disappear for the wrong people, and the records underneath can still be read by anyone who asks the right way. Authentication for AI-generated apps is two jobs, not one: deciding who may enter, and enforcing what each person may touch on the server, on every request.
Do them in that order. Below is the sequence, what to ask for in the chat, and the tests that show the result holds before real people put real data in.
Start with one of three access models
Every Draftship app has three access models, set in Dashboard → Login & access. Changes apply right away, without a rebuild.
| Setting | Who gets in | When they sign in |
|---|---|---|
| Public | anyone | only where the app asks |
| Sign-in required | anyone with an account | before they see anything |
| Private (Pro) | people you invite or approve | before they see anything |
Pick the model before you write any data rules, because it decides what "anonymous" means in your app.
- Public suits a landing page, a guestbook, a public dashboard. Anyone can read, and sign-in only appears where you ask for it.
- Sign-in required suits a product where every screen is personal: a tracker, a workspace, a client portal. Visitors who are not signed in land on the app's sign-in page at
/_ds/loginon your app's address. - Private suits a closed beta or an internal tool. People arrive by invite or by access request, and on a private app a sign-up without an invite becomes an access request rather than a member.
With sign-in required or private, Draftship checks every request to your app's data, not just the pages, and keeps the app out of search results.
Choose a sign-in method that matches your users
- Email and password. The default. Passwords are 8 characters or more and "Forgot password?" is built in.
- Email confirmation codes. A 6-digit code, usable once, valid for 10 minutes, with 5 tries and an option to send a new one. Optional for ordinary public-app sign-ups, always required for private apps, invited people and administrator sign-ups. Nobody signs in until they confirm.
- Google. One click, no password or code, once the Google connector is set up on your Draftship server.
- Single sign-on (Pro+). Microsoft Entra ID, Okta, Google Workspace or any OpenID Connect provider. You enter the issuer URL, client ID and secret, and register the redirect URL with your provider. You can limit sign-in to company email domains, and let SSO users into a private app without an invite.
A rough rule: consumer product, email and password plus Google. Company tool, SSO with no passwords. Small beta, private with invites.
Password reset is worth checking too. The emailed link works once for one hour, and choosing a new password signs the person out on every other device. Someone who signed up with Google or SSO can use the same flow to add a password.
The check that matters: rules on the server, not hidden buttons
This is where generated apps break. Asking the AI to hide a delete control for non-admins changes the interface. It does not change who can call the delete. A hidden control is a design choice, not a permission.
In Draftship, each table has four permissions: create, read, update and delete. You describe the intent in the chat and Draftship writes the rule into the table's schema file. For a contact form where anyone may submit but only you may read:
"rls": {
"create": true,
"read": { "user_condition": { "role": "admin" } },
"update": { "user_condition": { "role": "admin" } },
"delete": { "user_condition": { "role": "admin" } }
}
Watch the defaults. A table with no rules of its own lets anyone create and read records, and lets only the creator update or delete them. Anonymous records, with no signed-in user attached, can only be changed by admins. That default is reasonable for a public guestbook and wrong for a table of invoices.
Sometimes a record should be public but one field should not, like the email on a guestbook note. Field-level rules hide a field from anyone who fails the rule, and can also block who may set it. Hidden fields are removed before filters run, so they cannot be guessed with queries. created_by can be hidden the same way.
A rule you can read is not the same as a rule the server enforces. If a page hides something, the data call behind it must refuse as well, otherwise the interface is the only thing standing between a stranger and the records.
Roles and per-record permissions
Draftship has two roles, user and admin. Admins pass every data rule, so keep the list short. The first account registered with the owner's Draftship email becomes admin automatically, and you can change roles in Dashboard → Users.
Beyond roles, write rules about the record itself: limit a table to the person who created each row, leave reading open while keeping editing with the author, or restrict a single field such as a status to admins. Say which of those you want in the chat, then open the schema file and check what it wrote.
Profile fields set through updateMe are available in rules as user.data.<field>. Email, role and id cannot be changed that way, and neither can any field your access rules read, since that would let someone edit their way past a rule.
If you already have tables, run a security scan and use Apply fix on what it reports. It adds field rules of the kind above.
Test it as a stranger and as the wrong user
Reading the rules is not the same as proving them. Work through this list in a private browser window:
- Signed out. Open the app's address directly and try to reach an inner page by URL. On sign-in required or private, you should land on the sign-in page.
- Signed out against the API. The pages and the data are checked separately, so confirm a request without a token is refused rather than returning records.
- As a second user. Register a second account, create one record, then try to open the first user's record. It should fail, not render empty.
- As that person. In Dashboard → Users, use the eye icon to open the app as them and see exactly what they see.
- What is stored. Use the Data tab to check the records themselves, including fields you expected to be hidden.
- Blocked. Block a test account and confirm it is signed out everywhere.
OWASP's authentication cheat sheet covers the account side: password strength controls, password recovery, error messages, and protection against automated attacks such as login throttling and account lockout.
Common mistakes in generated apps
- Asking for a hidden button instead of a rule. Fix the rule, then decide about the button.
- Leaving a table on its default permissions because the app looked finished.
- Hiding a field in the interface but not with a field-level rule, so it still ships to the browser.
- Inviting people before email delivery is configured. Confirmation codes, reset links and invites are sent from your app's name and need email sending set up on your Draftship server.
- Flipping an app to private and assuming the door is shut. People who already had an account keep access, so block the ones who should lose it.
- Treating the admin preview as a test. When you preview a private app in Draftship you are signed in as its admin automatically, which is exactly the view that hides permission bugs.
- Forgetting that session tokens are scoped to one app and valid for 30 days. Blocking someone is your lever when they leave.
Doing it with Draftship
Sign-in and permissions are built into every Draftship app, so you are configuring rather than wiring up an auth library. Set the access model in Dashboard → Login & access, choose methods, invite people from Dashboard → Users, then write your rules in the chat and test them signed out and as a second account.
The pages worth reading next are Managing login and registration for access models and sign-in methods, Managing data permissions for rule formats and defaults, and Auth for tokens, roles and how the server resolves a caller in your own functions.
Primary sources
- Authentication - OWASP Cheat Sheet Series · cheatsheetseries.owasp.org
- Authorization - OWASP Cheat Sheet Series · cheatsheetseries.owasp.org
This article was drafted with AI assistance from the primary sources listed below and checked automatically against them. An editor hasn't reviewed it yet.