-
Notifications
You must be signed in to change notification settings - Fork 3.3k
feat(sessions): remove redis as priority option for session data #1600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This reverts commit 833e700.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Summary
Reverts commit 833e700 which added Redis as a priority storage option for session data in better-auth.
Major changes:
- Removed Redis secondary storage from
better-authsession configuration inapps/sim/lib/auth.ts:62-72 - Re-introduced complex fallback mechanism in OTP route that attempts to access
inMemoryCachevia(global as any).inMemoryCache - Restored in-memory cache in
redis.tsbut left it as module-scoped (not exported or attached to global)
Critical issue:
The OTP fallback code at apps/sim/app/api/chat/[identifier]/otp/route.ts:40-50 tries to access inMemoryCache through the global object, but inMemoryCache in redis.ts:14 is only module-scoped and never attached to global. This means the fallback will silently fail when Redis is unavailable, breaking OTP functionality for environments without Redis.
Confidence Score: 0/5
- This PR contains a critical runtime bug that will break OTP authentication in non-Redis environments
- The revert introduces broken code that attempts to access a module-scoped variable through the global object, which will always return undefined. This will cause OTP storage to silently fail when Redis is not available, breaking authentication flows.
- apps/sim/app/api/chat/[identifier]/otp/route.ts requires immediate attention - the fallback cache access pattern is fundamentally broken
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| apps/sim/app/api/chat/[identifier]/otp/route.ts | 1/5 | Reverted to complex fallback mechanism with broken global cache access that will fail at runtime |
| apps/sim/lib/auth.ts | 5/5 | Removed Redis secondary storage configuration for better-auth sessions |
| apps/sim/lib/redis.ts | 3/5 | Re-added in-memory cache fallback but not exported or accessible from other modules |
Sequence Diagram
sequenceDiagram
participant Client
participant OTPRoute
participant Redis
participant InMemoryCache
participant BetterAuth
participant Database
Note over Client,Database: OTP Flow After Revert
Client->>OTPRoute: Request OTP
OTPRoute->>Database: Query chat config
Database-->>OTPRoute: Chat details
OTPRoute->>OTPRoute: Generate OTP code
OTPRoute->>Redis: Check if available
alt Redis Available
Redis-->>OTPRoute: Client instance
OTPRoute->>Redis: Store OTP
Redis-->>OTPRoute: Stored
else Redis Not Available
Redis-->>OTPRoute: null
OTPRoute->>InMemoryCache: Try global access
Note over OTPRoute,InMemoryCache: Bug: cache not exported
InMemoryCache-->>OTPRoute: undefined
end
OTPRoute->>Client: Success response
Note over Client,Database: Session Storage After Revert
Client->>BetterAuth: Auth request
BetterAuth->>Database: Store in PostgreSQL only
Note over BetterAuth: Redis secondary storage removed
BetterAuth-->>Client: Session created
3 files reviewed, 1 comment
| // Access the in-memory cache directly - hacky but works for fallback | ||
| const inMemoryCache = (global as any).inMemoryCache |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: accessing inMemoryCache via (global as any).inMemoryCache breaks because inMemoryCache in redis.ts is module-scoped, not attached to global
| // Access the in-memory cache directly - hacky but works for fallback | |
| const inMemoryCache = (global as any).inMemoryCache | |
| // inMemoryCache is not accessible here - this code will not work |
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/app/api/chat/[identifier]/otp/route.ts
Line: 40:41
Comment:
**logic:** accessing `inMemoryCache` via `(global as any).inMemoryCache` breaks because `inMemoryCache` in `redis.ts` is module-scoped, not attached to global
```suggestion
// inMemoryCache is not accessible here - this code will not work
```
How can I resolve this? If you propose a fix, please make it concise.
This reverts commit 833e700.