From 18ca94ce85d9e630b593135385ee779bb6028b29 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Mon, 11 Sep 2023 18:27:37 +0530 Subject: [PATCH] fix: ep login issues --- .../emailpassword/EmailPassword.java | 4 ++-- .../test/accountlinking/MultitenantTest.java | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/supertokens/emailpassword/EmailPassword.java b/src/main/java/io/supertokens/emailpassword/EmailPassword.java index 940de4a33..0c7fb08a0 100644 --- a/src/main/java/io/supertokens/emailpassword/EmailPassword.java +++ b/src/main/java/io/supertokens/emailpassword/EmailPassword.java @@ -177,7 +177,7 @@ public static ImportUserResponse importUserWithPasswordHash(TenantIdentifierWith LoginMethod loginMethod = null; for (AuthRecipeUserInfo currUser : allUsers) { for (LoginMethod currLM : currUser.loginMethods) { - if (currLM.email.equals(email) && currLM.recipeId == RECIPE_ID.EMAIL_PASSWORD) { + if (currLM.email.equals(email) && currLM.recipeId == RECIPE_ID.EMAIL_PASSWORD && currLM.tenantIds.contains(tenantIdentifierWithStorage.getTenantId())) { userInfoToBeUpdated = currUser; loginMethod = currLM; break; @@ -246,7 +246,7 @@ public static AuthRecipeUserInfo signIn(TenantIdentifierWithStorage tenantIdenti LoginMethod lM = null; for (AuthRecipeUserInfo currUser : users) { for (LoginMethod currLM : currUser.loginMethods) { - if (currLM.recipeId == RECIPE_ID.EMAIL_PASSWORD && currLM.email.equals(email)) { + if (currLM.recipeId == RECIPE_ID.EMAIL_PASSWORD && currLM.email.equals(email) && currLM.tenantIds.contains(tenantIdentifierWithStorage.getTenantId())) { user = currUser; lM = currLM; } diff --git a/src/test/java/io/supertokens/test/accountlinking/MultitenantTest.java b/src/test/java/io/supertokens/test/accountlinking/MultitenantTest.java index 103cfee08..ed1494005 100644 --- a/src/test/java/io/supertokens/test/accountlinking/MultitenantTest.java +++ b/src/test/java/io/supertokens/test/accountlinking/MultitenantTest.java @@ -23,6 +23,7 @@ import io.supertokens.authRecipe.exception.AccountInfoAlreadyAssociatedWithAnotherPrimaryUserIdException; import io.supertokens.emailpassword.EmailPassword; import io.supertokens.emailpassword.exceptions.EmailChangeNotAllowedException; +import io.supertokens.emailpassword.exceptions.WrongCredentialsException; import io.supertokens.featureflag.EE_FEATURES; import io.supertokens.featureflag.FeatureFlagTestContent; import io.supertokens.featureflag.exceptions.FeatureNotEnabledException; @@ -256,6 +257,13 @@ public void testVariousCases() throws Exception { new AssociateUserToTenant(t2, 0), new MakePrimaryUser(t1, 0), }), + new TestCase(new TestCaseStep[]{ + new CreateEmailPasswordUser(t1, "test@example.com"), + new CreatePlessUserWithEmail(t2, "test@example.com"), + new MakePrimaryUser(t1, 0), + new LinkAccounts(t1, 0, 1), + new SignInEmailPasswordUser(t2, 0).expect(new WrongCredentialsException()) + }), new TestCase(new TestCaseStep[]{ new CreateEmailPasswordUser(t1, "test1@example.com"), @@ -830,4 +838,20 @@ public void execute(Main main) throws Exception { AuthRecipe.unlinkAccounts(main, tenantIdentifierWithStorage.toAppIdentifierWithStorage(), TestCase.users.get(userIndex).getSupertokensUserId()); } } + + private static class SignInEmailPasswordUser extends TestCaseStep { + TenantIdentifier tenantIdentifier; + int userIndex; + + public SignInEmailPasswordUser(TenantIdentifier tenantIdentifier, int userIndex) { + this.tenantIdentifier = tenantIdentifier; + this.userIndex = userIndex; + } + + @Override + public void execute(Main main) throws Exception { + TenantIdentifierWithStorage tenantIdentifierWithStorage = tenantIdentifier.withStorage(StorageLayer.getStorage(tenantIdentifier, main)); + EmailPassword.signIn(tenantIdentifierWithStorage, main, TestCase.users.get(userIndex).loginMethods[0].email, "password"); + } + } }