Skip to content
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

fix: user pagination changes #766

Merged
merged 2 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/io/supertokens/authRecipe/AuthRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static boolean unlinkAccounts(Main main, AppIdentifierWithStorage appIden
if (primaryUser.id.equals(recipeUserId)) {
// we are trying to unlink the user ID which is the same as the primary one.
if (primaryUser.loginMethods.length == 1) {
storage.unlinkAccounts_Transaction(appIdentifierWithStorage, con, recipeUserId);
storage.unlinkAccounts_Transaction(appIdentifierWithStorage, con, primaryUser.id, recipeUserId);
Session.revokeAllSessionsForUser(main, appIdentifierWithStorage,
mappingResult == null ? recipeUserId : mappingResult.externalUserId,
false);
Expand All @@ -109,7 +109,7 @@ public static boolean unlinkAccounts(Main main, AppIdentifierWithStorage appIden
return true;
}
} else {
storage.unlinkAccounts_Transaction(appIdentifierWithStorage, con, recipeUserId);
storage.unlinkAccounts_Transaction(appIdentifierWithStorage, con, primaryUser.id, recipeUserId);
Session.revokeAllSessionsForUser(main, appIdentifierWithStorage,
mappingResult == null ? recipeUserId : mappingResult.externalUserId, false);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,11 @@
import javax.annotation.Nullable;

public class UserPaginationContainer {
public final UsersContainer[] users;
public final AuthRecipeUserInfo[] users;
public final String nextPaginationToken;

public UserPaginationContainer(@Nonnull AuthRecipeUserInfo[] users, @Nullable String nextPaginationToken) {
this.users = new UsersContainer[users.length];
for (int i = 0; i < users.length; i++) {
this.users[i] = new UsersContainer(users[i]);
}
this.users = users;
this.nextPaginationToken = nextPaginationToken;
}

public static class UsersContainer {
public final AuthRecipeUserInfo user;
public final String recipeId;

public UsersContainer(AuthRecipeUserInfo user) {
this.user = user;
this.recipeId = user.getRecipeId().toString();
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/io/supertokens/inmemorydb/Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -2819,7 +2819,7 @@ public void linkAccounts_Transaction(AppIdentifier appIdentifier, TransactionCon
}

@Override
public void unlinkAccounts_Transaction(AppIdentifier appIdentifier, TransactionConnection con, String recipeUserId)
public void unlinkAccounts_Transaction(AppIdentifier appIdentifier, TransactionConnection con, String primaryUserId, String recipeUserId)
throws StorageQueryException {
// TODO:..
}
Expand Down
28 changes: 15 additions & 13 deletions src/main/java/io/supertokens/webserver/api/core/UsersAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.supertokens.authRecipe.UserPaginationToken;
import io.supertokens.output.Logging;
import io.supertokens.pluginInterface.RECIPE_ID;
import io.supertokens.pluginInterface.authRecipe.AuthRecipeUserInfo;
import io.supertokens.pluginInterface.dashboard.DashboardSearchTags;
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
import io.supertokens.pluginInterface.multitenancy.TenantIdentifierWithStorage;
Expand Down Expand Up @@ -169,31 +170,32 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO

ArrayList<String> userIds = new ArrayList<>();
for (int i = 0; i < users.users.length; i++) {
userIds.add(users.users[i].user.id);
userIds.add(users.users[i].id);
}
HashMap<String, String> userIdMapping = UserIdMapping.getUserIdMappingForSuperTokensUserIds(
tenantIdentifierWithStorage, userIds);
if (!userIdMapping.isEmpty()) {
for (int i = 0; i < users.users.length; i++) {
String externalId = userIdMapping.get(userIds.get(i));
if (externalId != null) {
users.users[i].user.setExternalUserId(externalId);
} else {
users.users[i].user.setExternalUserId(null);
}

for (int i = 0; i < users.users.length; i++) {
String externalId = userIdMapping.get(userIds.get(i));
if (externalId != null) {
users.users[i].setExternalUserId(externalId);
} else {
users.users[i].setExternalUserId(null);
}
}

JsonObject result = new JsonObject();
result.addProperty("status", "OK");

JsonArray usersJson = new JsonArray();
for (UserPaginationContainer.UsersContainer user : users.users) {
for (AuthRecipeUserInfo user : users.users) {
JsonObject jsonObj = new JsonObject();
jsonObj.addProperty("recipeId", user.recipeId);
if (getVersionFromRequest(req).lesserThan(SemVer.v4_0)) {
jsonObj.addProperty("recipeId", user.loginMethods[0].recipeId.toString());
}
JsonObject userJson =
getVersionFromRequest(req).greaterThanOrEqualTo(SemVer.v4_0) ? user.user.toJson() :
user.user.toJsonWithoutAccountLinking();
getVersionFromRequest(req).greaterThanOrEqualTo(SemVer.v4_0) ? user.toJson() :
user.toJsonWithoutAccountLinking();
jsonObj.add("user", userJson);
usersJson.add(jsonObj);
}
Expand Down
Loading
Loading