Skip to content

fix: handle auth separately#11

Merged
sanny-io merged 1 commit intodevfrom
fix/auth-caching
Feb 3, 2026
Merged

fix: handle auth separately#11
sanny-io merged 1 commit intodevfrom
fix/auth-caching

Conversation

@sanny-io
Copy link
Member

@sanny-io sanny-io commented Feb 3, 2026

Closes #10

Summary by CodeRabbit

Release Notes

  • New Features

    • Cache queries now support authentication-scoped isolation, enabling separate cache entries for different authenticated users even when query parameters are identical.
  • Tests

    • Added comprehensive test coverage for auth-scoped caching behavior across memory and Redis implementations.
  • Chores

    • Updated development environment configuration and VS Code extension recommendations.
    • Enhanced package metadata with expanded keywords for improved discoverability.

@coderabbitai
Copy link

coderabbitai bot commented Feb 3, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This PR introduces auth-aware cache key generation for the cache package, extending the onQuery handler to include authenticated user IDs in cache hashes when auth is present. It adds development tooling support, updates package metadata, and generates type definitions for test schemas.

Changes

Cohort / File(s) Summary
Developer Configuration
.devcontainer/devcontainer.json, .vscode/extensions.json
Added zenstack.zenstack-v3 VS Code extension to development environment and recommended extensions list.
Package Metadata
packages/cache/package.json
Reordered and expanded keywords array, adding redis and self-hosted to the list of package tags.
Cache Plugin Logic
packages/cache/src/plugin.ts
Extended onQuery handler signature to accept a client parameter; updated hash construction to conditionally include userId derived from client.$auth when auth is present, otherwise maintaining original hash payload.
Test Files
packages/cache/tests/memory.test.ts, packages/cache/tests/redis.test.ts
Updated schema import paths and added new "caches auth separately" test cases verifying that cache state differs based on authentication state via $setAuth.
Generated Schema Types
packages/cache/tests/schemas/basic/input.ts, packages/cache/tests/schemas/basic/models.ts
Added comprehensive auto-generated TypeScript type definitions mapping ORM argument shapes and result types for User, Post, Comment, and Profile entities with standard CRUD operation aliases.
Schema Definition
packages/cache/tests/schemas/basic/schema.ts, packages/cache/tests/schemas/basic/schema.zmodel
Introduced new schema.zmodel with SQLite datasource and data models (User, Post, Comment, Profile with Role enum); updated compiled schema.ts to remove access-control attributes and refine array type handling in relation definitions.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Plugin as Cache Plugin
    participant AuthModel as Auth Model Info
    participant Cache

    Client->>Plugin: onQuery({ args, model, operation, proceed, client })
    
    alt client.$auth is present
        Plugin->>AuthModel: Extract auth type and ID fields
        Plugin->>Plugin: Compute userId from client.$auth
        Plugin->>Plugin: Construct hash: { args, model, operation, userId }
    else client.$auth is absent
        Plugin->>Plugin: Construct hash: { args, model, operation }
    end
    
    Plugin->>Cache: Lookup with computed hash
    alt Cache hit
        Cache-->>Plugin: Return cached result
    else Cache miss
        Plugin->>Client: proceed() to fetch fresh data
        Client-->>Plugin: Return result
        Plugin->>Cache: Store result with hash
    end
    
    Plugin-->>Client: Return result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/auth-caching

Important

Action Needed: IP Allowlist Update

If your organization protects your Git platform with IP whitelisting, please add the new CodeRabbit IP address to your allowlist:

  • 136.113.208.247/32 (new)
  • 34.170.211.100/32
  • 35.222.179.152/32

Failure to add the new IP will result in interrupted reviews.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sanny-io sanny-io merged commit 4ba6ad6 into dev Feb 3, 2026
1 of 2 checks passed
@sanny-io sanny-io deleted the fix/auth-caching branch February 3, 2026 10:24
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.

The AuthType ID should be part of the cache key

1 participant