Lesson 8 of 16 · 55 min suggested practice
Add sign-in and test row-level security with two accounts
Give users cross-device saves while proving that one account cannot read or change another account's private records.
Design the account flow around a benefit
Keep the library and free downloads open. Offer sign-in when a visitor wants their saved list across devices, then explain that benefit directly. Choose the sign-in methods your audience needs rather than enabling every available provider. Include logout, recovery, and useful error messages.
Define what happens to browser-local favourites after login. A simple option is an explicit import action showing how many items will be added. Do not silently replace the user's existing account list or imply that old browser data was already synced.
Write ownership rules before polishing forms
A saved-resource row should belong to one user. Reading, creating, and deleting that row require the correct owner. The trusted part of the app must determine ownership; a client should not be able to submit someone else's user ID and gain access.
Review the generated policies. A rule that merely permits authenticated users may allow every signed-in user to access all covered rows. Public resource editing needs a separate administrator rule. Service-role requests bypass database RLS, so privileged server functions must enforce permissions themselves.
Run a two-account verification
Create account A and account B using synthetic test data. Save different resources in each account. Confirm that A sees A's saved list and B sees B's list. Then test direct requests for A's saved record while signed in as B; hiding it in the interface is insufficient.
Also test signed-out requests, expired sessions, duplicate saves, and attempts to edit public resource records as an ordinary user. Record the expected result and observed result for each case. A denied request should fail safely without exposing private data in the response.
Handle failures without weakening access
If a legitimate save fails, inspect the session, owner assignment, and policy condition. Do not solve the problem by opening the table to everyone. If a saved list leaks across accounts, stop the affected feature and repair the authorization path before sharing it.
Retest the complete login-to-save journey on the published app because redirect settings and production configuration can differ from the preview. Keep test accounts and records clearly marked, and remove them when they are no longer needed for verification.
Try this focused prompt.
Add optional account-based favourites to Resource Shelf. Public browsing and downloads remain open. Enforce owner-only reads, creates, and deletes for saved-resource records, and separate administrator permissions for catalogue edits. Do not trust a client-supplied owner ID. If privileged server functions bypass RLS, check ownership there too. Provide and run a two-account test using synthetic records, including direct requests, signed-out access, duplicate saves, and an ordinary user attempting a catalogue edit.
Replace the sample context with your own approved facts. Review Lovable’s proposed changes before accepting them.
Evidence before the next step
Check your work.
- Account A cannot access B's private saved records and vice versa.
- Signed-out and ordinary-user privileges match the written rules.
- The published login, recovery, and save flow is verified.
Your checkmark stays in this browser. It records your own progress, not a certification.
Official sources & further reading
- Users and authentication
- Control who can access your app's data
- Security overview
- Test and verify your app
Reviewed November 19, 2026. Plans, terminology and interfaces can change; follow the linked documentation if your workspace differs.