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.

Start the interactive lessonRead the lesson below

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.

Workshop files

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

Start hereWorkshop files

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.

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.

Supabase: row-level security

Files for this step

Start hereWorkshop files

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);

Supabase: row-level security

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.

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.

Files for this step

Start hereWorkshop files

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.

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.

Files for this step

Start hereWorkshop files

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.

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.

Files for this step

Start hereWorkshop files

Open or download the files below. When saving a project, keep the folder paths shown in the filenames.

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.

Was this lesson useful?

Leave a like, or share it with someone who could use it.

Continue learning

Explore the other lessons