mansuralikoroglu
06/20/2023, 11:17 AMSuperTokens with a NestJS app. 😦
Currently SuperTokens sdk is used as a middleware. This is also described in the NestJS integration documentation of SuperTokens.
However here is how NestJS request-response cycle works.
request -> middleware -> guard -> interceptor (before) -> pipe -> controller -> service -> controller -> interceptor (after) -> filter (if applicable) -> response
With SuperTokens middleware it will work for configured SuperTokens routes just like below.
request -> middleware -> response
With that, some important aspects of the application might lose.
1. No guards called. Guards can be used to restrict ip address, or restrict geolocation. There will be no restrictions for SuperTokens routes.
2. No interceptors called. Interceptors can be used for metrics, all kind of analysis and logs. There will be no analysis about what Supertokens routes called with what frequency, in what times and many more.
To give an example, commonly used middlewares in NestJS are cors() and helmet() middlewares. They do not early terminate request so interceptors, guards and other middlewares also run.
So, current NestJS integration with middlewares does not seem right to me. What do you think about the concerns? Are there any plans to enhance NestJS integration?rp_st
06/20/2023, 11:43 AMporcellus
06/20/2023, 11:50 AMporcellus
06/20/2023, 11:53 AMmansuralikoroglu
06/20/2023, 11:57 AMmansuralikoroglu
06/20/2023, 11:58 AMSuperTokens. What do you suggest for us for now?porcellus
06/20/2023, 12:03 PMporcellus
06/20/2023, 12:03 PMmansuralikoroglu
06/20/2023, 12:04 PMmansuralikoroglu
06/20/2023, 12:07 PM/metrics without middlewares. I think proper way for a nestjs integration would be creating controllers in a module and users can register that module. into their applications. So everything will be in regular nestjs request-response cycle.
However this might be a maintenance burder for you unfortunately. Because it will require creating a NestJS module and keeping it sync with current sdk.mansuralikoroglu
06/20/2023, 12:08 PMNestJS integrations?rp_st
06/20/2023, 12:13 PMmansuralikoroglu
06/20/2023, 12:13 PMsdk and keeping that in a base that would be used with sdk and NestJS module can greatly reduce the maintenance burden.
TBH I did not check current sdk's code. Maybe it's already like that.porcellus
06/20/2023, 12:15 PMporcellus
06/20/2023, 12:20 PMporcellus
06/20/2023, 12:21 PMmansuralikoroglu
06/20/2023, 12:24 PMporcellus
06/20/2023, 12:26 PMmansuralikoroglu
06/20/2023, 12:29 PMNestJS integration.
https://github.com/supertokens/supertokens-node/issues/593mansuralikoroglu
06/20/2023, 12:29 PMporcellus
06/20/2023, 12:59 PMmansuralikoroglu
06/26/2023, 5:25 PMrp_st
06/26/2023, 5:30 PMmansuralikoroglu
06/26/2023, 5:39 PM