Skip to content

Commit

Permalink
fix: revert optimization that made emailVerifyGET only update the cla…
Browse files Browse the repository at this point in the history
…im if the value changes
  • Loading branch information
porcellus committed Oct 16, 2023
1 parent b93b469 commit 244bfa5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 50 deletions.
8 changes: 1 addition & 7 deletions lib/build/recipe/emailverification/api/implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,7 @@ function getAPIInterface() {
newSession,
};
} else {
if ((await session.getClaimValue(emailVerificationClaim_1.EmailVerificationClaim)) !== false) {
await session.setClaimValue(
emailVerificationClaim_1.EmailVerificationClaim,
false,
userContext
);
}
await session.setClaimValue(emailVerificationClaim_1.EmailVerificationClaim, false, userContext);
return {
status: "OK",
isVerified: false,
Expand Down
39 changes: 16 additions & 23 deletions lib/build/recipe/emailverification/recipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,30 +187,23 @@ class Recipe extends recipeModule_1.default {
// We also have the sub cases here that the account that just
// got verified was already linked to the session's primary user ID,
// but either way, we don't need to change any user ID.
// In this case, all we do is to update the emailverification claim if it's
// not already set to true (it is ok to assume true cause this function
// is only called when the email is verified).
if (
(await input.session.getClaimValue(emailVerificationClaim_1.EmailVerificationClaim)) !==
true
) {
try {
// EmailVerificationClaim will be based on the recipeUserId
// and not the primary user ID.
await input.session.fetchAndSetClaim(
emailVerificationClaim_1.EmailVerificationClaim,
input.userContext
);
} catch (err) {
// This should never happen, since we've just set the status above.
if (err.message === "UNKNOWN_USER_ID") {
throw new error_2.default({
type: error_2.default.UNAUTHORISED,
message: "Unknown User ID provided",
});
}
throw err;
// In this case, all we do is to update the emailverification claim
try {
// EmailVerificationClaim will be based on the recipeUserId
// and not the primary user ID.
await input.session.fetchAndSetClaim(
emailVerificationClaim_1.EmailVerificationClaim,
input.userContext
);
} catch (err) {
// This should never happen, since we've just set the status above.
if (err.message === "UNKNOWN_USER_ID") {
throw new error_2.default({
type: error_2.default.UNAUTHORISED,
message: "Unknown User ID provided",
});
}
throw err;
}
return;
} else {
Expand Down
4 changes: 1 addition & 3 deletions lib/ts/recipe/emailverification/api/implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ export default function getAPIInterface(): APIInterface {
newSession,
};
} else {
if ((await session.getClaimValue(EmailVerificationClaim)) !== false) {
await session.setClaimValue(EmailVerificationClaim, false, userContext);
}
await session.setClaimValue(EmailVerificationClaim, false, userContext);

return {
status: "OK",
Expand Down
30 changes: 13 additions & 17 deletions lib/ts/recipe/emailverification/recipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,24 +304,20 @@ export default class Recipe extends RecipeModule {
// got verified was already linked to the session's primary user ID,
// but either way, we don't need to change any user ID.

// In this case, all we do is to update the emailverification claim if it's
// not already set to true (it is ok to assume true cause this function
// is only called when the email is verified).
if ((await input.session.getClaimValue(EmailVerificationClaim)) !== true) {
try {
// EmailVerificationClaim will be based on the recipeUserId
// and not the primary user ID.
await input.session.fetchAndSetClaim(EmailVerificationClaim, input.userContext);
} catch (err) {
// This should never happen, since we've just set the status above.
if ((err as Error).message === "UNKNOWN_USER_ID") {
throw new SessionError({
type: SessionError.UNAUTHORISED,
message: "Unknown User ID provided",
});
}
throw err;
// In this case, all we do is to update the emailverification claim
try {
// EmailVerificationClaim will be based on the recipeUserId
// and not the primary user ID.
await input.session.fetchAndSetClaim(EmailVerificationClaim, input.userContext);
} catch (err) {
// This should never happen, since we've just set the status above.
if ((err as Error).message === "UNKNOWN_USER_ID") {
throw new SessionError({
type: SessionError.UNAUTHORISED,
message: "Unknown User ID provided",
});
}
throw err;
}

return;
Expand Down

0 comments on commit 244bfa5

Please sign in to comment.