javascriptserveradapterqwiksupertokens

Integrating multiple adapters with QwikJS


I would like to integrate my Qwik app with https://supertokens.com/. Is it possible to have Supertokens backend config to use Qwik's node adapter, and the rest of the app running on the AWS lambda adapter?

Since, the SSG adapter can be used for certain routes, I was hoping something similar could be done to run different parts of the app using different servers/adapters. Or, should I just create a separate app for Supertokens backend service?


Solution

  • You could use the custom framework provided by supertokens to add support for Qwik. The over:

    The idea is that you first create an instance of PreParsedRequest. You need to map the functions from context to the respective functions required to create an instance of PreParsedRequest. An example of this can be found here - here we create an instance to wrap NextJS' request object into something that SuperTokens can understand.

    You then create a CollectingResponse instance. See here.

    Then you call the supertokens middleware which takes in the instances you created above. This function either returns an error or a boolean (handled).

    If error, then you essentially propagate that to your app's error handler. Else, if handled, it means our middleware handled the request and created a response (the response body, headers are in the instance of CollectingResponse). This can happen if you call an API that our middleware exposes (like sign in, sign out etc). In this case, you have to create a response object as understood by your framework and transfer the body, headers, status code and cookies. See an example here.

    In case not handled, it means that it's a request to one of your APIs, and you pass it on to your other APIs, or return a 404.