From 9eb76a1f011e1e247768b1a0d46c7afb6f6981fb Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Fri, 1 Mar 2024 15:49:13 +0530 Subject: [PATCH] fix: user metadata --- .../usermetadata/RemoveUserMetadataAPI.java | 13 +++++--- .../api/usermetadata/UserMetadataAPI.java | 30 ++++++++++--------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/main/java/io/supertokens/webserver/api/usermetadata/RemoveUserMetadataAPI.java b/src/main/java/io/supertokens/webserver/api/usermetadata/RemoveUserMetadataAPI.java index 4ef1bc926..8e6a91a24 100644 --- a/src/main/java/io/supertokens/webserver/api/usermetadata/RemoveUserMetadataAPI.java +++ b/src/main/java/io/supertokens/webserver/api/usermetadata/RemoveUserMetadataAPI.java @@ -19,8 +19,11 @@ import com.google.gson.JsonObject; import io.supertokens.AppIdentifierWithStorageAndUserIdMapping; import io.supertokens.Main; +import io.supertokens.StorageAndUserIdMapping; import io.supertokens.multitenancy.exception.BadPermissionException; +import io.supertokens.pluginInterface.Storage; import io.supertokens.pluginInterface.emailpassword.exceptions.UnknownUserIdException; +import io.supertokens.pluginInterface.multitenancy.AppIdentifier; import io.supertokens.pluginInterface.multitenancy.AppIdentifierWithStorage; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.pluginInterface.RECIPE_ID; @@ -52,15 +55,17 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I // API is app specific JsonObject input = InputParser.parseJsonObjectOrThrowError(req); String userId = InputParser.parseStringOrThrowError(input, "userId", false); + + AppIdentifier appIdentifier = getAppIdentifier(req); try { try { - AppIdentifierWithStorageAndUserIdMapping appIdStorageAndMapping = + StorageAndUserIdMapping storageAndUserIdMapping = this.getStorageAndUserIdMappingForAppSpecificApi( req, userId, UserIdType.ANY); - UserMetadata.deleteUserMetadata(appIdStorageAndMapping.appIdentifierWithStorage, userId); + UserMetadata.deleteUserMetadata(appIdentifier, storageAndUserIdMapping.storage, userId); } catch (UnknownUserIdException e) { - AppIdentifierWithStorage appIdentifierWithStorage = this.enforcePublicTenantAndGetPublicTenantStorage(req); - UserMetadata.deleteUserMetadata(appIdentifierWithStorage, userId); + Storage storage = this.enforcePublicTenantAndGetPublicTenantStorage(req); + UserMetadata.deleteUserMetadata(appIdentifier, storage, userId); } JsonObject response = new JsonObject(); diff --git a/src/main/java/io/supertokens/webserver/api/usermetadata/UserMetadataAPI.java b/src/main/java/io/supertokens/webserver/api/usermetadata/UserMetadataAPI.java index 022e41f07..4444d0551 100644 --- a/src/main/java/io/supertokens/webserver/api/usermetadata/UserMetadataAPI.java +++ b/src/main/java/io/supertokens/webserver/api/usermetadata/UserMetadataAPI.java @@ -17,11 +17,12 @@ package io.supertokens.webserver.api.usermetadata; import com.google.gson.JsonObject; -import io.supertokens.AppIdentifierWithStorageAndUserIdMapping; import io.supertokens.Main; +import io.supertokens.StorageAndUserIdMapping; import io.supertokens.multitenancy.exception.BadPermissionException; +import io.supertokens.pluginInterface.Storage; import io.supertokens.pluginInterface.emailpassword.exceptions.UnknownUserIdException; -import io.supertokens.pluginInterface.multitenancy.AppIdentifierWithStorage; +import io.supertokens.pluginInterface.multitenancy.AppIdentifier; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.pluginInterface.RECIPE_ID; import io.supertokens.pluginInterface.exceptions.StorageQueryException; @@ -52,16 +53,16 @@ public String getPath() { protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { // API is app specific String userId = InputParser.getQueryParamOrThrowError(req, "userId", false); + AppIdentifier appIdentifier = getAppIdentifier(req); try { JsonObject metadata; try { - AppIdentifierWithStorageAndUserIdMapping appIdStorageAndMapping = - this.getStorageAndUserIdMappingForAppSpecificApi( - req, userId, UserIdType.ANY); - metadata = UserMetadata.getUserMetadata(appIdStorageAndMapping.appIdentifierWithStorage, userId); + StorageAndUserIdMapping storageAndUserIdMapping = this.getStorageAndUserIdMappingForAppSpecificApi( + req, userId, UserIdType.ANY); + metadata = UserMetadata.getUserMetadata(appIdentifier, storageAndUserIdMapping.storage, userId); } catch (UnknownUserIdException e) { - AppIdentifierWithStorage appIdentifierWithStorage = this.enforcePublicTenantAndGetPublicTenantStorage(req); - metadata = UserMetadata.getUserMetadata(appIdentifierWithStorage, userId); + Storage storage = this.enforcePublicTenantAndGetPublicTenantStorage(req); + metadata = UserMetadata.getUserMetadata(appIdentifier, storage, userId); } JsonObject response = new JsonObject(); @@ -79,18 +80,19 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO JsonObject input = InputParser.parseJsonObjectOrThrowError(req); String userId = InputParser.parseStringOrThrowError(input, "userId", false); JsonObject update = InputParser.parseJsonObjectOrThrowError(input, "metadataUpdate", false); + + AppIdentifier appIdentifier = getAppIdentifier(req); try { JsonObject metadata; try { - AppIdentifierWithStorageAndUserIdMapping appIdStorageAndMapping = - this.getStorageAndUserIdMappingForAppSpecificApi( - req, userId, UserIdType.ANY); - metadata = UserMetadata.updateUserMetadata(appIdStorageAndMapping.appIdentifierWithStorage, userId, + StorageAndUserIdMapping storageAndUserIdMapping = this.getStorageAndUserIdMappingForAppSpecificApi( + req, userId, UserIdType.ANY); + metadata = UserMetadata.updateUserMetadata(appIdentifier, storageAndUserIdMapping.storage, userId, update); } catch (UnknownUserIdException e) { - AppIdentifierWithStorage appIdentifierWithStorage = this.enforcePublicTenantAndGetPublicTenantStorage(req); - metadata = UserMetadata.updateUserMetadata(appIdentifierWithStorage, userId, update); + Storage storage = this.enforcePublicTenantAndGetPublicTenantStorage(req); + metadata = UserMetadata.updateUserMetadata(appIdentifier, storage, userId, update); } JsonObject response = new JsonObject();