Skip to content

Commit e8147bd

Browse files
authored
fix: passwordless login fix (#829)
* fix: pless login fix * fix: version
1 parent 1c248d2 commit e8147bd

File tree

4 files changed

+74
-3
lines changed

4 files changed

+74
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
66
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [7.0.2] = 2023-10-05
9+
10+
- Fixes `500` error for passwordless login in certain cases - https://github.com/supertokens/supertokens-core/issues/828
11+
812
## [7.0.1] - 2023-10-04
913

1014
- Remove padding from link codes and pre-auth session ids in passwordless, but keep support for old format that included padding (`=` signs)

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ compileTestJava { options.encoding = "UTF-8" }
1919
// }
2020
//}
2121

22-
version = "7.0.1"
22+
version = "7.0.2"
2323

2424

2525
repositories {

src/main/java/io/supertokens/passwordless/Passwordless.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ public static ConsumeCodeResponse consumeCode(TenantIdentifierWithStorage tenant
399399
consumedDevice.email);
400400
for (AuthRecipeUserInfo currUser : users) {
401401
for (LoginMethod currLM : currUser.loginMethods) {
402-
if (currLM.recipeId == RECIPE_ID.PASSWORDLESS && currLM.email.equals(consumedDevice.email) && currLM.tenantIds.contains(tenantIdentifierWithStorage.getTenantId())) {
402+
if (currLM.recipeId == RECIPE_ID.PASSWORDLESS && currLM.email != null && currLM.email.equals(consumedDevice.email) && currLM.tenantIds.contains(tenantIdentifierWithStorage.getTenantId())) {
403403
user = currUser;
404404
loginMethod = currLM;
405405
break;
@@ -412,7 +412,7 @@ public static ConsumeCodeResponse consumeCode(TenantIdentifierWithStorage tenant
412412
for (AuthRecipeUserInfo currUser : users) {
413413
for (LoginMethod currLM : currUser.loginMethods) {
414414
if (currLM.recipeId == RECIPE_ID.PASSWORDLESS &&
415-
currLM.phoneNumber.equals(consumedDevice.phoneNumber) && currLM.tenantIds.contains(tenantIdentifierWithStorage.getTenantId())) {
415+
currLM.phoneNumber != null && currLM.phoneNumber.equals(consumedDevice.phoneNumber) && currLM.tenantIds.contains(tenantIdentifierWithStorage.getTenantId())) {
416416
user = currUser;
417417
loginMethod = currLM;
418418
break;

src/test/java/io/supertokens/test/accountlinking/EmailPasswordTests.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.supertokens.emailpassword.EmailPassword;
2222
import io.supertokens.featureflag.EE_FEATURES;
2323
import io.supertokens.featureflag.FeatureFlagTestContent;
24+
import io.supertokens.passwordless.Passwordless;
2425
import io.supertokens.pluginInterface.STORAGE_TYPE;
2526
import io.supertokens.pluginInterface.authRecipe.AuthRecipeUserInfo;
2627
import io.supertokens.pluginInterface.emailpassword.exceptions.UnknownUserIdException;
@@ -83,4 +84,70 @@ public void testUpdatePasswordWithDifferentValidUserId() throws Exception {
8384
process.kill();
8485
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED));
8586
}
87+
88+
@Test
89+
public void testPasswordlessUserWithSameEmail() throws Exception {
90+
String[] args = {"../"};
91+
TestingProcessManager.TestingProcess process = TestingProcessManager.start(args, false);
92+
FeatureFlagTestContent.getInstance(process.getProcess())
93+
.setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{
94+
EE_FEATURES.ACCOUNT_LINKING, EE_FEATURES.MULTI_TENANCY});
95+
process.startProcess();
96+
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED));
97+
98+
if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) {
99+
return;
100+
}
101+
102+
AuthRecipeUserInfo user1 = EmailPassword.signUp(process.getProcess(), "[email protected]", "password");
103+
Passwordless.CreateCodeResponse code = Passwordless.createCode(process.getProcess(), null, "+919876543210",
104+
null, null);
105+
AuthRecipeUserInfo user2 = Passwordless.consumeCode(process.getProcess(), code.deviceId, code.deviceIdHash, code.userInputCode, null).user;
106+
107+
AuthRecipe.createPrimaryUser(process.getProcess(), user1.getSupertokensUserId());
108+
AuthRecipe.linkAccounts(process.getProcess(), user2.getSupertokensUserId(), user1.getSupertokensUserId());
109+
110+
Passwordless.CreateCodeResponse code1 = Passwordless.createCode(process.getProcess(), "[email protected]", null,
111+
null, null);
112+
AuthRecipeUserInfo user3 = Passwordless.consumeCode(process.getProcess(), code1.deviceId, code1.deviceIdHash, code1.userInputCode, null).user;
113+
114+
process.kill();
115+
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED));
116+
}
117+
118+
@Test
119+
public void testPasswordlessUsersLinked() throws Exception {
120+
String[] args = {"../"};
121+
TestingProcessManager.TestingProcess process = TestingProcessManager.start(args, false);
122+
FeatureFlagTestContent.getInstance(process.getProcess())
123+
.setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{
124+
EE_FEATURES.ACCOUNT_LINKING, EE_FEATURES.MULTI_TENANCY});
125+
process.startProcess();
126+
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED));
127+
128+
if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) {
129+
return;
130+
}
131+
132+
Passwordless.CreateCodeResponse code1 = Passwordless.createCode(process.getProcess(), "[email protected]", null,
133+
null, null);
134+
AuthRecipeUserInfo user1 = Passwordless.consumeCode(process.getProcess(), code1.deviceId, code1.deviceIdHash, code1.userInputCode, null).user;
135+
136+
Thread.sleep(50);
137+
138+
Passwordless.CreateCodeResponse code2 = Passwordless.createCode(process.getProcess(), null, "+919876543210",
139+
null, null);
140+
AuthRecipeUserInfo user2 = Passwordless.consumeCode(process.getProcess(), code2.deviceId, code2.deviceIdHash, code2.userInputCode, null).user;
141+
142+
AuthRecipe.createPrimaryUser(process.getProcess(), user1.getSupertokensUserId());
143+
AuthRecipe.linkAccounts(process.getProcess(), user2.getSupertokensUserId(), user1.getSupertokensUserId());
144+
145+
Passwordless.CreateCodeResponse code3 = Passwordless.createCode(process.getProcess(), null, "+919876543210",
146+
null, null);
147+
AuthRecipeUserInfo user3 = Passwordless.consumeCode(process.getProcess(), code3.deviceId, code3.deviceIdHash, code3.userInputCode, null).user;
148+
149+
process.kill();
150+
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED));
151+
152+
}
86153
}

0 commit comments

Comments
 (0)