Hi 👋
I have some concerns using
SuperTokens
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?