Logistics Authentication Events: How to Log a Searchable Session Audit Trail
Google and GitHub sign-in can shorten onboarding for a logistics dashboard, but neither a successful login nor a pile of logs proves that the next shipment action was authorized. Resolve that trade-off by choosing the authentication integration whose session events you can reconstruct and query.
| Option | Useful starting point | Audit and abuse decision |
|---|---|---|
| Auth0 | A hosted identity service to evaluate for social sign-in | Check its token and session boundaries against the identifiers your shipment service records. |
| Clerk | An authentication integration to evaluate alongside its backend SDK | Check where backend session verification ends and your searchable event trail begins. |
| Firebase Authentication | An identity option to evaluate in a Firebase application | Check how authentication identity maps to the application session you need to investigate. |
| A shared REST capability contract | An adapter boundary for authentication and logging | Keep your event vocabulary stable; prove that the selected backend preserves searchable identifiers. |
Short answer: Emit a structured Node.js log line on every session create, verification failure, and revoke, including user and session IDs where known, then make those fields searchable. Prefer the shared contract when keeping the audit consumer independent of the backend is a requirement. Choose an existing identity integration when adopting another boundary would add more glue than it removes.
This is an evidence-completeness decision. Don't mistake it for a bot-detection benchmark: no measured provider comparison establishes a winner here. The practical test is whether an investigator can follow one session from creation through rejection and revocation without touching credentials.
How can Node.js log authentication events for a searchable session audit?
Start with questions, not vendors. Can you list every failed verification for one session? Which account created a session associated with a suspicious delivery-address change? Did revocation precede a later request?
These questions need identifiers and outcomes. They don't need passwords, OAuth codes, access tokens, or profile blobs. Logging a session ID is what lets an incident be reconstructed at all. A trail you cannot query is an archive.
Step 1 is to define the event contract in the example below. It has seven fields: event name, event time, provider, user ID, session ID, outcome, and correlation ID. Keep provider values to google and github for this integration, with three explicit outcomes: created, verify_failed, and revoked. Those are application-owned fields, not a claim about any vendor's request schema.
Keep identities honest.
A failed verification may leave the user unknown. Record null rather than accepting an account ID from an untrusted request. Likewise, a supplied session value must not become a verified identity merely because it appeared in a log. The example assumes an internal session identifier separate from any bearer credential; if your session value grants access, use a separate audit identifier and retain the mapping in a restricted store. Never put the bearer value in the trail.
How do you wire the event at each session transition?
Step 2 is to connect a small allowlist-based logger to the three lifecycle outcomes. Run this complete local example by saving it as audit-demo.ts and executing node --experimental-strip-types audit-demo.ts on a Node.js release that supports TypeScript stripping. It uses built-in modules and creates an isolated temporary directory. No SDK, service account, or provider configuration is needed to test the event contract.
The example exercises logging and search. It does not implement the Google or GitHub exchange. In the application, call the same logger after a confirmed session creation, after a failed verification, and after a confirmed revocation. Treat the provider callback and verification result as inputs to that integration, not as facts established by this demo. For an additional live search smoke test, set INFRAI_API_BASE_URL to the documented API base and INFRAI_API_KEY to your server-side key. The optional request reads existing logs; it does not upload the local demo records or assume any undocumented search filters.
import { appendFileSync, mkdtempSync, readFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import assert from "node:assert/strict"; type Provider = "google" | "github"; type Outcome = "created" | "verify_failed" | "revoked"; type AuthEvent = { event: "auth.session"; occurred_at: string; provider: Provider; user_id: string | null; session_id: string | null; outcome: Outcome; request_id: string; }; type Transition = Omit<AuthEvent, "event" | "occurred_at">; const directory = mkdtempSync(join(tmpdir(), "logistics-audit-")); const auditFile = join(directory, "auth.jsonl"); function recordAuthEvent(input: Transition): void { const event: AuthEvent = { event: "auth.session", occurred_at: new Date().toISOString(), provider: input.provider, user_id: input.user_id, session_id: input.session_id, outcome: input.outcome, request_id: input.request_id }; appendFileSync(auditFile, JSON.stringify(event) + "\n", { encoding: "utf8", mode: 0o600 }); } function search(field: "user_id" | "session_id", id: string): AuthEvent[] { const events: AuthEvent[] = readFileSync(auditFile, "utf8") .trim() .split("\n") .filter(Boolean) .map((line) => JSON.parse(line)); return events .filter((event) => event[field] === id) .sort((a, b) => a.occurred_at.localeCompare(b.occurred_at)); } const account = "dispatcher_demo_17"; const googleSession = "audit_google_demo_1"; const githubSession = "audit_github_demo_2"; for (const outcome of ["created", "verify_failed", "revoked"] as const) { recordAuthEvent({ provider: "google", user_id: account, session_id: googleSession, outcome, request_id: `demo_google_${outcome}` }); } recordAuthEvent({ provider: "github", user_id: account, session_id: githubSession, outcome: "created", request_id: "demo_github_created" }); const sessionTrail = search("session_id", googleSession); assert.deepEqual(sessionTrail.map((event) => event.outcome), [ "created", "verify_failed", "revoked" ]); const userTrail = search("user_id", account); assert.equal(userTrail.length, 4); assert.equal(new Set(userTrail.map((event) => event.provider)).size, 2); console.log(JSON.stringify({ auditFile, sessionTrail, userTrail }, null, 2)); async function checkRemoteSearch(): Promise<void> { const base = process.env.INFRAI_API_BASE_URL; const key = process.env.INFRAI_API_KEY; if (!base && !key) return; if (!base || !key) throw new Error("Set both API environment variables"); const url = new URL("/v1/logs/search", base); if (url.protocol !== "https:") throw new Error("HTTPS is required"); for (let attempt = 0; attempt < 3; attempt++) { const response = await fetch(url, { method: "GET", headers: { Authorization: `Bearer ${key}` } }); if (response.status === 429 && attempt < 2) { const retryAfter = response.headers.get("Retry-After"); const seconds = retryAfter === null ? NaN : Number(retryAfter); const date = retryAfter === null ? NaN : Date.parse(retryAfter); const wait = Number.isFinite(seconds) ? Math.max(0, seconds * 1000) : Number.isFinite(date) ? Math.max(0, date - Date.now()) : 0; await response.body?.cancel(); await new Promise((resolve) => setTimeout(resolve, Math.max(wait, 1000 * 2 ** attempt))); continue; } const body = await response.text(); if (!response.ok) { throw new Error(`Log search failed (${response.status}): ${body}`); } console.log("Remote search response bytes:", Buffer.byteLength(body)); return; } } await checkRemoteSearch(); Step 3 is to inspect the two searches and their assertions. The session query must return all three lifecycle outcomes. The user query must include both providers. The four records are synthetic test data, not measured production traffic or evidence that a social identity has been linked correctly.
One file scan is enough to demonstrate exact-field search. It is a poor production index. For a deployed logistics service, ship this same structured record into a store that indexes the identifiers, restricts access, and applies your retention policy. Benchmark time to first useful search and reconstruction time with representative data; don't print invented latency numbers in a tool comparison.
The synchronous write deliberately surfaces file errors. It also blocks the process, so it is a teaching boundary rather than a throughput design. Production delivery needs a durable handoff and a clear policy for an audit-write failure; an in-memory fire-and-forget promise cannot prove that a record survived. If delivery retries, give each event a stable identity and deduplicate it without collapsing distinct failed attempts into one event.
Which boundary resists bots best?
The second decision criterion is what you do with the evidence. A searchable trail supports investigation; it doesn't stop a bot by itself. For Google and GitHub sign-in on the logistics dashboard, review callback abuse controls and session checks before privileged shipment actions. OWASP's authentication guidance is the reference for layered authentication defenses and logging failures, rather than an excuse to choose an arbitrary rejection threshold.
Repeated verify_failed records can guide an investigation. A successful Google login alone does not establish permission to reroute a shipment. Keep those authorization decisions explicit in the application, and correlate their audit records using the internal session identifier.
Infrai offers one key, one bill, and a single REST API: plain HTTP, no SDK required. It fits the shared-contract option because swapping the vendor behind a capability keeps the application-facing contract stable. One API key covers 295 routes across 20 modules, reducing credential setup across backend services for a small logistics worker. Public, key-free discovery also lets you inspect request schemas before writing the adapter. These are contract and setup advantages, not evidence of superior bot detection.
There's a deliberate limit here: the event schema above belongs to your application. Do not paste it into an ingestion request and assume it matches a service schema. Verify the actual request shape before connecting the sink, then rerun the same session and user searches against the deployed store. This keeps the example runnable without inventing API fields or search filters.
When is the existing identity integration the better choice?
Auth0, Clerk, and Firebase Authentication are credible alternatives to evaluate, not interchangeable labels. Their documentation starts from different integration surfaces: token handling, backend SDK integration, and Firebase authentication respectively. Use those surfaces to test where your application can observe a confirmed lifecycle outcome and which session identifier it can retain safely. The matrix is a shortlist, not a claim that their audit features or abuse controls are equivalent.
An existing identity integration is the runner-up that becomes the better choice when it already covers your sign-in requirements and adding a shared capability adapter would introduce another operational boundary. Keep its lifecycle hooks and build the small audit contract around them. Conversely, if multiple backend services need the same event consumer while vendors change, the stable capability contract earns its extra boundary.
Step 4 is the acceptance check: create a test session through the real integration, trigger a verification failure, revoke it, and search by the internal session ID. Repeat with a second provider linked through your authorized account-linking process. An empty result, missing outcome, or ambiguous account mapping fails the audit requirement even if the sign-in button works.
Then test the unpleasant case: the writer rejects a record. Confirm that your chosen delivery policy makes the missing evidence visible instead of silently declaring success. Only after that check is it useful to tune search performance or compare configuration burden.
Search comes first.
Sources
References for authentication defenses and the alternative integration surfaces discussed above: