Skip to content

Commit 8a7f248

Browse files
fix: thirdpartypasswordless email verification fix (#333)
1 parent 58e8ee6 commit 8a7f248

File tree

3 files changed

+39
-18
lines changed

3 files changed

+39
-18
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [unreleased]
99

10+
### Changes
11+
12+
- Fixes a few typos
13+
- Changes `getEmailForUserIdForEmailVerification` function inside thirdpartypasswordless to take into account passwordless emails and return an empty string in case a passwordless email doesn't exist. This helps situations where the dev wants to customise the email verification functions in the thirdpartypasswordless recipe.
14+
1015
## [9.3.0] - 2022-06-17
1116

1217
### Added

lib/build/recipe/thirdpartypasswordless/recipe.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,20 @@ class Recipe extends recipeModule_1.default {
129129
if (userInfo === undefined) {
130130
throw new Error("Unknown User ID provided");
131131
} else if (!("thirdParty" in userInfo)) {
132-
// this is a passwordless user.. so we always return some random email,
133-
// and in the function for isEmailVerified, we will check if the user
134-
// is a passwordless user, and if they are, we will return true in there
135-
132+
// this is a passwordless user
133+
if (userInfo.email !== undefined) {
134+
return userInfo.email;
135+
} else {
136+
// this is a passwordless user with only a phone number.
137+
// returning an empty string here is not a problem since
138+
// we override the email verification functions above to
139+
// send that the email is already verified for passwordless users.
140+
return "";
141+
}
142+
} else {
143+
// third party user
144+
return userInfo.email;
136145
}
137-
return userInfo.email;
138146
});
139147
this.isInServerlessEnv = isInServerlessEnv;
140148
this.config = utils_1.validateAndNormaliseUserInput(this, appInfo, config);
@@ -151,7 +159,7 @@ class Recipe extends recipeModule_1.default {
151159
let builder = new supertokens_js_override_1.default(implementation_1.default());
152160
this.apiImpl = builder.override(this.config.override.apis).build();
153161
}
154-
const recipImplReference = this.recipeInterfaceImpl;
162+
const recipeImplReference = this.recipeInterfaceImpl;
155163
const emailVerificationConfig = this.config.emailVerificationFeature;
156164
this.emailDelivery =
157165
ingredients.emailDelivery === undefined
@@ -178,7 +186,7 @@ class Recipe extends recipeModule_1.default {
178186
return Object.assign(Object.assign({}, oI), {
179187
createEmailVerificationToken: function (input) {
180188
return __awaiter(this, void 0, void 0, function* () {
181-
let user = yield recipImplReference.getUserById({
189+
let user = yield recipeImplReference.getUserById({
182190
userId: input.userId,
183191
userContext: input.userContext,
184192
});
@@ -193,7 +201,7 @@ class Recipe extends recipeModule_1.default {
193201
},
194202
isEmailVerified: function (input) {
195203
return __awaiter(this, void 0, void 0, function* () {
196-
let user = yield recipImplReference.getUserById({
204+
let user = yield recipeImplReference.getUserById({
197205
userId: input.userId,
198206
userContext: input.userContext,
199207
});

lib/ts/recipe/thirdpartypasswordless/recipe.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import RecipeImplementation from "./recipeImplementation";
3636
import PasswordlessRecipeImplementation from "./recipeImplementation/passwordlessRecipeImplementation";
3737
import ThirdPartyRecipeImplementation from "./recipeImplementation/thirdPartyRecipeImplementation";
3838
import getThirdPartyIterfaceImpl from "./api/thirdPartyAPIImplementation";
39-
import getPasswordlessIterfaceImpl from "./api/passwordlessAPIImplementation";
39+
import getPasswordlessInterfaceImpl from "./api/passwordlessAPIImplementation";
4040
import APIImplementation from "./api/implementation";
4141
import { Querier } from "../../querier";
4242
import OverrideableBuilder from "supertokens-js-override";
@@ -98,7 +98,7 @@ export default class Recipe extends RecipeModule {
9898
this.apiImpl = builder.override(this.config.override.apis).build();
9999
}
100100

101-
const recipImplReference = this.recipeInterfaceImpl;
101+
const recipeImplReference = this.recipeInterfaceImpl;
102102
const emailVerificationConfig = this.config.emailVerificationFeature;
103103

104104
this.emailDelivery =
@@ -131,7 +131,7 @@ export default class Recipe extends RecipeModule {
131131
return {
132132
...oI,
133133
createEmailVerificationToken: async function (input) {
134-
let user = await recipImplReference.getUserById({
134+
let user = await recipeImplReference.getUserById({
135135
userId: input.userId,
136136
userContext: input.userContext,
137137
});
@@ -145,7 +145,7 @@ export default class Recipe extends RecipeModule {
145145
}
146146
},
147147
isEmailVerified: async function (input) {
148-
let user = await recipImplReference.getUserById({
148+
let user = await recipeImplReference.getUserById({
149149
userId: input.userId,
150150
userContext: input.userContext,
151151
});
@@ -193,7 +193,7 @@ export default class Recipe extends RecipeModule {
193193
return PasswordlessRecipeImplementation(this.recipeInterfaceImpl);
194194
},
195195
apis: (_) => {
196-
return getPasswordlessIterfaceImpl(this.apiImpl);
196+
return getPasswordlessInterfaceImpl(this.apiImpl);
197197
},
198198
},
199199
},
@@ -350,11 +350,19 @@ export default class Recipe extends RecipeModule {
350350
if (userInfo === undefined) {
351351
throw new Error("Unknown User ID provided");
352352
} else if (!("thirdParty" in userInfo)) {
353-
// this is a passwordless user.. so we always return some random email,
354-
// and in the function for isEmailVerified, we will check if the user
355-
// is a passwordless user, and if they are, we will return true in there
356-
353+
// this is a passwordless user
354+
if (userInfo.email !== undefined) {
355+
return userInfo.email;
356+
} else {
357+
// this is a passwordless user with only a phone number.
358+
// returning an empty string here is not a problem since
359+
// we override the email verification functions above to
360+
// send that the email is already verified for passwordless users.
361+
return "";
362+
}
363+
} else {
364+
// third party user
365+
return userInfo.email;
357366
}
358-
return userInfo.email;
359367
};
360368
}

0 commit comments

Comments
 (0)