
Mini lesson 11 of 30 · Accounts and access
Understand the sign-in journey
Who is this for?
People who want account sign-in on a small website. A managed service and supplied app handle the implementation; you can work with a coding assistant without writing authentication code.
Receiving a code and being signed in are different moments.
Purpose of this lesson
- Request and use a real sign-in code.
- Verify the signed-in and signed-out states.
- Keep wrong codes and missing messages as honest failures.
Explanation, worked example and practice
Before you start
Your own Supabase practice project and a permitted test inbox or configured sender. Use the supplied page over local HTTP or your own HTTPS host. A coding assistant can guide setup and configure email codes.
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.
- How to publish your website from GitHub
Connect a practice repository to hosting.
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. Email delivery/account setup can add waiting. Provider restrictions and session lifetimes must be checked in the account used for the exercise.
Understand the idea
Use the ready page with your assistant. The person enters an address, receives a code and submits that code before the service establishes sign-in.
A page saying “Check your inbox” means a request was made, not that the visitor is authenticated.
A concrete example
An email address alone is not evidence that its owner completed sign-in.
Use the supplied Supabase sign-in app. Guide me through provider email-code setup with my own permitted test inbox, put only the publishable project values in the public config and run the page over HTTP. Help test requesting a code, entering it, reloading and signing out. An invalid code or missing email must not become a pretend signed-in state.Files for this step
Open or download the files below. When saving a project, keep the folder paths shown in the filenames.
Try it yourself
Which visible states will you check between address entry and actual sign-in?
Show a worked solution
Illustrative answer: “After Send sign-in code, I expect a request-accepted message. Next I must find the email. Only after Verify code succeeds should the page identify my signed-in account.”
“Check your inbox” is a request-stage message. It does not establish that email arrived or a session exists.
What a sound answer includes
- Separates requesting a message, receiving its code and verifying sign-in.
- Identifies the verified account display, rather than address entry, as session evidence.
How it works (optional)
Add a real sign-in session
Authentication verifies an identity; displaying an email address is not enough.
We will use Supabase Auth to send a one-time email code and establish a session after verification. The browser SDK manages session storage and refresh; we do not implement a password database.
A request accepted by the email endpoint does not mean a user is signed in. The session appears only after a valid verification step. Authorization for private data is a later, separate check.
Worked example
Typing another person’s email into a field must not grant that person’s access. The code sent to the inbox is the verification step.
Supabase: email sign-in codes · Supabase: API key types
Extra implementation exercise
The page accepted an email address and says “Check your inbox”. Is the visitor authenticated yet?
Show a worked solution
No. The sign-in request has started. Verify the code and inspect the resulting session before showing a signed-in state.
- Keeps requested and verified states separate.
- Requires successful verification and a session.

Step 1 · How to let people sign in to your website
Prepare the provider and page
Choose the code flow the supplied form expects.
Explanation, worked example and practice
Understand the idea
Before testing, have your assistant check four required setup items: the intended Supabase practice project, an inbox permitted by its sender settings, an email template containing a sign-in code and the supplied page running over HTTP. The template must match this code-entry interface, rather than contain only a magic link.
Only the project URL and publishable key belong in public/config.js. Keep secret/service-role keys out of browser files. These provider and running-app checks are required; reading or rewriting the authentication implementation is optional.
A concrete example
A working email link can still be the wrong journey for a page that asks you to type a code.
Files for this step
Open or download the files below. When saving a project, keep the folder paths shown in the filenames.
Try it yourself
Did the provider setup and received message match the code-entry form?
Show a worked solution
Illustrative setup record: “The practice project is selected; the email template includes the sign-in code; public/config.js contains only the project URL and publishable key; the page opens over local HTTP.”
A blocked version could read: “The page opens, but the email contains only a link. Code-entry testing is blocked until the assistant helps correct the provider template.” Neither record includes a key or reusable code.
What a sound answer includes
- Names the practice project, code-containing email template and HTTP preview readiness.
- Distinguishes the public project settings from secret keys and reports any blocked setup step.
How it works (optional)
Configure the provider and browser client
The email template and key type must match the supplied code flow.
In a separate Supabase project enable Email authentication. Check whether its sender can deliver to your test inbox; configure supported SMTP when required. In the Magic Link email template, include {{ .Token }} so the message provides the code expected by this page.
Put the project URL and publishable key in config.js. That key identifies the application; it is not a user session or an administrative secret. Never put a secret/service-role key in this browser file. Serve public/ through HTTP/HTTPS so module imports work.
The page expects a typed email code (OTP). In the provider's email template, {{ .Token }} renders that code; a template containing only a confirmation-link variable will not give this UI the code it asks for. Use the current passwordless-email guide to locate the template rather than guessing a setting name.
The official Supabase “With OTP” guide explicitly explains that email codes share the Magic Link implementation: alter the Magic Link email template to include {{ .Token }}. The name does not mean this page should receive a link-only message. Follow that guide if dashboard labels differ; do not invent an unrelated template setting.
Worked example
The SDK method is called signInWithOtp, but the email can contain a link or a code depending on the template. Our interface expects the code version.
Extra implementation exercise
Your page asks for a code, but the email contains only a magic link. What should you check?
Show a worked solution
Check the configured template for the Token value and repeat the request after aligning it with the code interface. Follow the current provider documentation for your project.
- Checks the email template and intended flow.
- Does not invent a code or claim the message was verified.

Step 2 · How to let people sign in to your website
Complete one real sign-in
Use the email message rather than an invented code.
Explanation, worked example and practice
Understand the idea
Begin signed out in a fresh private window. Request a code for your controlled inbox and deliberately enter an incorrect code first. Verify that the attempt stays rejected and the page still reports no signed-in account. Then request a fresh code, enter the real value from the email and inspect the identified account.
A rejected code must not establish sign-in. If you start while already signed in, a wrong code may leave that existing session intact; that is a different situation and does not test prevention of a new session. If no email arrives, record that exact blocked stage.
A concrete example
A friendly success label after a rejected code would misrepresent the account state.
Files for this step
Open or download the files below. When saving a project, keep the folder paths shown in the filenames.
Try it yourself
In a fresh signed-out window, what happened with an incorrect code and then a fresh real email code?
Show a worked solution
Illustrative test record: “In a fresh private window, an incorrect code showed Code was not accepted and the page still reported No signed-in account. I then requested a fresh email code, verified it and saw my controlled test account identified.”
If the email never arrives, a valid record is “Request accepted; no code found in the permitted inbox or spam; successful verification not run.” An incorrect-code test performed while already signed in does not establish that a new session was prevented.
What a sound answer includes
- Tests an incorrect code in a signed-out session and records that sign-in was not established.
- Uses a fresh real code afterward and checks the resulting account identity.
How it works (optional)
Request and verify a code
Each button corresponds to a different state transition.
Read public/app.js. The first action calls signInWithOtp with the entered email; the second calls verifyOtp with that email and the received token. A successful result includes a session.
Use your own inbox and copy the current code exactly. A wrong, expired or already-used code should leave the user unsigned-in. Do not log codes or access tokens in a shared report.
Worked example
The UI uses textContent for status and account text. It does not interpret an email address as HTML.
const {data,error}=await client.auth.verifyOtp({email,token,type:'email'});
if(error || !data.session) { /* keep the unverified state */ }Extra implementation exercise
An incorrect code returns an error, but your app shows “Signed in” anyway. Which condition must change?
Show a worked solution
Show the signed-in state only when verification succeeds and a session exists. Do not use the button click itself as proof.
- Checks the returned error and session.
- Keeps failure separate from successful authentication.

Step 3 · How to let people sign in to your website
Check reload and sign-out
Make sure the visible state follows the real session.
Explanation, worked example and practice
Understand the idea
Reload after successful sign-in and inspect the displayed account. Then use Sign out and inspect the identity again. For an independent-session check, use a separate browser profile, or close every private window before opening a new one: additional private windows can share their existing private session.
The supplied starter shows account state; it does not contain a protected document to test. If you add private content later, a server must verify access before returning it. A hidden button alone cannot provide that protection.
A concrete example
A signed-out page should not keep acting as the previous account merely because a label remains.
Files for this step
Open or download the files below. When saving a project, keep the folder paths shown in the filenames.
Try it yourself
What account state appeared after reload, after sign-out and in a fresh private window?
Show a worked solution
Illustrative session record: “Reload still identified test account A. Sign out changed the identity to No signed-in account. A separate browser profile also showed no account.”
This starter demonstrates account state, not a private document. If the session remains after sign-out, record that failure; testing access to private content belongs to the private-page lesson.
What a sound answer includes
- Records the account state after reload and after the sign-out action.
- Checks a separate browser profile or newly started private session rather than assuming another window is independent.
How it works (optional)
Check persistence and sign-out
Test more than the first successful code.
After sign-in refresh the page and inspect the account state. Then sign out and refresh again. Use a private window to verify that another browser does not inherit the session automatically.
Signing out clears this client’s session; it does not mean every copied access token everywhere instantly stops working. Access-token lifetime and revocation behavior matter when building protected server endpoints.
Worked example
A signed-out UI should not keep a private account display or automatically attach an old token to a new request. Private endpoints still need server verification.
Extra implementation exercise
Would hiding the Sign in button be enough to protect a private document?
Show a worked solution
No. The server must verify the caller before returning protected content. The next private-page lesson implements that boundary.
- Separates UI state from server authorization.
- Requires access checks on the document request.

Step 4 · How to let people sign in to your website
Record the full account journey
Finish with reproducible observations, not just a screenshot of success.
Explanation, worked example and practice
Understand the idea
Repeat the address–email–code route after any repair. Save a redacted record of sign-in, reload, sign-out and one meaningful failed attempt.
If sender restrictions or account limits block the test, report that stage precisely. Do not substitute a local mock for a real delivered code.
A concrete example
A useful report distinguishes no email, wrong code and successful verification.
Files for this step
Open or download the files below. When saving a project, keep the folder paths shown in the filenames.
Try it yourself
Provide your account-journey checks and anything still blocked.
What to produce: A short account-journey record covering real code arrival, sign-in, reload, sign-out and a failed attempt.
Show a worked solution
Illustrative completed record: “Controlled inbox received a code; wrong code while signed out was rejected; a fresh valid code identified A; reload kept A; sign-out cleared the identity; an independent browser profile had no session.”
Illustrative incomplete record: “The code request failed under the provider’s sender restrictions. Arrival and verification were not run; next action: check the permitted recipient and sender setup.” A blocked account flow must remain incomplete, rather than be replaced with a local pretend login.
What a sound answer includes
- Provides the request, email, wrong-code, valid-code, reload and sign-out observations in order.
- Names any missing email/provider step and keeps codes or session tokens out of the record.
How it works (optional)
Your assignment: verify the complete account journey
Document requested, failed, signed-in and signed-out states.
Test a wrong code before completing a valid sign-in. Check refresh behavior, sign-out and a private window. Use only inboxes you control.
Improve one unclear message without changing its truth: a requested code is pending, and an error is not a successful session.
Worked example
The report should identify observed states without exposing the received code, bearer token or private profile information.
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
Complete the account journey and explain what each observed state proves.
Show a worked solution
Configure the project URL and publishable key, then a template containing {{ .Token }} so the message contains the code this page expects. Request a code for your own inbox. A requested email is not a verified session.
Enter a wrong code and confirm that no user session is created. Use a fresh valid code, verify the identity shown, reload and observe the session. Sign out and verify the tab no longer reports a session.
Repeat from a private window: it must not inherit the first window's sign-in state. Hiding a button is unrelated to protecting a document; a server must verify authorization before returning private content.
- Wrong-code and signed-out cases remain unauthenticated.
- A valid session persists as configured, and client sign-out is verified honestly.
Was this lesson useful?
Leave a like, or share it with someone who could use it.