Skip to content

Commit 65d5c41

Browse files
committed
pkg:auth:ref: enhance rate limiting configuration by adding custom rules for auth endpoints
1 parent a3d83ba commit 65d5c41

1 file changed

Lines changed: 48 additions & 20 deletions

File tree

packages/auth/src/configs/auth.config.ts

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,6 @@ export function createAuthConfig(env: Env) {
395395
// IP address tracking for rate limiting and session security
396396
ipAddress: {
397397
ipAddressHeaders: ['cf-connecting-ip', 'x-forwarded-for', 'x-real-ip'],
398-
disableIpTracking: false,
399398
},
400399
// Unified cross-domain cookie configuration
401400
// Works for both auth worker and integrated auth, all environments
@@ -413,25 +412,54 @@ export function createAuthConfig(env: Env) {
413412
domain: isDevelopment ? undefined : '.deepcrawl.dev',
414413
},
415414
},
416-
// rateLimit: {
417-
// window: 60, // time window in seconds
418-
// max: 100, // max requests in the window
419-
// customRules: {
420-
// "/sign-in/email": {
421-
// window: 10,
422-
// max: 3,
423-
// },
424-
// "/two-factor/*": async (request)=> {
425-
// // custom function to return rate limit window and max
426-
// return {
427-
// window: 10,
428-
// max: 3,
429-
// }
430-
// }
431-
// },
432-
// storage: 'secondary-storage',
433-
// modelName: 'rateLimit', //optional by default "rateLimit" is used
434-
// },
415+
rateLimit: {
416+
customRules: {
417+
'/sign-in/email': {
418+
window: 10,
419+
max: 3,
420+
},
421+
'/sign-up/email': {
422+
window: 10,
423+
max: 3,
424+
},
425+
'/forgot-password': {
426+
window: 10,
427+
max: 3,
428+
},
429+
'/reset-password': {
430+
window: 10,
431+
max: 3,
432+
},
433+
'/verify-email': {
434+
window: 10,
435+
max: 3,
436+
},
437+
'/two-factor/*': {
438+
window: 10,
439+
max: 3,
440+
},
441+
'/magic-link/*': {
442+
window: 10,
443+
max: 3,
444+
},
445+
'/organization/accept-invitation': {
446+
window: 10,
447+
max: 3,
448+
},
449+
'/change-password': {
450+
window: 10,
451+
max: 3,
452+
},
453+
'/change-email': {
454+
window: 10,
455+
max: 3,
456+
},
457+
'/passkey/*': {
458+
window: 10,
459+
max: 3,
460+
},
461+
},
462+
},
435463
} satisfies BetterAuthOptions;
436464

437465
return config;

0 commit comments

Comments
 (0)