
Mini lesson · English
How to let users edit their profile information
Save and reload an account’s display name, then use a second test account to check that another person cannot change it.
Who is this for?
People who want editable user profiles. The supplied setup and a coding assistant handle the database rules; you focus on what each account can save and see.
Before you start
Your own disposable Supabase project with the supplied sign-in route working, plus two test accounts you control. Ask your coding assistant to apply the provided profile setup only in that project.
Estimated time: 20–32 min
Estimates for the supplied starter files with prerequisite accounts and tools ready. Setup, deployment queues and delivery/DNS waits take additional time. Actual authentication and row policies must be tested in your own provider account; UI-only simulation does not establish access control.
What you will learn
- Save a display name for the signed-in account.
- Verify persistence after reload.
- Check that a second account cannot alter the first account’s profile.
Step 1
Define the owner’s result
Changing a profile name should affect only that account.
Open the ready profile project with your assistant. Choose a distinctive display name for test account A. This is profile text, not a change to the email used for sign-in.
The service must enforce ownership even if a caller changes a request. A hidden account field is not the protection by itself.
A concrete example
Account B should not gain permission simply by submitting A’s identity.
Use the supplied profile workshop with my separate Supabase practice project. Apply the provided schema and ownership rules without opening anonymous access. Help me sign in as account A, save and reload a name, then test account B separately and confirm it cannot change A. Handle the implementation; explain the observable checks I should perform.Files for this step
Open or download the files below. When saving a project, keep the folder paths shown in the filenames.
How it works (optional)
Save profile information for its owner
A display name is editable profile data, not proof of identity.
We will store one display-name row for each account. The row ID matches that account’s verified user ID. Changing the display name does not change the email used to sign in.
The browser can request changes, but the database must enforce who can write each row. A user can alter a request outside the interface.
Worked example
If account B submits account A’s ID, B must not be allowed to overwrite A’s profile just because the request contains that ID.
Extra implementation exercise
Why is a hidden userId input not a sufficient ownership check?
Show a worked solution
The caller can change hidden inputs. Enforce ownership in the database or server using verified identity, not the submitted field alone.
- Treats browser fields as editable by the caller.
- Requires enforcement using the authenticated identity.
Common mistake
Using a display name or a browser-supplied ID as authorization.
Step 2
Apply the supplied profile setup
Use the isolated project and keep its ownership rules.
Ask your assistant to review and apply schema.sql in your disposable Supabase project. Use the ready sign-in configuration and launch the page.
Keep access restricted to the appropriate account. Do not broaden permissions merely because a first request fails; inspect the project and setup instead.
A concrete example
The implementation rules can be handled by the assistant while you verify their effect with two accounts.
Try it yourself
Did the practice setup complete, and which sign-in route can you actually open?
Discuss your answer with the lesson tutor
Show a worked solution
Illustrative readiness record: “The assistant checked the disposable project, applied the supplied profile setup there and kept owner-only permissions. The local HTTP app opens and my two controlled accounts can complete sign-in.”
A blocked example is “The page loads, but B cannot receive a code; cross-account testing is not ready.” Broadening table access would not repair that email setup problem.
- Confirms that the supplied schema was applied only to the disposable practice project.
- Records a working sign-in route or the exact provider/setup step still blocking it.
Files for this step
Open or download the files below. When saving a project, keep the folder paths shown in the filenames.
How it works (optional)
Create the table and ownership policies
Allow the signed-in role to act only on rows where auth.uid() matches the row ID.
Run schema.sql in your separate practice project. It creates a constrained display-name column and enables row-level security. The SELECT, INSERT and UPDATE policies cover different actions.
The update policy checks both the existing row and its new state. This prevents changing the owner ID as part of an edit. The example grants no anonymous access and no delete capability.
A hidden input or a userId property sent from the browser is editable by its caller. For a row owned by account A, the policy must reject account B even if B supplies A's ID. USING checks which existing row may be updated; WITH CHECK prevents changing its owner to an unauthorized new ID.
Worked example
An UPDATE rule without a corresponding ownership check for the new row can leave a gap. Read the full policy set instead of adding a broad allow-all policy to fix a failing query.
create policy "update own" on public.profiles
for update to authenticated
using (auth.uid()=id) with check (auth.uid()=id);Extra implementation exercise
Why does the update policy check the new row as well as the old row?
Show a worked solution
The existing row must belong to the caller, and the updated row must still belong to that caller. The browser is not trusted to preserve the ID.
- Recognizes that an update can change ownership fields.
- Preserves the owner constraint after the write.
Common mistake
Disabling row security because the first save returned an error.
Step 3
Save and reload your own name
Look for a persisted value, not a temporary label.
Sign in as A, enter the distinctive name and save it. Reload or reopen the page and read the value again.
A missing first profile is normal; a service error is different. Ask the assistant to keep an actual error visible rather than calling it “no profile.”
A concrete example
A name displayed only until reload may never have reached storage.
Try it yourself
What name did A save, and what appeared after reload?
Discuss your answer with the lesson tutor
Show a worked solution
Illustrative persistence record: “A saved A’s workshop profile. After reopening the app, A used Load profile and the page showed Stored display name: A’s workshop profile.”
“No profile has been created yet” would mean no saved row was found. “Could not read the profile” is a service/read error; neither is evidence that the chosen name persisted.
- Names the display value saved by A and the value loaded after reopening.
- Distinguishes a missing profile or service error from a successful stored read.
Files for this step
Open or download the files below. When saving a project, keep the folder paths shown in the filenames.
How it works (optional)
Save only the intended fields
The app constructs an explicit profile object and checks the returned result.
Configure the sign-in files, sign in and enter a display name. The app retrieves the verified user, trims and checks the name, then upserts the owner’s profile.
The name is displayed with textContent. An absent row is a normal first-use state; an actual read error is not the same as “no profile yet”. The backend constraints remain necessary even though the app validates the form.
Worked example
The inserted object contains only id and display_name. A random field added to the browser form is not automatically forwarded into the database.
Extra implementation exercise
If a caller bypasses the maxlength attribute, what still restricts the stored name?
Show a worked solution
The database constraint still enforces its length rule, and the ownership policies still control the row. Keep both checks.
- Identifies the database check constraint.
- Does not treat browser validation as the access or data-integrity boundary.
Common mistake
Forwarding all submitted fields into an unrestricted update.
Step 4
Try a second account
Use separate sessions so you know who is acting.
Use a separate browser profile for B and verify its account identity; another private window may share an already-open private session. Ask your assistant to run an isolated direct update with actor B but target A’s existing profile, and show those redacted labels before the attempt. The ordinary profile form writes the current user’s own row, so simply using B’s form is not this cross-owner test.
Try changing A’s name to a distinctive test value, then return to A and load its stored name. A’s original value must remain unchanged. A rejection may appear as an error or no affected row; confirm the final stored value rather than judging only a status label.
A concrete example
Illustrative check: actor B; target A; requested name B changed this; A’s loaded name still A’s workshop profile. The actual test must establish those identities without sharing reusable session tokens.
Try it yourself
Could B change A’s stored name, and how did you verify the final value?
Discuss your answer with the lesson tutor
Show a worked solution
Illustrative ownership record: “Actor: B in a separate browser profile. Target: A’s existing profile. Attempt: replace A’s workshop profile with B changed this. Result: no permitted update; A reloaded and still read A’s workshop profile.”
The assistant can run the isolated direct-request check and show redacted actor/target labels. Saving B’s own form is not equivalent because the starter normally targets the current account. A denied response or no affected row must be paired with the unchanged A value.
- Identifies the actor as B and the target as A before the assisted direct update.
- Checks A’s final stored value after the attempt, not merely the absence of a visible edit control.
Files for this step
Open or download the files below. When saving a project, keep the folder paths shown in the filenames.
How it works (optional)
Test ownership with two accounts
A successful own-profile save is only half of the access test.
Use account A to save a distinctive name and reload it. Use a separate browser profile or private window for account B so the sessions remain independent.
From B’s session, try a request targeting A’s row. It must not change A’s stored value. Depending on the operation, a denied policy may produce an error or an empty result; verify the actual unchanged row instead of requiring one universal status code.
Worked example
Return to A’s session and reload the profile after B’s attempt. That checks the result directly rather than trusting B’s UI message.
Extra implementation exercise
B’s SELECT for A returns an empty list. Does that prove A’s row was deleted?
Show a worked solution
No. A row-level policy may filter it from B’s view. Check from A’s session before drawing a conclusion about deletion.
- Recognizes row filtering as different from deletion.
- Verifies the row through its owner’s authorized session.
Common mistake
Checking only two successful saves without attempting a forbidden cross-account edit.
Step 5
Add a small biography safely
Keep the same ownership behavior after extending the form.
Ask the assistant to add a biography with a reasonable length limit to the form and provided storage setup. Use only synthetic profile content.
Save/reload it as the owner and repeat the second-account attempt. The new field must not weaken the original owner boundary.
A concrete example
A field that looks correct for A can still expose a problem when B targets it.
Try it yourself
Start with these materials
The starter files and test content are supplied. A live verification still requires your own permitted provider account, inbox or domain as listed under prerequisites. Local inspection is possible without them; record the live step as not tested until you actually perform it.
Provide the biography change and the owner/reload/cross-account observations.
What to produce A redacted profile record showing owner persistence and a rejected cross-account change.
Discuss your answer with the lesson tutor
Show a worked solution
Illustrative biography record: “The assistant used the supplied reference’s 300-character biography limit. A saved I build small practice websites and loaded the same text after reopening. An overlong biography was rejected.”
“B’s separate-session attempt targeted A’s biography; A’s loaded text stayed I build small practice websites.” This is an illustrative result, not proof that your project’s policy was tested; use your own observed owner and cross-account results.
- Records the owner’s biography save/reload and the chosen length limit.
- Repeats B-targets-A testing for the new field and verifies A’s value remains unchanged.
Files for this step
Open or download the files below. When saving a project, keep the folder paths shown in the filenames.
- schema.sqlDownload this file
- public/app.jsDownload this file
- ownership-tests.txtDownload this file
- worksheet.htmlDownload this file
- reference/assignment-walkthrough.txtDownload this file
- reference/START-HERE.txtDownload this file
- reference/public/index.htmlDownload this file
- reference/public/app.jsDownload this file
- reference/add-bio.sqlDownload this file
How it works (optional)
Your assignment: add an owner-editable biography
Extend the schema and explicit write object while keeping the same ownership boundary.
Add a biography with a documented maximum length, a form field and database validation. Update only the fields intended to be editable.
Repeat the owner reload and cross-account attempt. Do not store passwords or secret tokens in profile fields.
Worked example
A new field should not create a new way to change the row’s owner.
The complete reference walkthrough is available in reference/assignment-walkthrough.txt. Compare its steps with your own result; fill the test record from observations in your own project.
Extra implementation exercise
Add a biography and demonstrate that account B cannot change account A’s data.
Show a worked solution
Sign in as account A and save the display name 'A's workshop profile'. Reload and verify that A reads it from the database, not only from an input's current value.
Using account B, attempt a direct update identifying A's row. Check both the response and A's value afterward; an empty filtered result is not evidence that A's row disappeared. The owner policies must protect direct requests too.
For the bio extension, add a text column and a database length constraint, load/save it with the existing owner-bound row and test an overlong value. The reference SQL and browser implementation keep the same owner policies and show the complete extension.
- Biography is validated and persists for its owner.
- Ownership remains enforced on direct requests as well as through the interface.
Common mistake
Testing the new field only through a form that hides other users’ IDs.
Was this lesson useful?
Leave a like, or share it with someone who could use it.
Continue learning
- How to build your first personal website
- How to publish your website from GitHub
- How to connect a custom domain to your website
- How to set up email on your own domain
- How to make your website usable on phones
- How to make website images load faster
- How to get website feedback in your inbox
- How to add email subscriptions to your website
- How to send automated emails from your website
- How to save form submissions in a database
- How to let people sign in to your website
- How to keep a page private
- How to let users upload images
- How to keep API keys out of your frontend
- How to show data from an external API on your website
- How to add an AI chatbot to your website
- How to make a chatbot answer from your own content
- How to add a blog to your website
- How to add search to your website
- How to add another language to your website
- How to help Google find your website
- How to fix your website preview when sharing a link
- How to measure visits and useful actions on your website
- How to let visitors book an appointment
- How to accept a payment on your website
- How to preview website changes before publishing
- How to undo a broken website deployment
- How to back up and restore your website data
- How to find and fix errors on your live website