
Mini lesson · English
How to keep a page private
Use a ready sign-in project to keep a practice note private and test both allowed and denied access.
Who is this for?
People who want a page or note available only after sign-in. A coding assistant can connect the supplied protection; server programming is not the learning requirement.
Before you start
The supplied sign-in setup or equivalent Supabase access, a separate function-hosting project and a coding assistant. Use a fictional PRIVATE_NOTE kept only in the server environment, never real private content.
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. This example allows all valid users of the practice project. Per-user records and roles require additional authorization rules.
What you will learn
- Keep private content out of the public page.
- Test the same route signed out and signed in.
- Check an access failure without revealing the note.
Step 1
Choose what needs protection
Private means unavailable to an unauthorized visitor, not merely hidden.
Use the supplied fictional note and ready project. Ask the assistant to keep the note on the server rather than inside the downloaded public page.
A visitor can inspect public files even when an element is hidden. Do not put real private information into the exercise.
A concrete example
A paragraph concealed by page styling is still part of the public file.
Use this complete private-note workshop and my managed sign-in practice project. Keep PRIVATE_NOTE only in the private server environment and preserve the supplied access checks. Help run the app, then compare signed-out direct access with verified sign-in. Do not treat hiding a paragraph as protection or expose another person’s data.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)
Protect the response, not just the button
Private content must not be shipped to an unauthorized browser in the first place.
CSS hiding and disabled buttons change the interface, not the response. Anyone can inspect public files and issue a direct request to an endpoint.
Our server reads a note from its environment and returns it only after verifying a user token. The fictional note is for the lab; real private data belongs in a protected data source, not a public repository.
Worked example
A public JavaScript file containing a “hidden” note is still a public copy. The example instead keeps the value out of public/.
Extra implementation exercise
The page hides a paragraph until sign-in, but the paragraph is in the HTML source. Is it private?
Show a worked solution
No. Gate the server response before sending the content. Hiding a received value cannot make it secret.
- Recognizes that the browser already received it.
- Moves access control before the protected response.
Common mistake
Equating a hidden DOM element with authorization.
Step 2
Connect the ready protection
Let the assistant configure the existing server checks.
Follow run-locally.txt with your assistant. Before testing, confirm the intended authentication project, its public browser values, the private server authentication settings and the fictional PRIVATE_NOTE. Start the complete project and open the actual proxy URL; a plain file preview cannot run its protection.
These account/server readiness checks are required. Reading the function implementation is optional. The service must verify the account session before returning the note; a caller typing another account ID into a request is not proof of identity.
A concrete example
A user-supplied identity is not the same as a confirmed account session.
Supabase: verified user retrieval · Node.js: supported release status
Try it yourself
Which setup step is complete, and what actual app URL can you test?
Discuss your answer with the lesson tutor
Show a worked solution
Illustrative readiness record: “The supplied app is running at the local proxy URL printed by the server. The practice authentication project and fictional server note are configured. The note is absent from the public page files.”
A blocked record could read: “The page opens, but the server reports Auth not configured; the assistant must check the private provider environment before I test access.” The page opening by itself does not establish server protection.
- Identifies the running application address and completed server/provider configuration.
- Reports a concrete setup blocker without publishing the private note or credentials.
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)
Send a session token to the server
The client supplies a bearer token; the server verifies it independently.
Configure the sign-in files and server environment in START-HERE.txt. The client obtains its current session and sends its access token in the Authorization header when requesting the private endpoint.
The server calls the provider’s user endpoint with that token and the project’s publishable application key. It rejects missing or invalid tokens, and distinguishes a provider outage from accepted identity. Decoding a token without verifying it is not sufficient.
Follow the request in order: browser sends its user access token → the server asks the identity provider whether that token represents a user → only a verified result permits returning the note. The project publishable key identifies the application; it does not by itself identify or authorize the person.
For the complete local sequence, open run-locally.txt: prepare the private root environment, link only the practice project and start the Netlify function proxy. server-env.example.txt lists variable names without real secrets. Opening only the HTML cannot run the server.
Worked example
A caller-supplied userId field is not proof that the caller owns that ID. Use the identity returned by verification.
const r=await fetch('/.netlify/functions/mini-private-note', {
headers:{Authorization:'Bearer '+session.access_token}
});Supabase: verified user retrieval · Node.js: supported release status
Extra implementation exercise
Could the server authorize a request by trusting userId from the browser JSON?
Show a worked solution
No. The browser can change that field. Verify the credential and use the verified identity.
- Treats client identity claims as untrusted.
- Uses a verified token and resulting identity.
Common mistake
Checking only that a token string exists.
Step 3
Test the allowed audience
Decide who should be able to read this particular item.
Sign in with your controlled test account and request the fictional note. For this lab the rule is any verified signed-in user; ask the assistant to preserve that stated scope.
If you later store one person’s account data, that broader rule is not enough. State the audience rather than assuming all private data has identical permissions.
A concrete example
A shared member note and an individual account record need different access decisions.
Try it yourself
Who is allowed to read your practice note, and did the signed-in request match that rule?
Discuss your answer with the lesson tutor
Show a worked solution
Illustrative access record: “Test account A is verified and received the fictional member note. The lab rule is any verified signed-in user, so another verified test member is also within the allowed audience.”
This is a shared-member rule. It would be insufficient for A’s personal profile, which must be restricted to A; that different boundary needs an ownership check.
- States that the lab permits any verified signed-in user, not only one note owner.
- Records the allowed account’s result without extending this rule to personal account data.
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)
Return only the intended protected data
A valid identity does not automatically grant access to every user’s records.
This small example grants every valid user in the practice project access to one shared note. That is an explicit authorization rule, not a universal definition of private content.
The response uses private, no-store caching so a shared cache should not retain the note. A later profile lesson uses ownership rules for per-user records. Do not expand this handler into a global database dump.
Worked example
The server’s viewerId is derived from verification. The note comes from its environment, not from data supplied in the request.
Extra implementation exercise
If the note were replaced with another user’s account details, would “any signed-in user” remain a suitable rule?
Show a worked solution
No. Add a rule matching the authenticated identity to the requested record or role. A login alone does not grant access to another account.
- Distinguishes authentication from record-level authorization.
- Requires ownership or an appropriate role for per-user data.
Common mistake
Using a shared private-page rule for sensitive per-user records.
Step 4
Try the same route signed out
A direct request matters as much as the normal button.
Use a genuinely signed-out browser profile, or sign out and verify the account state, then ask your assistant to request the same note directly. An extra private window may share an existing private session. Repeat the note request with verified sign-in.
The signed-out result must not contain the note; the allowed session should receive it. A request failure should stay an error without leaking content.
A concrete example
Removing a menu link does not protect the address it used to open.
Try it yourself
What did the direct signed-out and signed-in attempts each return?
Discuss your answer with the lesson tutor
Show a worked solution
Illustrative direct-request record: “Signed out: the note route returned Sign in required and no note. Signed in as A: the same route returned the fictional note. The assistant helped inspect those response bodies without sharing tokens.”
If the signed-out response includes the note, access protection failed even if the page hides it. If the authentication service is unavailable, record that failure separately from an ordinary denied request.
- Compares the same note route with a signed-out request and an allowed signed-in request.
- Checks that denied or failed responses contain no private note text.
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)
Try the endpoint without the interface
A real access test targets the data request directly.
Request the function URL in a fresh window without an Authorization header; it should not return the note. Try a malformed bearer token, then use the signed-in UI to make an authorized request.
Sign out and check that the app clears the displayed note and does not send a session token again. A previously issued token may remain valid until its configured expiry; immediate global revocation is a separate requirement.
Worked example
A denied direct request demonstrates more than a screenshot of a login button. Keep the response status and whether protected text was present in your record.
Extra implementation exercise
A direct request returns 401 with no note, while a verified session receives the note. What boundary did you test?
Show a worked solution
You tested that this endpoint verifies identity before returning the shared note. Other endpoints and ownership rules need their own tests.
- Identifies the server response boundary.
- Does not claim universal token revocation or per-user authorization beyond the example.
Common mistake
Testing only the happy path through the browser buttons.
Step 5
Protect one more test value
Repeat the same checks after a small change.
Ask the assistant to add a second fictional server-only value using the same intended audience rule. Do not move either value into public files for convenience.
Repeat allowed, denied and failure observations. Keep the handoff redacted and label any test not run.
A concrete example
Adding another field should not accidentally make the original private note public.
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 new value’s protection and the observed access results.
What to produce The working practice route and observed signed-out/signed-in/error access checks.
Discuss your answer with the lesson tutor
Show a worked solution
Illustrative extension record: “I added a fictional meeting location beside the original member note. A verified test member received both; the signed-out direct request received neither. With authentication deliberately unavailable in the disposable setup, the response stayed an error and contained neither value.”
A handoff can identify the two fields and these outcomes without reproducing their contents. If a failure case was not run, list it as not run rather than treating a successful signed-in check as proof of every boundary.
- Keeps both fictional values server-only under the stated shared-member rule.
- Retests allowed, denied and service-failure responses for the added value.
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)
Your assignment: add a second protected value
Keep the new value out of public files and apply the same server checks.
Add another practice value in the server environment, return it only after verification and display it safely as text. Keep the response non-cacheable.
Repeat missing-token, invalid-token and valid-session tests. Search the public source to confirm that neither private value was embedded there.
Worked example
The assignment extends the protected response, not the amount of data shipped before sign-in.
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
Protect a second value and provide both positive and negative access evidence.
Show a worked solution
Call the private-note endpoint directly with no Authorization header: expect 401 and no note. A made-up bearer token must also fail. The browser's userId or a hidden button does not satisfy the server's identity check.
With your actual verified session token in your own practice project, expect the configured server note and Cache-Control: private, no-store. Keep the note out of public HTML/JavaScript. Do not paste a real bearer token into a shared test report.
After sign-out, the UI should clear private content and stop making authenticated requests. An already copied access token may remain usable until expiry: sign-out UI behaviour is not an instant-revocation guarantee. This shared-note lab authorizes signed-in users; per-user ownership is the separate profile exercise.
- Both values remain server-side until authorization succeeds.
- Unauthorized direct requests contain neither value; valid access and no-store behavior are checked.
Common mistake
Adding the second value as a browser constant for convenience.
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 let users edit their profile information
- 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