Skip to content

feat: optimize context, add auth middleware, consolidate components, add query keys#215

Merged
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
Leothosine:feat/context-auth-components-querykeys
Apr 26, 2026
Merged

feat: optimize context, add auth middleware, consolidate components, add query keys#215
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
Leothosine:feat/context-auth-components-querykeys

Conversation

@Leothosine
Copy link
Copy Markdown
Contributor

Summary

This PR addresses four issues across performance, security, structure, and caching:

  • Context API Optimization: Added useMemo to the ToastContext provider value so the context object is only recreated when its contents actually change, preventing unnecessary re-renders in all consumers
  • Route Handler Authentication: Added
    equireAuth middleware helper in src/lib/authMiddleware.ts - a single function that validates the Authorization: Bearer header and returns a 401 response if missing or invalid, ready to be used across all protected API routes
  • Duplicate Component Definitions: Added src/components/index.ts as the canonical barrel export for all shared UI components, establishing @/components as the single source of truth and providing a migration path away from @/app/components
  • Query Key Factory: Added src/lib/queryKeys.ts with a structured key factory covering courses, user, search, bookmarks, and notes - ensures consistent, type-safe cache keys across all data-fetching hooks

Changes

  • src/context/ToastContext.tsx - memoized context value with useMemo
  • src/lib/authMiddleware.ts -
    equireAuth helper for route protection
  • src/components/index.ts - canonical component barrel export
  • src/lib/queryKeys.ts - query key factory for all API resources

closes #162
closes #163
closes #171
closes #174

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Apr 26, 2026

@Leothosine Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

…add query keys

- Memoize ToastContext provider value with useMemo to prevent unnecessary re-renders (closes rinafcode#162)
- Add requireAuth middleware helper for consistent API route authentication (closes rinafcode#163)
- Add src/components/index.ts barrel as canonical component export point (closes rinafcode#171)
- Add queryKeys factory for consistent cache keys across all API calls (closes rinafcode#174)
@RUKAYAT-CODER RUKAYAT-CODER merged commit e9c1c48 into rinafcode:main Apr 26, 2026
1 of 4 checks passed
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.

Query Key Factory Missing Duplicate Component Definitions Route Handler Authentication Context API Optimization

2 participants