https://supertokens.com/ logo
Title
g

ggishant

12/29/2022, 9:05 AM
Hey team, we're using supertokens with golang. For debugging usage, we are logging all our API requests into a db, but we're unable to catch requests from supertokens in the middleware. The middleware is called in the very beginning. We're using Gorilla Mux.
r

rp

12/29/2022, 9:06 AM
hey @ggishant you could always add a custom middlware before ours and log through that?
g

ggishant

12/29/2022, 9:09 AM
We're registering our routers after this and at the end
r

rp

12/29/2022, 9:11 AM
you are using the supertokens middleware twice?
g

ggishant

12/29/2022, 9:13 AM
No, the first supertokens middleware is our custom middleware, that performs some checks before calling the verify session function for supertokens. I suppose the second middleware is attach the routes that supertokens uses.
r

rp

12/29/2022, 9:14 AM
ahh righrt
so you want to do something like where the logAPiRequest middleware runs before the supertokens middleware:
apmhttp.Wrap(logAPIRequestToDb(supertokens.Middleware(r)))
the code above is of course not right, but something that semantically is like that
g

ggishant

12/29/2022, 9:17 AM
But isn't exactly something like this happening already?
r

rp

12/29/2022, 9:17 AM
not really. The supertokens middleware runs first and then the logging one. If the API is handled by the supertokens middleware, then it doesn't call the next one since the response is already sent
g

ggishant

12/29/2022, 9:48 AM
Thanks a ton, this worked!