Supertokens middleware - empty body {}
Opened this issue · 0 comments
manazoid commented
What version of Elysia is running?
Elysia: command not found
What platform is your computer?
Microsoft Windows NT 10.0.19044.0 x64
What steps can reproduce the bug?
install elysia
, supertokens-node
and elysia-connect-middleware
bun i elysia elysia-connect-middleware @elysiajs/cors supertokens-node
create project bun create elysia app
and insert following config of middlewares
// index.ts
import supertokens from "supertokens-node";
import Session from "supertokens-node/recipe/session";
import EmailPassword from "supertokens-node/recipe/emailpassword";
import {TypeInput} from "supertokens-node/types";
import Elysia from "elysia";
import {connect} from "elysia-connect-middleware";
import {cors} from '@elysiajs/cors'
import {middleware} from "supertokens-node/framework/express";
const SuperTokensConfig: TypeInput = {
supertokens: {
connectionURI: "https://try.supertokens.com",
},
appInfo: {
appName: "supertokensx",
apiDomain: "http://localhost:3000",
websiteDomain: "http://localhost:5173",
apiBasePath: "/auth",
websiteBasePath: "/auth",
},
recipeList: [
EmailPassword.init(),
Session.init(),
]
}
supertokens.init(SuperTokensConfig)
new Elysia()
.use(cors({
origin: "http://localhost:3000",
allowedHeaders: ["content-type", ...supertokens.getAllCORSHeaders()],
methods: ["GET", "PUT", "POST", "DELETE"],
credentials: true,
}));
.use(connect((req, res, next) => {
console.log(req.body) // check for empty body {}
next();
// @ts-ignore
}, middleware()))
.listen(3000, () => {
console.log('Server is running on http://localhost:3000');
});
run it and check signin endpoint with POST method on frontend
bun dev
- frontend can be any from this docs
What is the expected behavior?
Signin endpoint works fine and all other endpoints receive non-empty JSON body (like normal)
app.use(connect((req, res, next) => {
console.log(req.body) // not empty body {}
next();
// @ts-ignore
}, middleware()))
Body
{
"formFields": [
{
"id": "email",
"value": "user@example.com"
},
{
"id": "password",
"value": "1234abcd"
}
],
"shouldTryLinkingWithSessionUser": false
}
What do you see instead?
Elysia does not provide any body to middlewares and ignore it at all.
// HERE IS LOG OF BODY
app.use(connect((req, res, next) => {
console.log(req.body) // check for empty body {}
next();
// @ts-ignore
}, middleware()))
Body
{}
Additional information
https://supertokens.com/docs/emailpassword/quickstart/backend-setup
If you won't to open frontend, then you can try POST /auth/signin with following body for test
{
"formFields": [
{
"id": "email",
"value": "user@example.com"
},
{
"id": "password",
"value": "1234abcd"
}
],
"shouldTryLinkingWithSessionUser": false
}
Have you try removing the node_modules
and bun.lockb
and try again yet?
yes