Skip to content

Commit

Permalink
fix: user metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Mar 1, 2024
1 parent 458c3b6 commit 9eb76a1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit 9eb76a1

Please sign in to comment.