From 6036e596de33a7ef74b9468733f99f5a4247fb9e Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Thu, 14 Mar 2024 09:39:37 +0530 Subject: [PATCH] fix: session for mongo --- .../java/io/supertokens/session/Session.java | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/main/java/io/supertokens/session/Session.java b/src/main/java/io/supertokens/session/Session.java index bf307be1f..a75370195 100644 --- a/src/main/java/io/supertokens/session/Session.java +++ b/src/main/java/io/supertokens/session/Session.java @@ -140,29 +140,30 @@ public static SessionInformationHolder createNewSession(TenantIdentifier tenantI sessionHandle += "_" + tenantIdentifier.getTenantId(); } - io.supertokens.pluginInterface.useridmapping.UserIdMapping userIdMapping = UserIdMapping.getUserIdMapping( - tenantIdentifier.toAppIdentifier(), storage, recipeUserId, UserIdType.EXTERNAL); - if (userIdMapping != null) { - recipeUserId = userIdMapping.superTokensUserId; - } - String primaryUserId = recipeUserId; - if (storage.getType().equals(STORAGE_TYPE.SQL)) { + + if (storage.getType() == STORAGE_TYPE.SQL) { + io.supertokens.pluginInterface.useridmapping.UserIdMapping userIdMapping = UserIdMapping.getUserIdMapping( + tenantIdentifier.toAppIdentifier(), storage, recipeUserId, UserIdType.EXTERNAL); + if (userIdMapping != null) { + recipeUserId = userIdMapping.superTokensUserId; + } + primaryUserId = StorageUtils.getAuthRecipeStorage(storage) .getPrimaryUserIdStrForUserId(tenantIdentifier.toAppIdentifier(), recipeUserId); if (primaryUserId == null) { primaryUserId = recipeUserId; } - } - HashMap userIdMappings = UserIdMapping.getUserIdMappingForSuperTokensUserIds( - tenantIdentifier.toAppIdentifier(), storage, - new ArrayList<>(Arrays.asList(primaryUserId, recipeUserId))); - if (userIdMappings.containsKey(primaryUserId)) { - primaryUserId = userIdMappings.get(primaryUserId); - } - if (userIdMappings.containsKey(recipeUserId)) { - recipeUserId = userIdMappings.get(recipeUserId); + HashMap userIdMappings = UserIdMapping.getUserIdMappingForSuperTokensUserIds( + tenantIdentifier.toAppIdentifier(), storage, + new ArrayList<>(Arrays.asList(primaryUserId, recipeUserId))); + if (userIdMappings.containsKey(primaryUserId)) { + primaryUserId = userIdMappings.get(primaryUserId); + } + if (userIdMappings.containsKey(recipeUserId)) { + recipeUserId = userIdMappings.get(recipeUserId); + } } String antiCsrfToken = enableAntiCsrf ? UUID.randomUUID().toString() : null;