Skip to content

Commit 291bf09

Browse files
authored
Merge pull request #1006 from supertokens/test/session-cookie-setting
test: setting session cookies
2 parents ac1c289 + 80fb310 commit 291bf09

File tree

4 files changed

+140
-2
lines changed

4 files changed

+140
-2
lines changed

test/auth-react-server/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ morgan.token("body", function (req, res) {
685685
});
686686

687687
morgan.token("res-body", function (req, res) {
688-
return typeof res.__custombody__ ? res.__custombody__ : JSON.stringify(res.__custombody__);
688+
return typeof res.__custombody__ === "string" ? res.__custombody__ : JSON.stringify(res.__custombody__);
689689
});
690690

691691
app.use(urlencodedParser);

test/test-server/package-lock.json

Lines changed: 126 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/test-server/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"dependencies": {
1111
"debug": "^4.3.5",
1212
"express": "^4.19.2",
13+
"morgan": "^1.10.0",
1314
"nock": "^13.5.4",
1415
"typescript": "^5.4.5"
1516
},

test/test-server/src/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import { resetOverrideLogs, logOverrideEvent, getOverrideLogs } from "./override
5959
import Dashboard from "../../../recipe/dashboard";
6060
import DashboardRecipe from "../../../lib/build/recipe/dashboard/recipe";
6161
import { TypeInput as WebauthnTypeInput } from "../../../lib/build/recipe/webauthn/types";
62-
62+
import morgan from "morgan";
6363
const { logDebugMessage } = logger("com.supertokens:node-test-server");
6464

6565
const API_PORT = Number(process.env.API_PORT || 3030);
@@ -163,6 +163,7 @@ function initST(config: any) {
163163
"Session.getCookieNameForTokenType",
164164
getCookieNameForTokenType
165165
),
166+
getTokenTransferMethod: () => config.getTokenTransferMethod ?? "any",
166167
override: {
167168
apis: overrideBuilderWithLogging("Session.override.apis", config?.override?.apis),
168169
functions: overrideBuilderWithLogging(
@@ -387,13 +388,23 @@ function initST(config: any) {
387388
supertokens.init(init);
388389
}
389390

391+
morgan.token("body", function (req, res) {
392+
return JSON.stringify(req.body);
393+
});
394+
395+
morgan.token("res-body", function (req, res) {
396+
return typeof res.__custombody__ === "string" ? res.__custombody__ : JSON.stringify(res.__custombody__);
397+
});
398+
390399
const app = express();
391400
app.use(express.json());
392401
app.use((req, res, next) => {
393402
logDebugMessage(req.method, req.path);
394403
next();
395404
});
396405
app.use(middleware());
406+
app.use(morgan("[:date[iso]] :url :method :body", { immediate: true }));
407+
app.use(morgan("[:date[iso]] :url :method :status :response-time ms - :res[content-length] :res-body"));
397408

398409
app.get("/test/ping", async (req, res, next) => {
399410
res.json({ ok: true });

0 commit comments

Comments
 (0)