-
Notifications
You must be signed in to change notification settings - Fork 630
fix: Isolation level and reservation table #1201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
4fa7b07
04805a3
30e06e2
201a2ec
6302155
504092e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "_comment": "Contains list of implementation dependencies URL for this project. This is a generated file, don't modify the contents by hand.", | ||
| "list": [ | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| { | ||
| "_comment": "Contains list of implementation dependencies URL for this project. This is a generated file, don't modify the contents by hand.", | ||
| "list": [ | ||
| { | ||
| "jar":"https://repo.maven.apache.org/maven2/com/google/code/gson/gson/2.13.1/gson-2.13.1.jar", | ||
| "name":"gson 2.13.1", | ||
| "src":"https://repo.maven.apache.org/maven2/com/google/code/gson/gson/2.13.1/gson-2.13.1-sources.jar" | ||
| }, | ||
| { | ||
| "jar":"https://repo.maven.apache.org/maven2/com/google/errorprone/error_prone_annotations/2.38.0/error_prone_annotations-2.38.0.jar", | ||
| "name":"error_prone_annotations 2.38.0", | ||
| "src":"https://repo.maven.apache.org/maven2/com/google/errorprone/error_prone_annotations/2.38.0/error_prone_annotations-2.38.0-sources.jar" | ||
| }, | ||
| { | ||
| "jar":"https://repo.maven.apache.org/maven2/org/jetbrains/annotations/13.0/annotations-13.0.jar", | ||
| "name":"annotations 13.0", | ||
| "src":"https://repo.maven.apache.org/maven2/org/jetbrains/annotations/13.0/annotations-13.0-sources.jar" | ||
| }, | ||
| { | ||
| "jar":"https://repo.maven.apache.org/maven2/com/auth0/java-jwt/4.0.0/java-jwt-4.0.0.jar", | ||
| "name":"java-jwt 4.0.0", | ||
| "src":"https://repo.maven.apache.org/maven2/com/auth0/java-jwt/4.0.0/java-jwt-4.0.0-sources.jar" | ||
| } | ||
| ] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ | |
| import io.supertokens.pluginInterface.StorageUtils; | ||
| import io.supertokens.pluginInterface.authRecipe.AuthRecipeUserInfo; | ||
| import io.supertokens.pluginInterface.authRecipe.LoginMethod; | ||
| import io.supertokens.pluginInterface.authRecipe.exceptions.AccountInfoAlreadyAssociatedWithAnotherPrimaryUserIdException; | ||
| import io.supertokens.pluginInterface.authRecipe.sqlStorage.AuthRecipeSQLStorage; | ||
| import io.supertokens.pluginInterface.bulkimport.BulkImportUser; | ||
| import io.supertokens.pluginInterface.bulkimport.exceptions.BulkImportBatchInsertException; | ||
|
|
@@ -286,12 +287,34 @@ private static CanLinkAccountsResult canLinkAccountsHelper(TransactionConnection | |
| tenantIds.addAll(recipeUser.tenantIds); | ||
| tenantIds.addAll(primaryUser.tenantIds); | ||
|
|
||
| checkIfLoginMethodCanBeLinkedOnTenant(con, appIdentifier, authRecipeStorage, tenantIds, recipeUser.loginMethods[0], primaryUser); | ||
| Set<String> emails = new HashSet<>(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we have a for update lock on both the primary and recipe user at this point, right? |
||
| Set<String> phoneNumbers = new HashSet<>(); | ||
| Set<LoginMethod.ThirdParty> thirdParties = new HashSet<>(); | ||
|
|
||
| for (LoginMethod currLoginMethod : primaryUser.loginMethods) { | ||
| checkIfLoginMethodCanBeLinkedOnTenant(con, appIdentifier, authRecipeStorage, tenantIds, currLoginMethod, primaryUser); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we remove the util function we used to use? |
||
| for (var lm : primaryUser.loginMethods) { | ||
| if (lm.email != null) { | ||
| emails.add(lm.email); | ||
| } | ||
| if (lm.phoneNumber != null) { | ||
| phoneNumbers.add(lm.phoneNumber); | ||
| } | ||
| if (lm.thirdParty != null) { | ||
| thirdParties.add(lm.thirdParty); | ||
| } | ||
| } | ||
| for (var lm : recipeUser.loginMethods) { | ||
| if (lm.email != null) { | ||
| emails.add(lm.email); | ||
| } | ||
| if (lm.phoneNumber != null) { | ||
| phoneNumbers.add(lm.phoneNumber); | ||
| } | ||
| if (lm.thirdParty != null) { | ||
| thirdParties.add(lm.thirdParty); | ||
| } | ||
| } | ||
|
|
||
| authRecipeStorage.checkIfLoginMethodsCanBeLinked_Transaction(con, appIdentifier, tenantIds, emails, phoneNumbers, thirdParties, primaryUser.getSupertokensUserId()); | ||
| return new CanLinkAccountsResult(recipeUser.getSupertokensUserId(), primaryUser.getSupertokensUserId(), false); | ||
| } | ||
|
|
||
|
|
@@ -707,61 +730,8 @@ private static CreatePrimaryUserResult canCreatePrimaryUserHelper(TransactionCon | |
| // this means that the user has only one login method since it's not a primary user | ||
| // nor is it linked to a primary user | ||
| assert (targetUser.loginMethods.length == 1); | ||
| LoginMethod loginMethod = targetUser.loginMethods[0]; | ||
|
|
||
| for (String tenantId : targetUser.tenantIds) { | ||
| if (loginMethod.email != null) { | ||
| AuthRecipeUserInfo[] usersWithSameEmail = authRecipeStorage | ||
| .listPrimaryUsersByEmail_Transaction(appIdentifier, con, | ||
| loginMethod.email); | ||
| for (AuthRecipeUserInfo user : usersWithSameEmail) { | ||
| if (!user.tenantIds.contains(tenantId)) { | ||
| continue; | ||
| } | ||
| if (user.isPrimaryUser) { | ||
| throw new AccountInfoAlreadyAssociatedWithAnotherPrimaryUserIdException( | ||
| user.getSupertokensUserId(), | ||
| "This user's email is already associated with another user ID"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (loginMethod.phoneNumber != null) { | ||
| AuthRecipeUserInfo[] usersWithSamePhoneNumber = authRecipeStorage | ||
| .listPrimaryUsersByPhoneNumber_Transaction(appIdentifier, con, | ||
| loginMethod.phoneNumber); | ||
| for (AuthRecipeUserInfo user : usersWithSamePhoneNumber) { | ||
| if (!user.tenantIds.contains(tenantId)) { | ||
| continue; | ||
| } | ||
| if (user.isPrimaryUser) { | ||
| throw new AccountInfoAlreadyAssociatedWithAnotherPrimaryUserIdException( | ||
| user.getSupertokensUserId(), | ||
| "This user's phone number is already associated with another user" + | ||
| " ID"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (loginMethod.thirdParty != null) { | ||
| AuthRecipeUserInfo[] usersWithSameThirdParty = authRecipeStorage | ||
| .listPrimaryUsersByThirdPartyInfo_Transaction(appIdentifier, con, | ||
| loginMethod.thirdParty.id, loginMethod.thirdParty.userId); | ||
| for (AuthRecipeUserInfo userWithSameThirdParty : usersWithSameThirdParty) { | ||
| if (!userWithSameThirdParty.tenantIds.contains(tenantId)) { | ||
| continue; | ||
| } | ||
| if (userWithSameThirdParty.isPrimaryUser) { | ||
| throw new AccountInfoAlreadyAssociatedWithAnotherPrimaryUserIdException( | ||
| userWithSameThirdParty.getSupertokensUserId(), | ||
| "This user's third party login is already associated with another" + | ||
| " user ID"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| authRecipeStorage.checkIfLoginMethodCanBecomePrimary_Transaction(appIdentifier, con, targetUser.loginMethods[0]); | ||
|
|
||
| return new CreatePrimaryUserResult(targetUser, false); | ||
| } | ||
|
|
@@ -945,7 +915,7 @@ public static CreatePrimaryUserResult createPrimaryUser(Main main, | |
| return authRecipeStorage.startTransaction(con -> { | ||
|
|
||
| try { | ||
| CreatePrimaryUserResult result = canCreatePrimaryUserHelper(con, appIdentifier, authRecipeStorage, | ||
| CreatePrimaryUserResult result = canCreatePrimaryUserHelper(con, appIdentifier, authRecipeStorage, | ||
| recipeUserId); | ||
| if (result.wasAlreadyAPrimaryUser) { | ||
| return result; | ||
|
|
@@ -1447,6 +1417,8 @@ private static void deleteAuthRecipeUser(TransactionConnection con, | |
| .deleteThirdPartyUser_Transaction(con, appIdentifier, userId, deleteFromUserIdToAppIdTableToo); | ||
| StorageUtils.getPasswordlessStorage(storage) | ||
| .deletePasswordlessUser_Transaction(con, appIdentifier, userId, deleteFromUserIdToAppIdTableToo); | ||
| StorageUtils.getAuthRecipeStorage(storage) | ||
| .deleteAccountInfoReservations_Transaction(con, appIdentifier, userId); | ||
| } | ||
|
|
||
| public static boolean deleteNonAuthRecipeUser(TenantIdentifier tenantIdentifier, Storage storage, String userId) | ||
|
|
||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these being added now?