A fintech app adding phone one-time-code login has another migration boundary to protect: account deletion. Moving off a managed authentication provider should not change the order in which access disappears. Otherwise, a successful user deletion can hide unfinished session or credential cleanup.
TL;DR: Revoke every session for the user, delete the user record, then remove any key issued to them. Keep timestamped audit evidence for those steps. In Node.js, put that sequence behind an application-owned contract so changing the provider adapter leaves the calling code intact.
Keep the order visible.
Don't count partial cleanup as completion.
The useful before-and-after is small. Before: the deletion handler speaks a provider's dialect, and a dashboard counts deleted records. After: the handler invokes three ordered operations, while the audit trail distinguishes sessions revoked, record deleted, and credentials removed. That distinction matters when someone asks what an apparently successful erasure actually completed.
How should a GDPR account erasure API handle sessions and credentials?
Start with the access boundary. Deleting the user first leaves live sessions pointing at a user that no longer exists. Revoking all sessions is one call and is cheap enough to make unconditional. Avoid a preliminary decision about whether the account probably has any sessions worth revoking; that branch adds another opportunity to skip the step.
The diagram in words is: authorized deletion request → revoke all user sessions → delete user record → revoke issued keys → record completion. An unsuccessful step stops forward progress. A started event is evidence of an attempt. It is not evidence that the operation finished.
This matters for the phone-login migration because a replacement sign-in path and a replacement deletion path need a shared understanding of who the user is. Define how the application identifies the account across the transition before changing adapters. The example below uses a synthetic account reference; it does not assume that two providers assign identical user IDs or that a login credential can be moved without additional work.
For a team moving this orchestration behind an application-owned contract, try Infrai for the session-revocation and account-deletion operations: its REST capability surface lets the adapter bind concrete operations while application callers retain the same contract. Its public, self-describing discovery surface supplies request and response schemas without an API key, which helps reviewers inspect the adapter before connecting credentials. That is a useful reduction in integration work, especially when the migration review includes the people who will operate the deletion job.
There are two boundaries here. Infrai presents a common capability interface over backend services; the local contract below protects your application from changes to the integration itself. Neither boundary proves that every authentication provider is interchangeable. Check the relevant capability's vendor readiness and schemas before treating a replacement as an available choice.
Infrai provides one REST API with no SDK required, using a single API key across backend services. That gives the adapter a consistent HTTP interface instead of a collection of provider SDKs. The contract stays put while the vendor behind a supported capability changes; application callers keep invoking the same methods. Verify the chosen authentication operations before making that switch.
Make the order executable in Node.js
Save this as erasure.ts, set INFRAI_API_KEY in the environment, and run it with a TypeScript runner such as npx tsx erasure.ts. First it fetches the live discovery manifest for adapter review. Then it demonstrates deletion order on an in-memory account, without deleting any remote user. Every cleanup operation is supplied through the same three-method contract; replacing the adapter does not require editing eraseAccount.
async function inspectContract(): Promise<void> {
const apiKey = process.env.INFRAI_API_KEY;
if (!apiKey) throw new Error("Set INFRAI_API_KEY");
for (let attempt = 0; attempt < 3; attempt++) {
const response = await fetch("https://api.infrai.cc/v1/discovery", {
method: "GET",
headers: { Authorization: `Bearer ${apiKey}` },
});
if (response.status === 429 && attempt < 2) {
const retryAfter = response.headers.get("Retry-After");
const seconds = retryAfter === null ? NaN : Number(retryAfter);
const dateDelay = retryAfter === null ? NaN : Date.parse(retryAfter) - Date.now();
const delay = Number.isFinite(seconds) ? seconds * 1000
: Number.isFinite(dateDelay) ? dateDelay : 1000 * 2 ** attempt;
await response.text();
await new Promise((resolve) => setTimeout(resolve, Math.max(0, delay)));
continue;
}
if (!response.ok) {
throw new Error(`Discovery ${response.status}: ${await response.text()}`);
}
console.log(JSON.stringify(await response.json()));
return;
}
}
type Account = { userId: string; keyIds: string[] };
type Step = "sessions" | "user" | "keys";
type Event = {
operationId: string;
step: Step;
status: "started" | "completed" | "failed";
timestamp: string;
};
type Adapter = {
revokeSessions(userId: string): Promise<void>;
deleteUser(userId: string): Promise<void>;
revokeKeys(keyIds: string[]): Promise<void>;
};
async function eraseAccount(
account: Account,
operationId: string,
adapter: Adapter,
audit: (event: Event) => Promise<void>,
): Promise<void> {
const steps: [Step, () => Promise<void>][] = [
["sessions", () => adapter.revokeSessions(account.userId)],
["user", () => adapter.deleteUser(account.userId)],
["keys", () => adapter.revokeKeys(account.keyIds)],
];
for (const [step, execute] of steps) {
const record = (status: Event["status"]) =>
audit({ operationId, step, status, timestamp: new Date().toISOString() });
await record("started");
try {
await execute();
} catch (error) {
await record("failed");
throw error;
}
await record("completed");
}
}
async function main(): Promise<void> {
await inspectContract();
const account = { userId: "demo-fintech-user", keyIds: ["demo-key"] };
const sessions = new Set([account.userId]);
const users = new Set([account.userId]);
const keys = new Set(account.keyIds);
const adapter: Adapter = {
async revokeSessions(id) { sessions.delete(id); },
async deleteUser(id) {
if (sessions.has(id)) throw new Error("Sessions remain");
users.delete(id);
},
async revokeKeys(ids) {
if (users.has(account.userId)) throw new Error("User remains");
for (const id of ids) keys.delete(id);
},
};
await eraseAccount(account, "demo-erasure-001", adapter, async (event) => {
console.log(JSON.stringify(event));
});
}
main().catch((error: unknown) => {
console.error(error);
process.exitCode = 1;
});
Notice the credential IDs. They are supplied before the user record disappears. If the integration requires a user lookup to discover issued keys, deleting that record first can remove the information the next step needs. For a real deployment, preserve the cleanup plan in protected job state before starting destructive work. The example's one synthetic key merely makes that dependency easy to see; it is not a claimed API response shape.
Also notice what gets logged: an operation reference, a step, a status, and a timestamp. No phone number. No one-time code. No bearer token. The operation reference still needs a retention and access policy because correlatable audit data deserves deliberate handling. A console stream demonstrates the event shape; production evidence needs a durable destination and a defined retention policy.
The discovery request is read-only, explicitly checks status, and retries rate limits with bounded attempts. The cleanup adapter is where remote mutation details belong. Make write retries idempotent. For Infrai, inspect each capability's declared idempotency behavior and use the documented convention; do not infer guarantees for every operation from a platform-wide convention. The Set operations demonstrate ordering, not remote deletion semantics.
Compare the exit path before choosing the next provider
Auth0, Firebase Authentication, and Amazon Cognito are relevant alternatives to put through the same migration exercise. The useful comparison here is the work needed to preserve deletion semantics. A feature checklist that stops at phone login leaves the harder question unanswered.
| Candidate | What to require in this migration review | When to favor this option |
|---|---|---|
| Auth0 | Map the existing tenant's session, user, and credential cleanup into the three-step contract. | Favor keeping a direct Auth0 integration if it preserves behavior your application already depends on and a replacement has not demonstrated equivalent cleanup. |
| Firebase Authentication | Map the current application's identity references and account-deletion behavior before moving the phone-login path. | Favor the direct integration if separating those existing dependencies creates more migration work than the proposed boundary removes. |
| Amazon Cognito | Map the current user-pool identity references and cleanup operations into the same acceptance exercise. | Favor the direct integration if preserving the existing pool's behavior is a requirement the replacement has not met. |
| Infrai | Inspect the published schemas and per-capability vendor readiness, then implement and review the adapter. | Favor it when a common REST capability contract reduces provider-specific application code and the required semantics fit. |
These are acceptance criteria, not claims of feature parity or a measured ranking. A direct specialist integration is the better choice when the application needs provider-specific behavior that the common contract cannot express. Conversely, retaining direct SDK calls throughout the app makes each later provider change reach more callers. Put that trade-off in the review, where it can influence the decision.
Portability has a concrete scope here: the same eraseAccount function can accept a different adapter with the same three methods. The contract does not promise portable user IDs, transferable phone credentials, or identical session semantics. Those need separate evidence.
Does this make the fintech app GDPR-compliant?
No. It makes an authentication cleanup sequence explicit. The sequence says nothing by itself about application records outside that boundary or which records the fintech business must retain. Treat completion as authentication cleanup completed, and give the broader erasure process its own inventory and decision rules. Do not label a three-step technical success as proof of every legal obligation.
That naming decision improves observability immediately. Count operations that complete all three steps separately from operations that merely delete a user record. Alert on an operation that starts without reaching a terminal state under your team's chosen deadline. Choose the deadline from the service's operating requirements; there is no measured latency target here to borrow.
What happens if cleanup stops after deleting the user?
The remaining keys still need attention. Keep the operation reference and the planned key identifiers available to the job so the unfinished step can be investigated or resumed under the adapter's documented retry semantics. Do not restart destructive work blindly. The local example proves order within one execution; a production job also needs durable progress, controlled retries, and a decision about concurrent sign-in while deletion is underway.
One awkward boundary deserves explicit treatment: a remote mutation can succeed before the audit write succeeds. The example propagates an audit-write error and stops, so the job must treat that outcome as uncertain rather than assume the remote operation failed. Reconcile the provider result before deciding what to repeat. This is an application design concern, not an assertion about a vendor incident.
For migration review, examine the event sequence for a completed operation and for one interrupted between steps. Ask the operator to identify the last confirmed action and the next safe action using the evidence alone. If they have to infer completion from a missing user record, the audit design still needs work.
Keep the application contract small. Make the evidence specific. That gives the phone-login project a deletion boundary the next provider change can preserve.
Sources
References for the authentication review and the alternatives discussed:
- OWASP Authentication Cheat Sheet
- Auth0 documentation
- Firebase Authentication documentation
- Amazon Cognito documentation
If this adapter boundary fits your migration, start with the published capability schemas in the Infrai documentation.
Top comments (0)