You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: knowledge.md
+25Lines changed: 25 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -253,6 +253,30 @@ Important constants are centralized in `common/src/constants.ts`:
253
253
-`CREDITS_REFERRAL_BONUS`: Credits awarded for successful referral
254
254
- Credit limits for different user types
255
255
256
+
## Referral System
257
+
258
+
**IMPORTANT**: Referral codes must be applied through the npm-app CLI, not through the web interface.
259
+
260
+
- Web onboarding flow shows instructions for entering codes in CLI
261
+
- Users must type their referral code in the Codebuff terminal after login
262
+
- Auto-redemption during web login was removed to prevent abuse
263
+
- The `handleReferralCode` function in `npm-app/src/client.ts` handles CLI redemption
264
+
- The `redeemReferralCode` function in `web/src/app/api/referrals/helpers.ts` processes the actual credit granting
265
+
266
+
### OAuth Referral Code Preservation
267
+
268
+
**Problem**: NextAuth doesn't preserve referral codes through OAuth flow because:
269
+
270
+
- NextAuth generates its own state parameter for CSRF/PKCE protection
271
+
- Custom state parameters are ignored/overwritten
272
+
- OAuth callback URLs don't always survive the round trip
273
+
274
+
**Solution**: Multi-layer approach implemented in SignInButton and ReferralRedirect components:
275
+
276
+
1.**Primary**: Use absolute callback URLs with referral codes for better NextAuth preservation
277
+
2.**Fallback**: Store referral codes in localStorage before OAuth starts
278
+
3.**Recovery**: ReferralRedirect component on home page catches missed referrals and redirects to onboard page
279
+
256
280
## Environment Variables
257
281
258
282
This project uses [Infisical](https://infisical.com/) for secret management. All secrets are injected at runtime.
@@ -270,6 +294,7 @@ The `.bin/bun` script automatically wraps bun commands with infisical when secre
270
294
**Worktree Support**: The wrapper automatically detects and loads `.env.worktree` files when present, allowing worktrees to override Infisical environment variables (like ports) for local development. This enables multiple worktrees to run simultaneously on different ports without conflicts.
271
295
272
296
The wrapper also loads environment variables in the correct precedence order:
297
+
273
298
1. Infisical secrets are loaded first (if needed)
274
299
2.`.env.worktree` is loaded second to override any conflicting variables
275
300
3. This ensures worktree-specific overrides (like custom ports) always take precedence over cached Infisical defaults
0 commit comments