A healthtech account deletion flow has a difficult boundary: a patient can request deletion while another device still has a session, or while an email login code is waiting to be verified. Its audit log needs to explain what happened to both access paths. The evaluation constraint is that neither an existing session nor a pending login should restore access after the application has accepted the deletion request. This is an acceptance target, not a reported benchmark.
TL;DR: Send the email code, verify it, create the session, and track delivery because the mail path is the login path. For a deletion workflow, add an application admission gate that prevents new sessions, revoke existing sessions, and keep evidence of each transition. A successful email send doesn't establish login, and an accepted deletion request doesn't establish that every access path has closed.
For a Python RAG or agent application, this boundary matters before retrieval starts. A valid-looking session must not become permission to load a deleted patient's context. Keep that decision in deterministic application logic; spending prompt tokens on an authorization decision would make the behavior harder to evaluate and audit.
How should an email code flow verify identity before session creation?
The tempting implementation is a straight line: authenticate the patient, delete the account, show a confirmation. That sequence leaves an unanswered question about concurrent session creation. A second browser may already be completing email verification. Adding a revoke operation at the end still requires a policy for a session admitted after that operation has finished. The problem is the ordering of permission changes, not the wording of the confirmation screen.
Close admission first.
Here, admission means the application's permission to create or accept a session for a particular account. Once deletion begins, every session-creation path must consult the same authoritative account state, including paths entered through an older email code. Code verification establishes the email challenge result; it doesn't override the account's deletion state. This is a proposed application design, not an assertion that an authentication provider implements that entire policy automatically.
There is a friction trade-off. Requiring a fresh email challenge before a destructive action can increase confidence that the requester controls the mailbox, but it also makes successful deletion depend on mail delivery. Codes are easier to support than links when the patient reads email on a different device. Expire them in minutes and make them single-use. Choose the expiration window through evaluation of the intended workflow rather than treating a sample duration as a security standard.
A GDPR deletion request also reaches beyond authentication. Session revocation is an access-control step; it doesn't establish that every clinical record, backup, or downstream copy has been erased. Define those obligations separately with the people responsible for the data. The engineering claim in this experiment is narrower: account closure should stop further authenticated use through the application's covered paths.
The audit trail should explain a decision
Build the record around transitions: a challenge was requested, sending succeeded or failed, verification succeeded or failed, session creation was admitted or denied, deletion began, and revocation completed or needs attention. Those are application event concepts, not promised vendor response fields. Correlate them with an opaque workflow identifier so an operator can follow one request without copying the email code, bearer credential, prompt, or patient document into a log.
Delivery is part of availability.
A send failure prevents a patient from completing an email-based flow even if the rest of the application responds normally. Track send failures separately from verification failures and from abandonment. A send acknowledgment alone doesn't prove inbox delivery or patient receipt. If the mail provider supplies delivery evidence, retain the distinction between that evidence and the patient's later verification event; otherwise, state exactly which stage is observable.
For deletion, the event sequence should make a denied session-creation attempt understandable. Was the challenge invalid, was it already consumed, or did account closure prohibit admission? Keep user-facing responses appropriately restrained while preserving enough internal evidence to diagnose the decision. OWASP's authentication guidance is a useful starting point for balancing useful feedback against account disclosure.
The RAG boundary deserves its own check. An assistant request admitted before deletion might already have work in progress. Decide where the application will recheck authorization before reading patient context or returning protected results, and document the limits of that decision. Revoking a session should never be described as undoing data already returned to a client.
A small notebook test for the closure rule
Start notebook-to-prod work with a session inventory for a synthetic account. The following Python example reads the account's sessions through the REST interface. It preserves the response without assuming undocumented session fields. It doesn't implement email verification or deletion; use it as an inspection step when constructing the closure test.
Set INFRAI_BASE_URL to the service's trusted HTTPS API base ending in /v1, INFRAI_API_KEY to your server-side credential, and TEST_USER_ID to a synthetic account identifier. Use Python 3.11 or later. Keep this outside the browser and run it against test data: the response can contain session information. There is no model call and no prompt cost. That's a useful place to start!
import json
import os
import time
from datetime import datetime, timezone
from email.utils import parsedate_to_datetime
from urllib.error import HTTPError
from urllib.parse import quote
from urllib.request import Request, urlopen
base = os.environ["INFRAI_BASE_URL"].rstrip("/")
if not base.startswith("https://") or not base.endswith("/v1"):
raise ValueError("Use the trusted HTTPS API base ending in /v1")
user_id = quote(os.environ["TEST_USER_ID"], safe="")
request = Request(
f"{base}/auth/session/list_for_user/{user_id}",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
method="GET",
)
for attempt in range(4):
try:
with urlopen(request, timeout=20) as response:
if response.status != 200:
raise RuntimeError(f"Unexpected status: {response.status}")
print(json.dumps(json.load(response), indent=2))
break
except HTTPError as error:
body = error.read().decode("utf-8", errors="replace")
if error.code != 429 or attempt == 3:
raise RuntimeError(f"HTTP {error.code}: {body}") from error
delay = float(2 ** attempt)
retry_after = error.headers.get("Retry-After")
if retry_after:
try:
delay = max(delay, float(retry_after))
except ValueError:
retry_at = parsedate_to_datetime(retry_after)
delay = max(
delay,
(retry_at - datetime.now(timezone.utc)).total_seconds(),
)
time.sleep(delay)
The 4 attempts are a bounded retry policy for a read-only request; they aren't a service guarantee. This inspection doesn't prove revocation. Test actual protected access from 2 sessions, representing a browser and a second device. Coordinating account state and session admission is still necessary: two workers reading stale state could violate the closure rule. Add an integration test that pauses verification, starts deletion in another request, then resumes session creation. The expected result is denial, with an audit event that identifies account closure as the internal reason.
That's the useful eval-driven step: turn an access invariant into a reproducible interleaving, then test the deployed boundary. A happy-path notebook can't supply that evidence.
Choose the authentication service around the boundary
An email login tutorial, including one written for Node.js, usually concentrates on sending and verifying a challenge before creating a session. Those are necessary steps. For this healthtech workflow, the selection question is also how much application code is needed to enforce closure across all session-entry paths and to explain that decision afterward.
| Option | Relevant login approach | Fit and boundary to evaluate |
|---|---|---|
| Auth0 | Passwordless email supports codes or links. | Evaluate it when managed identity is the desired boundary. Test how your application's deletion state interacts with session and token acceptance. |
| Firebase Authentication | Email-link authentication is a documented sign-in path. | Evaluate it for an application using Firebase's identity model. Test cross-device completion and the application's account-closure checks. |
| Supabase Auth | Passwordless email supports magic links and one-time passwords. | Evaluate it when that authentication model fits the application. Test the chosen email flow together with session admission and data-access policy. |
These are different integration starting points, not a ranking of deletion correctness. None of the email-login documentation alone proves that a particular healthtech application blocks every post-deletion access path. Compare them using the same synthetic account, the same second device, and the same paused verification attempt. Don't substitute the presence of a dashboard for evidence of the behavior you need.
Infrai offers a plain REST API with a single API key and unified billing. An HTTP-capable Python or Node.js application can call it without installing a dedicated SDK. That shared credential covers 295 routes across 20 modules, reducing credential and billing reconciliation work when the workflow spans authentication and observability. Evaluate its email verification and session operations against the same closure invariant; the application still needs its own admission policy and audit evidence.
A REST interface reduces client-library maintenance, but it doesn't remove the work of defining authorization. Conversely, a provider-specific SDK may fit an existing application well enough that replacing it adds friction without improving the deletion boundary. This choice should follow the system's access model.
Measure closure before copying the choice
Use synthetic accounts and record separate results for successful verification, invalid verification, reuse of a consumed code, an expired code, sending failure, and verification resumed after deletion begins. Add 2 active sessions to the deletion case, then attempt protected access from each. Count admission after closure as a failed security test, even if the interface has already displayed a reassuring confirmation. These are proposed checks; no measured pass rate is claimed here.
Measure friction too.
Track completion and abandonment by stage, plus the time between requesting a code and successful verification. Compare same-device and cross-device completion. Keep transport evidence separate from identity evidence, and inspect whether an operator can reconstruct the closure decision without seeing the patient's message content. If a fresh challenge blocks legitimate deletion requests because mail doesn't arrive, that is a workflow availability problem to address explicitly.
Before adopting the design, require evidence for three properties: session admission stops at the chosen boundary, existing sessions lose protected access, and the audit record explains both outcomes. Then evaluate the broader deletion obligations separately. For a healthtech AI builder, that gives the notebook a concrete production exit criterion while keeping sensitive context out of prompts and out of the test fixture.
References
The sources below document authentication guidance and the compared email-login approaches. The closure rule and proposed acceptance tests above are application design recommendations.
Sources
- OWASP Authentication Cheat Sheet: https://cheatsheetseries.owasp.org/cheatsheets/Authentication_Cheat_Sheet.html
- Auth0 passwordless email documentation: https://auth0.com/docs/authenticate/passwordless/authentication-methods/email-otp
- Firebase email-link authentication: https://firebase.google.com/docs/auth/web/email-link-auth
- Supabase passwordless email authentication: https://supabase.com/docs/guides/auth/auth-email-passwordless
Top comments (0)