Skip to content

fix(auth): return promise chains from auth interceptor to prevent unh…#81

Merged
SteakFisher merged 1 commit into
mainfrom
fix/auth-interceptor-promise-chain
Jun 6, 2026
Merged

fix(auth): return promise chains from auth interceptor to prevent unh…#81
SteakFisher merged 1 commit into
mainfrom
fix/auth-interceptor-promise-chain

Conversation

@SteakFisher

Copy link
Copy Markdown
Member

…andled rejections

@greptile-apps

greptile-apps Bot commented Jun 6, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes two fire-and-forget promise chains in the gRPC auth interceptor by adding return before each async call, ensuring the promise is propagated to the caller rather than discarded. The README is also simplified to focus on CLI-driven setup rather than manual steps.

  • src/interceptors/auth.ts: checkWebhookEndpoint and lookupApiKey calls now return their promise chains. The now-redundant return; after the needsWebhook block is removed. This means any unhandled rejection not caught by the local .catch is surfaced to the gRPC framework rather than silently dropped.
  • README.md: Content rewritten to lead with the bunx scrawn@latest CLI workflow, dropping the manual Docker / migration / env steps and adding an SDK snippet.

Confidence Score: 5/5

Safe to merge — the two-line change is minimal, targeted, and consistent with the existing error-handling pattern throughout the interceptor.

Both async branches already had .catch handlers that forward errors to the gRPC callback; the only change is surfacing the returned promise instead of discarding it. The logic, error paths, and callback flow are identical to before — no new code paths are introduced and no existing checks are removed.

No files require special attention.

Important Files Changed

Filename Overview
src/interceptors/auth.ts Adds return to two fire-and-forget promise chains; removes now-redundant explicit return — correct fix with no behaviour regressions.
README.md Documentation-only rewrite: shorter, CLI-first quick-start with an SDK code snippet; no code logic affected.

Sequence Diagram

sequenceDiagram
    participant C as gRPC Client
    participant I as authInterceptor
    participant AC as apiKeyCache
    participant DB as PostgreSQL
    participant WC as webhookEndpointCache
    participant H as gRPC Handler

    C->>I: request (Bearer token)
    I->>I: "validate header & key format"
    I->>AC: cache.get(apiKeyHash)
    
    alt Cache HIT
        AC-->>I: cached record
        I->>I: role check
        alt needsWebhook path
            I->>WC: webhookEndpointCache.get(apiKeyId)
            alt cache miss
                WC->>DB: SELECT webhook endpoint
                DB-->>WC: result
            end
            WC-->>I: hasEndpoint
            alt hasEndpoint
                I->>H: return handler(call, callback)
            else no endpoint
                I-->>C: callback(permissionDenied)
            end
        else standard path
            I->>H: return handler(call, callback)
        end
    else Cache MISS
        I->>DB: return lookupApiKey(hash)
        DB-->>I: apiKeyRecord
        I->>I: validate (null/revoked/expired/role)
        I->>AC: apiKeyCache.set(...)
        alt needsWebhook path
            I->>WC: return checkWebhookEndpoint(id)
            WC-->>I: hasEndpoint
            alt hasEndpoint
                I->>H: return handler(call, callback)
            else no endpoint
                I-->>C: callback(permissionDenied)
            end
        else standard path
            I->>H: return handler(call, callback)
        end
    end
Loading

Reviews (1): Last reviewed commit: "fix(auth): return promise chains from au..." | Re-trigger Greptile

@SteakFisher SteakFisher merged commit ccd4be9 into main Jun 6, 2026
2 checks passed
@SteakFisher SteakFisher deleted the fix/auth-interceptor-promise-chain branch June 6, 2026 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant