made invite code validation more lax and added numbers#1340
made invite code validation more lax and added numbers#1340Hugo0 merged 1 commit intopeanut-walletfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
💡 Enable Vercel Agent with $100 free credit for automated AI reviews |
WalkthroughCentralizes invite code generation through new utilities (generateInviteCodeSuffix, updated generateInviteCodeLink) and introduces redirect URL validation (getValidRedirectUrl). Updates points page to consume generated invite data from utilities instead of computing locally. Changes Invite import from value to type import. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Changes involve new utility logic with deterministic hashing and URL sanitization patterns alongside component refactoring. Logic is straightforward but requires verification of hashing determinism and redirect sanitization security considerations. Possibly related PRs
Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/utils/general.utils.ts (1)
1336-1347: Add input validation for username parameter.The function should validate that
usernameis non-empty to avoid edge cases. Additionally, the simple character code summation hash could produce collisions for different usernames (e.g., "ab" and "ba" would have the same hash). While the comment indicates this is "purely cosmetic," consider whether collision handling is needed.Apply this diff to add validation:
export const generateInviteCodeSuffix = (username: string): string => { + if (!username || username.trim() === '') { + throw new Error('Username cannot be empty') + } const lowerUsername = username.toLowerCase() // Create a simple hash from the username const hash = lowerUsername.split('').reduce((acc, char) => acc + char.charCodeAt(0), 0) // Generate 3 digits between 100-999 const threeDigits = 100 + (hash % 900) return threeDigits.toString() }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (2)
src/app/(mobile-ui)/points/page.tsx(2 hunks)src/utils/general.utils.ts(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-08T17:13:13.155Z
Learnt from: Zishan-7
PR: peanutprotocol/peanut-ui#1299
File: src/app/(mobile-ui)/points/page.tsx:41-51
Timestamp: 2025-10-08T17:13:13.155Z
Learning: In `src/app/(mobile-ui)/points/page.tsx`, the icon name "invite-heart" is intentionally used (not "inviter-heart") when displaying who invited the current user, as this is a deliberate design choice despite semantic differences with UserHeader usage.
Applied to files:
src/app/(mobile-ui)/points/page.tsx
🧬 Code graph analysis (1)
src/app/(mobile-ui)/points/page.tsx (1)
src/utils/general.utils.ts (1)
generateInviteCodeLink(1349-1354)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Deploy-Preview
🔇 Additional comments (6)
src/utils/general.utils.ts (3)
1332-1334: LGTM: Clear invite message.The updated share text effectively communicates the app's value proposition.
1356-1372: LGTM: Solid security implementation.The function properly handles URL decoding failures and uses the existing
sanitizeRedirectURLfunction to prevent open redirect vulnerabilities. Good defensive coding with clear fallback behavior.
1349-1354: Empty username edge case is handled gracefully—no issues found.All three call sites consistently use the
username ?? ''pattern, andgenerateInviteCodeSuffixproperly handles empty strings without errors. With an empty username, the function generates a valid invite code (e.g.,INVITESYOU100), though it lacks the username prefix. This graceful handling resolves the original concern.src/app/(mobile-ui)/points/page.tsx (3)
14-14: LGTM: Good TypeScript optimization.Using
import typefor type-only imports improves tree-shaking and makes the intent clearer.
15-15: LGTM: Centralizes invite code generation.Importing the utility function promotes consistency and maintainability across the codebase.
29-30: LGTM: Clean centralized usage.The destructuring pattern cleanly separates the invite code and link. However, note that the empty string fallback (
username ?? '') relies on proper validation ingenerateInviteCodeSuffix(see my comment insrc/utils/general.utils.ts).
No description provided.