Skip to content

Commit

Permalink
feat: get user by account info - webauthn support
Browse files Browse the repository at this point in the history
  • Loading branch information
tamassoltesz committed Jan 29, 2025
1 parent 8c3fc92 commit 599ff94
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,8 @@ private static List<AuthRecipeUserInfo> getPrimaryUserInfoForUserIds_Transaction
loginMethods.addAll(
PasswordlessQueries.getUsersInfoUsingIdList_Transaction(start, sqlCon, recipeUserIdsToFetch,
appIdentifier));
loginMethods.addAll(WebAuthNQueries.getUsersInfoUsingIdList_Transaction(start, sqlCon, recipeUserIdsToFetch,
appIdentifier));

Map<String, LoginMethod> recipeUserIdToLoginMethodMap = new HashMap<>();
for (LoginMethod loginMethod : loginMethods) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,13 @@ public static AuthRecipeUserInfo signUp_Transaction(Start start, Connection sqlC
});

sqlCon.commit();
Collection<? extends LoginMethod> loginMethods = getUsersInfoUsingIdList(start, Collections.singleton(userId), tenantIdentifier.toAppIdentifier());
if(!loginMethods.isEmpty()) { //expecting it to be size 1
for(LoginMethod loginMethod: loginMethods){
return AuthRecipeUserInfo.create(userId, false, loginMethod);
}
}

// TODO return AuthRecipeUserInfo.create(userId, false, );
return null;
} catch (SQLException throwables) {
throw new StorageTransactionLogicException(throwables);
Expand Down Expand Up @@ -293,6 +298,22 @@ public static String getPrimaryUserIdUsingEmail(Start start, TenantIdentifier te

public static Collection<? extends LoginMethod> getUsersInfoUsingIdList(Start start, Set<String> ids, AppIdentifier appIdentifier)
throws SQLException, StorageQueryException {
try {
return start.startTransaction(con -> {
Connection sqlConnection = (Connection) con.getConnection();
try {
return getUsersInfoUsingIdList_Transaction(start, sqlConnection, ids, appIdentifier);
} catch (SQLException e) {
throw new StorageQueryException(e);
}
});
} catch (StorageTransactionLogicException e) {
throw new StorageQueryException(e);
}
}

public static Collection<? extends LoginMethod> getUsersInfoUsingIdList_Transaction(Start start, Connection connection, Set<String> ids, AppIdentifier appIdentifier)
throws SQLException, StorageQueryException {
if (ids.size() > 0) {

String webauthnUsersTable = getConfig(start).getWebAuthNUsersTable();
Expand All @@ -308,10 +329,10 @@ public static Collection<? extends LoginMethod> getUsersInfoUsingIdList(Start st
"JOIN " + credentialTable + " as credentials ON webauthn.user_id = credentials.user_id " +
"JOIN " + usersTable + " as all_users ON webauthn.app_id = all_users.app_id AND webauthn.user_id = all_users.user_id " +
"JOIN " + userIdMappingTable + " as user_id_mapping ON webauthn.user_id = user_id_mapping.supertokens_user_id " +
"JOIN " + emailVerificationTable + " as email_verification ON webauthn.app_id = email_verification.app_id AND user_id_mapping.external_user_id = email_verification.user_id " +
"JOIN " + emailVerificationTable + " as email_verification ON webauthn.app_id = email_verification.app_id AND user_id_mapping.external_user_id = email_verification.user_id OR user_id_mapping.supertokens_user_id = email_verification.user_id" +
"WHERE webauthn.app_id = ? AND webauthn.user_id IN (" + Utils.generateCommaSeperatedQuestionMarks(ids.size()) + ")";

return execute(start, queryAll, pst -> {
return execute(connection, queryAll, pst -> {
pst.setString(1, appIdentifier.getAppId());
int index = 2;
for (String id : ids) {
Expand Down

0 comments on commit 599ff94

Please sign in to comment.