@@ -4,7 +4,13 @@ import * as supertokens from "../../../lib/build";
44import SessionRecipe from "../../../lib/build/recipe/session/recipe" ;
55import { logger } from "./logger" ;
66import { getFunc } from "./testFunctionMapper" ;
7- import { convertRequestSessionToSessionObject , deserializeClaim , deserializeValidator , maxVersion } from "./utils" ;
7+ import {
8+ convertRequestSessionToSessionObject ,
9+ deserializeClaim ,
10+ deserializeValidator ,
11+ maxVersion ,
12+ serializeResponseSession ,
13+ } from "./utils" ;
814import { logOverrideEvent } from "./overrideLogging" ;
915
1016const namespace = "com.supertokens:node-test-server:session" ;
@@ -34,7 +40,8 @@ const router = Router()
3440 req . body . disableAntiCsrf ,
3541 req . body . userContext
3642 ) ;
37- res . json ( response ) ;
43+
44+ res . json ( serializeResponseSession ( response ) ) ;
3845 } catch ( e ) {
3946 next ( e ) ;
4047 }
@@ -48,7 +55,7 @@ const router = Router()
4855 req . body . options ,
4956 req . body . userContext
5057 ) ;
51- res . json ( response ) ;
58+ res . json ( serializeResponseSession ( response ) ) ;
5259 } catch ( e ) {
5360 next ( e ) ;
5461 }
@@ -85,8 +92,9 @@ const router = Router()
8592 req . body . antiCsrfToken ,
8693 req . body . userContext
8794 ) ;
88- res . json ( response ) ;
95+ res . json ( serializeResponseSession ( response ) ) ;
8996 } catch ( e ) {
97+ console . error ( e ) ;
9098 // we do not call next(e) here so that the proper error response is sent back to the client
9199 // otherwise the supertokens error handler will send a different type of response.
92100 res . status ( 500 ) . json ( { ...e , message : e . message } ) ;
@@ -166,7 +174,7 @@ const router = Router()
166174 throw new Error ( "This should never happen: failed to deserialize session" ) ;
167175 }
168176 const retVal = await session . revokeSession ( req . body . userContext ) ; // : Promise<void>;
169- res . json ( { retVal, updatedSession : { ... session } } ) ;
177+ res . json ( { retVal, updatedSession : serializeResponseSession ( session ) } ) ;
170178
171179 logOverrideEvent ( "sessionobject.revokesession" , "RES" , retVal ) ;
172180 } catch ( e ) {
@@ -183,7 +191,7 @@ const router = Router()
183191 throw new Error ( "This should never happen: failed to deserialize session" ) ;
184192 }
185193 const retVal = await session . getSessionDataFromDatabase ( req . body . userContext ) ; // : Promise<any>;
186- res . json ( { retVal, updatedSession : { ... session } } ) ;
194+ res . json ( { retVal, updatedSession : serializeResponseSession ( session ) } ) ;
187195
188196 logOverrideEvent ( "sessionobject.getsessiondatafromdatabase" , "RES" , retVal ) ;
189197 } catch ( e ) {
@@ -200,7 +208,7 @@ const router = Router()
200208 throw new Error ( "This should never happen: failed to deserialize session" ) ;
201209 }
202210 const retVal = await session . updateSessionDataInDatabase ( req . body . newSessionData , req . body . userContext ) ; // : Promise<any>;
203- res . json ( { retVal, updatedSession : { ... session } } ) ;
211+ res . json ( { retVal, updatedSession : serializeResponseSession ( session ) } ) ;
204212
205213 logOverrideEvent ( "sessionobject.updatesessiondataindatabase" , "RES" , retVal ) ;
206214 } catch ( e ) {
@@ -217,7 +225,7 @@ const router = Router()
217225 throw new Error ( "This should never happen: failed to deserialize session" ) ;
218226 }
219227 const retVal = await session . getUserId ( req . body . userContext ) ; // : string;
220- res . json ( { retVal, updatedSession : { ... session } } ) ;
228+ res . json ( { retVal, updatedSession : serializeResponseSession ( session ) } ) ;
221229
222230 logOverrideEvent ( "sessionobject.getuserid" , "RES" , retVal ) ;
223231 } catch ( e ) {
@@ -234,7 +242,7 @@ const router = Router()
234242 throw new Error ( "This should never happen: failed to deserialize session" ) ;
235243 }
236244 const retVal = await session . getRecipeUserId ( req . body . userContext ) ; // : RecipeUserId;
237- res . json ( { retVal, updatedSession : { ... session } } ) ;
245+ res . json ( { retVal, updatedSession : serializeResponseSession ( session ) } ) ;
238246
239247 logOverrideEvent ( "sessionobject.getrecipeuserid" , "RES" , retVal ) ;
240248 } catch ( e ) {
@@ -251,7 +259,7 @@ const router = Router()
251259 throw new Error ( "This should never happen: failed to deserialize session" ) ;
252260 }
253261 const retVal = await session . getTenantId ( req . body . userContext ) ; // : string;
254- res . json ( { retVal, updatedSession : { ... session } } ) ;
262+ res . json ( { retVal, updatedSession : serializeResponseSession ( session ) } ) ;
255263
256264 logOverrideEvent ( "sessionobject.gettenantid" , "RES" , retVal ) ;
257265 } catch ( e ) {
@@ -268,7 +276,7 @@ const router = Router()
268276 throw new Error ( "This should never happen: failed to deserialize session" ) ;
269277 }
270278 const retVal = await session . getAccessTokenPayload ( req . body . userContext ) ; // : any;
271- res . json ( { retVal, updatedSession : { ... session } } ) ;
279+ res . json ( { retVal, updatedSession : serializeResponseSession ( session ) } ) ;
272280
273281 logOverrideEvent ( "sessionobject.getaccesstokenpayload" , "RES" , retVal ) ;
274282 } catch ( e ) {
@@ -285,7 +293,7 @@ const router = Router()
285293 throw new Error ( "This should never happen: failed to deserialize session" ) ;
286294 }
287295 const retVal = await session . getHandle ( req . body . userContext ) ; // : string;
288- res . json ( { retVal, updatedSession : { ... session } } ) ;
296+ res . json ( { retVal, updatedSession : serializeResponseSession ( session ) } ) ;
289297
290298 logOverrideEvent ( "sessionobject.gethandle" , "RES" , retVal ) ;
291299 } catch ( e ) {
@@ -302,7 +310,7 @@ const router = Router()
302310 throw new Error ( "This should never happen: failed to deserialize session" ) ;
303311 }
304312 const retVal = await session . getAllSessionTokensDangerously ( ) ; // : Promise<{}>;
305- res . json ( { retVal, updatedSession : { ... session } } ) ;
313+ res . json ( { retVal, updatedSession : serializeResponseSession ( session ) } ) ;
306314
307315 logOverrideEvent ( "sessionobject.getallsessiontokensdangerously" , "RES" , retVal ) ;
308316 } catch ( e ) {
@@ -319,7 +327,7 @@ const router = Router()
319327 throw new Error ( "This should never happen: failed to deserialize session" ) ;
320328 }
321329 const retVal = await session . getAccessToken ( req . body . userContext ) ; // : string;
322- res . json ( { retVal, updatedSession : { ... session } } ) ;
330+ res . json ( { retVal, updatedSession : serializeResponseSession ( session ) } ) ;
323331
324332 logOverrideEvent ( "sessionobject.getaccesstoken" , "RES" , retVal ) ;
325333 } catch ( e ) {
@@ -339,7 +347,7 @@ const router = Router()
339347 req . body . accessTokenPayloadUpdate ,
340348 req . body . userContext
341349 ) ; // : Promise<void>;
342- res . json ( { retVal, updatedSession : { ... session } } ) ;
350+ res . json ( { retVal, updatedSession : serializeResponseSession ( session ) } ) ;
343351
344352 logOverrideEvent ( "sessionobject.mergeintoaccesstokenpayload" , "RES" , retVal ) ;
345353 } catch ( e ) {
@@ -356,7 +364,7 @@ const router = Router()
356364 throw new Error ( "This should never happen: failed to deserialize session" ) ;
357365 }
358366 const retVal = await session . getTimeCreated ( req . body . userContext ) ; // : Promise<number>;
359- res . json ( { retVal, updatedSession : { ... session } } ) ;
367+ res . json ( { retVal, updatedSession : serializeResponseSession ( session ) } ) ;
360368
361369 logOverrideEvent ( "sessionobject.gettimecreated" , "RES" , retVal ) ;
362370 } catch ( e ) {
@@ -373,7 +381,7 @@ const router = Router()
373381 throw new Error ( "This should never happen: failed to deserialize session" ) ;
374382 }
375383 const retVal = await session . getExpiry ( req . body . userContext ) ; // : Promise<number>;
376- res . json ( { retVal, updatedSession : { ... session } } ) ;
384+ res . json ( { retVal, updatedSession : serializeResponseSession ( session ) } ) ;
377385
378386 logOverrideEvent ( "sessionobject.getexpiry" , "RES" , retVal ) ;
379387 } catch ( e ) {
@@ -393,7 +401,7 @@ const router = Router()
393401 req . body . claimValidators . map ( deserializeValidator ) ,
394402 req . body . userContext
395403 ) ; // : Promise<void>;
396- res . json ( { retVal, updatedSession : { ... session } } ) ;
404+ res . json ( { retVal, updatedSession : serializeResponseSession ( session ) } ) ;
397405
398406 logOverrideEvent ( "sessionobject.assertclaims" , "RES" , retVal ) ;
399407 } catch ( e ) {
@@ -411,7 +419,7 @@ const router = Router()
411419 }
412420
413421 const retVal = await session . fetchAndSetClaim ( deserializeClaim ( req . body . claim ) , req . body . userContext ) ; // : Promise<void>;
414- res . json ( { retVal, updatedSession : { ... session } } ) ;
422+ res . json ( { retVal, updatedSession : serializeResponseSession ( session ) } ) ;
415423
416424 logOverrideEvent ( "sessionobject.fetchandsetclaim" , "RES" , retVal ) ;
417425 } catch ( e ) {
@@ -432,7 +440,7 @@ const router = Router()
432440 req . body . value ,
433441 req . body . userContext
434442 ) ; // : Promise<void>;
435- res . json ( { retVal, updatedSession : { ... session } } ) ;
443+ res . json ( { retVal, updatedSession : serializeResponseSession ( session ) } ) ;
436444
437445 logOverrideEvent ( "sessionobject.setclaimvalue" , "RES" , retVal ) ;
438446 } catch ( e ) {
@@ -449,7 +457,7 @@ const router = Router()
449457 throw new Error ( "This should never happen: failed to deserialize session" ) ;
450458 }
451459 await session . removeClaim ( deserializeClaim ( req . body . claim ) , req . body . userContext ) ; // : Promise<void>;
452- res . json ( { updatedSession : { ... session } } ) ;
460+ res . json ( { updatedSession : serializeResponseSession ( session ) } ) ;
453461
454462 logOverrideEvent ( "sessionobject.removeClaim" , "RES" , undefined ) ;
455463 } catch ( e ) {
@@ -466,7 +474,7 @@ const router = Router()
466474 throw new Error ( "This should never happen: failed to deserialize session" ) ;
467475 }
468476 const retVal = await session . getClaimValue ( deserializeClaim ( req . body . claim ) , req . body . userContext ) ; // : Promise<void>;
469- res . json ( { retVal, updatedSession : { ... session } } ) ;
477+ res . json ( { retVal, updatedSession : serializeResponseSession ( session ) } ) ;
470478
471479 logOverrideEvent ( "sessionobject.getclaimvalue" , "RES" , retVal ) ;
472480 } catch ( e ) {
0 commit comments