Skip to content

Commit

Permalink
fix: test server compatible with 1.17
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Jul 26, 2024
1 parent cbf5e02 commit b99c077
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
6 changes: 4 additions & 2 deletions test/test-server/src/emailpassword.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const { logDebugMessage } = logger(namespace);

const router = Router()
.post("/signup", async (req, res, next) => {
const fdiVersion: string = req.headers["fdi-version"] as string;

try {
logDebugMessage("EmailPassword:signup %j", req.body);
let session = req.body.session && (await convertRequestSessionToSessionObject(req.body.session));
Expand All @@ -21,8 +23,8 @@ const router = Router()
);
res.json({
...response,
...serializeUser(response),
...serializeRecipeUserId(response),
...serializeUser(response, fdiVersion),
...serializeRecipeUserId(response, fdiVersion),
});
} catch (e) {
next(e);
Expand Down
9 changes: 8 additions & 1 deletion test/test-server/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@ const { logDebugMessage } = logger(namespace);

const router = Router()
.post("/createnewsessionwithoutrequestresponse", async (req, res, next) => {
const fdiVersion = req.headers["fdi-version"] as string;

try {
logDebugMessage("Session.createNewSessionWithoutRequestResponse %j", req.body);
const recipeUserId = supertokens.convertToRecipeUserId(req.body.recipeUserId);
let recipeUserId;
if (["1.17", "2.0"].includes(fdiVersion)) {
recipeUserId = supertokens.convertToRecipeUserId(req.body.userId);
} else {
recipeUserId = supertokens.convertToRecipeUserId(req.body.recipeUserId);
}
const response = await Session.createNewSessionWithoutRequestResponse(
req.body.tenantId || "public",
recipeUserId,
Expand Down
21 changes: 19 additions & 2 deletions test/test-server/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,21 @@ export async function convertRequestSessionToSessionObject(
return tokens;
}

export function serializeUser(response) {
export function serializeUser(response, fdiVersion: string) {
if (["1.17", "2.0"].includes(fdiVersion)) {
return {
...("user" in response && response.user instanceof supertokens.User
? {
user: {
id: (response.user as supertokens.User).id,
email: (response.user as supertokens.User).emails[0],
timeJoined: (response.user as supertokens.User).timeJoined,
tenantIds: (response.user as supertokens.User).tenantIds,
},
}
: {}),
};
}
return {
...("user" in response && response.user instanceof supertokens.User
? {
Expand All @@ -147,7 +161,10 @@ export function serializeUser(response) {
};
}

export function serializeRecipeUserId(response) {
export function serializeRecipeUserId(response, fdiVersion: string) {
if (["1.17", "2.0"].includes(fdiVersion)) {
return {};
}
return {
...("recipeUserId" in response && response.recipeUserId instanceof supertokens.RecipeUserId
? {
Expand Down

0 comments on commit b99c077

Please sign in to comment.