Skip to content

Commit 9ef94fe

Browse files
authored
Merge pull request #255 from supertokens/fix/bulk_migration_webauthn_search
fix: bulk migration webauthn search
2 parents 4df7cfb + 8751cd2 commit 9ef94fe

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/main/java/io/supertokens/storage/postgresql/queries/GeneralQueries.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,6 +1587,9 @@ public static AuthRecipeUserInfo[] listPrimaryUsersByMultipleEmailsOrPhonesOrThi
15871587
//collect ids by thirdparty
15881588
userIds.addAll(ThirdPartyQueries.listUserIdsByMultipleThirdPartyInfo_Transaction(start, sqlCon, appIdentifier, thirdpartyUserIdToThirdpartyId));
15891589

1590+
//collect ids by webauthn
1591+
userIds.addAll(WebAuthNQueries.getPrimaryUserIdsUsingEmails_Transaction(start, sqlCon, appIdentifier, emails));
1592+
15901593
List<AuthRecipeUserInfo> result = getPrimaryUserInfoForUserIds_Transaction(start, sqlCon, appIdentifier,
15911594
new ArrayList<>(userIds));
15921595

src/main/java/io/supertokens/storage/postgresql/queries/WebAuthNQueries.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,33 @@ public static String getPrimaryUserIdUsingEmail_Transaction(Start start, Connect
427427
});
428428
}
429429

430+
public static List<String> getPrimaryUserIdsUsingEmails_Transaction(Start start, Connection sqlConnection,
431+
AppIdentifier appIdentifier, List<String> emails)
432+
throws SQLException, StorageQueryException {
433+
if(emails == null || emails.isEmpty()) {
434+
return new ArrayList<>();
435+
}
436+
String QUERY = "SELECT DISTINCT all_users.primary_or_recipe_user_id AS user_id "
437+
+ "FROM " + getConfig(start).getWebAuthNUserToTenantTable() + " AS ep" +
438+
" JOIN " + getConfig(start).getUsersTable() + " AS all_users" +
439+
" ON ep.app_id = all_users.app_id AND ep.user_id = all_users.user_id" +
440+
" WHERE ep.app_id = ? AND ep.email in (" + Utils.generateCommaSeperatedQuestionMarks(emails.size()) + ")";
441+
442+
return execute(sqlConnection, QUERY, pst -> {
443+
pst.setString(1, appIdentifier.getAppId());
444+
int i = 2;
445+
for(String email : emails) {
446+
pst.setString(i++, email);
447+
}
448+
}, result -> {
449+
List<String> idResult = new ArrayList<>();
450+
if (result.next()) {
451+
idResult.add(result.getString("user_id"));
452+
}
453+
return idResult;
454+
});
455+
}
456+
430457
public static Collection<? extends LoginMethod> getUsersInfoUsingIdList(Start start, Set<String> ids, AppIdentifier appIdentifier)
431458
throws StorageQueryException {
432459
try {

0 commit comments

Comments
 (0)