fix: let TIC lookup run during onboarding + tolerate lowercase TIC status (#346)
* fix: let TIC lookup run during onboarding; tolerate lowercase TIC status Two bugs found in prod testing of the BankID picker: 1. Extension dispatcher required a resolved company context for every non-skipAuth route. /api/extensions/ext/tic/lookup is hit by Step2CompanyDetails' debounced fetcher (and the BankID picker's one-click path) during onboarding — before the user has a company — so requireCompanyId threw "No company context" and the call 500'd. Added a `skipCompanyContext` flag to ApiRouteDefinition. Marks /lookup and /profile on the TIC extension so they bypass company resolution but still require auth. Handlers don't use ctx for these routes, so no downstream changes were needed. 2. TIC enrichment has been observed returning lowercase 'failed' (and presumably other lowercase status values). The previous `=== 'Completed'` strict-case check would silently reject even a legitimately completed enrichment if TIC normalizes to lowercase. Now compares case-insensitively against 'completed' and 'partiallycompleted'. On non-usable enrichment, we now log the full response shape (minus the time-limited secureUrl token) so we can diagnose why real-user enrichments come back failed — useful for debugging TIC tenant config issues where status='failed' but no documented error field is set. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix: reject skipAuth + skipCompanyContext combination (PR review) Greptile P2 finding: if a future route accidentally sets both flags, skipAuth fires first and silently drops the auth requirement that skipCompanyContext implicitly assumes. No current route combines them, but this prevents the mistake from reaching prod. - Dispatcher throws 500 at matching time if both flags are set, with a descriptive log line naming the misconfigured route. - Type JSDoc now lists the three mutually-exclusive modes upfront and marks the combination as explicitly forbidden. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
8fd3f112f8
commit
1014d7cc2c
@@ -89,6 +89,21 @@ async function handleRequest(
|
||||
return NextResponse.json({ error: 'Route not found' }, { status: 404 })
|
||||
}
|
||||
|
||||
// Config sanity check: these flags are orthogonal and the combination is
|
||||
// nonsensical. `skipAuth` already implies no company resolution, so adding
|
||||
// `skipCompanyContext: true` is at best redundant — and if a maintainer
|
||||
// intended "auth required, no company" but also wrote `skipAuth: true`,
|
||||
// the auth requirement would be silently dropped (skipAuth fires first
|
||||
// below). Fail loudly instead of masking the mistake.
|
||||
if (matchedRoute.skipAuth && matchedRoute.skipCompanyContext) {
|
||||
console.error('[extension-dispatcher] route misconfigured: skipAuth + skipCompanyContext are mutually exclusive', {
|
||||
extensionId,
|
||||
routePath,
|
||||
method,
|
||||
})
|
||||
return NextResponse.json({ error: 'Route misconfigured' }, { status: 500 })
|
||||
}
|
||||
|
||||
// For skipAuth routes (e.g. OAuth callbacks from external providers),
|
||||
// skip user auth, toggle check, and AI consent — dispatch immediately
|
||||
if (matchedRoute.skipAuth) {
|
||||
@@ -118,8 +133,6 @@ async function handleRequest(
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||
}
|
||||
|
||||
const companyId = await requireCompanyId(supabase, user.id)
|
||||
|
||||
// If path params were extracted, create a new Request with them as search params
|
||||
let handlerRequest = request
|
||||
if (Object.keys(extractedParams).length > 0) {
|
||||
@@ -138,6 +151,15 @@ async function handleRequest(
|
||||
})
|
||||
}
|
||||
|
||||
// Routes that are authenticated but run before a company exists (TIC
|
||||
// /lookup during onboarding, for example) opt out of company resolution.
|
||||
// Dispatch without a context — handlers that opt in must not rely on ctx.
|
||||
if (matchedRoute.skipCompanyContext) {
|
||||
return matchedRoute.handler(handlerRequest)
|
||||
}
|
||||
|
||||
const companyId = await requireCompanyId(supabase, user.id)
|
||||
|
||||
// Build context and dispatch
|
||||
const ctx = createExtensionContext(supabase, user.id, companyId, extensionId)
|
||||
return matchedRoute.handler(handlerRequest, ctx)
|
||||
|
||||
Reference in New Issue
Block a user