refactor: eliminate workarounds, replace with idiomatic patterns#70
refactor: eliminate workarounds, replace with idiomatic patterns#70
Conversation
## hooks.server.ts - Remove redundant getSession() call (getUser() is sufficient for JWT validation) - Remove manual expired-session check (supabase handles this internally) - Replace 2 separate DB queries (memberships + subscriptions) with get_user_context RPC — consistent with layout.server.ts, saves 2 round-trips per protected request ## routes/+page.server.ts - Replace raw memberships query with get_user_context RPC (consistent with hooks) ## admin/settings/+page.server.ts action - Replace get_user_context RPC call (fetches too much) with targeted memberships query for just tenant_id — right tool for the job ## format.ts - Remove locale hack in formatCurrency (was manually mapping EUR→de-DE, USD→en-US, GBP→en-GB) - Use undefined locale so Intl.NumberFormat picks the correct locale for the currency automatically ## supabase.ts - Replace typeof window !== 'undefined' with browser from $app/environment (consistent with rest of codebase) ## (app)/+layout.svelte - Change $effect → $effect.pre for session/settings init — ensures stores are populated BEFORE first render, not after ## bookings/[type]/+page.svelte - Remove dead client-side isValidType guard (server already throws 404 for invalid types) - Use $derived for type/icon to properly track reactive data prop changes - Use satisfies for icons record type safety ## SQL: search_products - Change 'english' dictionary → 'simple' for language-agnostic full-text search - Adds ILIKE fallback for partial/typo matching - Fixes Greek product name search that was broken with English stemming ## SQL: mv_best_sellers - Remove synchronous refresh trigger that was blocking every order INSERT transaction - Convert to scheduled refresh via keep-alive cron (daily) using service_role RPC - Add refresh_mv_best_sellers() call to keep-alive endpoint ## mocks.ts - Add rpc() mock to createSupabaseMock (now required since hooks uses get_user_context) - Build get_user_context response from existing config shape - Add rpc to return type signature ## tests - Remove session-expiry test (the feature was removed from hooks — getSession no longer called)
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (2)
📒 Files selected for processing (10)
📝 WalkthroughWalkthroughThe pull request refactors session and membership handling to use an RPC-based context fetch, updates client-side utilities, and improves type safety in the booking component. Most pages migrate to the get_user_context RPC, though admin settings reverts to a direct query. Test coverage for session expiry is removed. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment |
hooks.server.ts
routes/+page.server.ts
admin/settings/+page.server.ts action
format.ts
supabase.ts
(app)/+layout.svelte
bookings/[type]/+page.svelte
SQL: search_products
SQL: mv_best_sellers
mocks.ts
tests
Summary by CodeRabbit
Bug Fixes
Improvements