DanielAtStruggly
01/20/2023, 8:11 AMrp_st
01/20/2023, 8:49 AMrp_st
01/20/2023, 8:49 AMDanielAtStruggly
01/20/2023, 10:12 AMrp_st
01/20/2023, 10:28 AMporcellus
01/20/2023, 10:28 AMporcellus
01/20/2023, 10:28 AMDanielAtStruggly
01/20/2023, 10:30 AMporcellus
01/20/2023, 10:49 AM{
provide: APP_GUARD,
useClass: ThrottlerGuard
}
(they write about this at the start of the guide you linked)porcellus
01/20/2023, 10:50 AMrp_st
01/20/2023, 10:53 AMporcellus
01/20/2023, 10:54 AMDanielAtStruggly
01/20/2023, 11:29 AMprovide: APP_GUARD
. Unfortunately, this doesn't help with the supertokens middleware 🙁 .porcellus
01/20/2023, 1:12 PMts
import { Injectable, NestMiddleware } from '@nestjs/common';
import { middleware } from 'supertokens-node/framework/express';
import { RateLimiterMemory } from 'rate-limiter-flexible';
@Injectable()
export class AuthMiddleware implements NestMiddleware {
supertokensMiddleware: any;
rateLimiter: RateLimiterMemory;
combinedMiddleware: any;
constructor() {
this.rateLimiter = new RateLimiterMemory({
points: 2, // 2 requests
duration: 60, // per 60 second by IP
});
this.supertokensMiddleware = middleware();
this.combinedMiddleware = (req, res, next) => {
this.rateLimiter
.consume(req.ip)
.then(() => {
this.supertokensMiddleware(req, res, next);
})
.catch(() => {
res.status(429).send('Too Many Requests');
});
};
}
use(req: Request, res: any, next: () => void) {
return this.combinedMiddleware(req, res, next);
}
}
porcellus
01/20/2023, 1:12 PMporcellus
01/20/2023, 1:14 PMAuthMiddleware
DanielAtStruggly
01/20/2023, 1:19 PMrp_st
01/20/2023, 1:19 PMporcellus
01/20/2023, 1:42 PMDanielAtStruggly
01/21/2023, 2:05 PMporcellus
01/21/2023, 2:22 PMporcellus
01/21/2023, 2:23 PMmansuralikoroglu
06/19/2023, 7:00 PM