Skip to content

Commit

Permalink
fix: ep login issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Sep 11, 2023
1 parent 1a9ae87 commit 18ca94c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/io/supertokens/emailpassword/EmailPassword.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -256,6 +257,13 @@ public void testVariousCases() throws Exception {
new AssociateUserToTenant(t2, 0),
new MakePrimaryUser(t1, 0),
}),
new TestCase(new TestCaseStep[]{
new CreateEmailPasswordUser(t1, "[email protected]"),
new CreatePlessUserWithEmail(t2, "[email protected]"),
new MakePrimaryUser(t1, 0),
new LinkAccounts(t1, 0, 1),
new SignInEmailPasswordUser(t2, 0).expect(new WrongCredentialsException())
}),

new TestCase(new TestCaseStep[]{
new CreateEmailPasswordUser(t1, "[email protected]"),
Expand Down Expand Up @@ -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");
}
}
}

0 comments on commit 18ca94c

Please sign in to comment.