LessonsHow to let users edit their profile information

Mini lesson 13 of 30 · Accounts and access

Define the owner’s result

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.

Changing a profile name should affect only that account.

Purpose of this lesson

  • 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.
Explanation, worked example and practice

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.

Check your starting skills

These are useful skills, not locked course requirements. If you can already do them, start this lesson; otherwise open the linked preparation. The supplied starter files mean you do not need an existing personal website.

  1. How to let people sign in to your website

    Request and use a real sign-in code.

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.

Understand the idea

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.

Try it yourself

Which account owns the first name you will save, and what should another account be unable to change?

Show a worked solution

Illustrative plan: “A will save the display name A’s workshop profile. This changes profile text, not A’s sign-in email. B must not be able to update A’s stored row by targeting A’s identity.”

Using the normal form as B to edit B’s own name is allowed and is not the cross-account test. The forbidden target must explicitly be A.

What a sound answer includes

  • Identifies A as the owner of a display name, separate from the sign-in email.
  • Defines the prohibited action as B changing A’s stored profile.
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 1 · How to let users edit their profile information

Apply the supplied profile setup

Use the isolated project and keep its ownership rules.

Explanation, worked example and practice

Understand the idea

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.

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.

Try it yourself

Did the practice setup complete, and which sign-in route can you actually open?

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.

What a sound answer includes

  • 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.
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 2 · How to let users edit their profile information

Save and reload your own name

Look for a persisted value, not a temporary label.

Explanation, worked example and practice

Understand the idea

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.

Try it yourself

What name did A save, and what appeared after reload?

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.

What a sound answer includes

  • 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.
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 3 · How to let users edit their profile information

Try a second account

Use separate sessions so you know who is acting.

Explanation, worked example and practice

Understand the idea

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.

Try it yourself

Could B change A’s stored name, and how did you verify the final value?

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.

What a sound answer includes

  • 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.
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 4 · How to let users edit their profile information

Add a small biography safely

Keep the same ownership behavior after extending the form.

Explanation, worked example and practice

Understand the idea

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.

Try it yourself

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.

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.

What a sound answer includes

  • 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.
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.