Effect CommunityEC
Effect Community14mo ago
5 replies
Guillem

Integrating Supertokens with Effect Platform: Accessing Request and Response Objects

✅ SOLVED --> Use middleware

I'm creating an open source example to make Supertokens (feature rich auth library) work with Effect Platform.

How can I get
request
and response?

import Session from 'supertokens-node/recipe/session' // https://github.com/supertokens/supertokens-node/blob/master/lib/ts/recipe/session/index.ts

...

const ApiDemoLive = HttpApiBuilder.group(api, 'demo', handlers =>
    handlers
        .handle('hello', () =>
            Effect.succeed(new ResponseHello({ message: 'Hello from Effect!' })),
        )
        .handle('protected', () =>
            {
                let session = await Session.getSession(req, res); // <------- Request & Response
                Effect.succeed(new ResponseProtected({ userId: session.getUserId() })),
            }
        ),
)


Below is the Supertokens example with Express
https://supertokens.com/docs/passwordless/common-customizations/sessions/session-verification-in-api/get-session#using-getsession
import express from "express";
import Session from "supertokens-node/recipe/session";

let app = express();

app.post("/like-comment", async (req, res, next) => {
    try {
        let session = await Session.getSession(req, res);

        let userId = session.getUserId();
        //....
    } catch (err) {
        next(err);
    }
});
Was this page helpful?