@supertokens-plugins/rownd-nodejs 0.3.0-beta.7 → 0.3.0-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +39 -8
- package/dist/index.mjs +41 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -289,6 +289,10 @@ __export(index_exports, {
|
|
|
289
289
|
});
|
|
290
290
|
module.exports = __toCommonJS(index_exports);
|
|
291
291
|
|
|
292
|
+
// src/plugin.ts
|
|
293
|
+
var import_emailverification2 = require("supertokens-node/recipe/emailverification");
|
|
294
|
+
var import_session3 = __toESM(require("supertokens-node/recipe/session"));
|
|
295
|
+
|
|
292
296
|
// ../../shared/js/src/createPluginInit.ts
|
|
293
297
|
var import_supertokens_js_override = __toESM(require_build());
|
|
294
298
|
var createPluginInitFunction = (init2, getImplementation, getNormalisedConfig = (config2) => config2) => {
|
|
@@ -1870,12 +1874,12 @@ function hasVerifiedRealLoginMethod(user) {
|
|
|
1870
1874
|
});
|
|
1871
1875
|
}
|
|
1872
1876
|
function getEffectiveAuthLevel(user, originalAuthLevel, verifiedData) {
|
|
1873
|
-
if (originalAuthLevel === INSTANT_AUTH_METHOD_ID) {
|
|
1874
|
-
return INSTANT_AUTH_METHOD_ID;
|
|
1875
|
-
}
|
|
1876
1877
|
if (hasVerifiedRealLoginMethod(user)) {
|
|
1877
1878
|
return "verified";
|
|
1878
1879
|
}
|
|
1880
|
+
if (originalAuthLevel === INSTANT_AUTH_METHOD_ID) {
|
|
1881
|
+
return INSTANT_AUTH_METHOD_ID;
|
|
1882
|
+
}
|
|
1879
1883
|
return getGuestAuthLevel(user) || originalAuthLevel || (verifiedData && Object.keys(verifiedData).length > 0 ? "verified" : "unverified");
|
|
1880
1884
|
}
|
|
1881
1885
|
function canUpdateUserDataField(field) {
|
|
@@ -2304,6 +2308,7 @@ async function completePendingEmailVerification(input) {
|
|
|
2304
2308
|
return;
|
|
2305
2309
|
}
|
|
2306
2310
|
let metadataUserId = userId;
|
|
2311
|
+
let verifiedRecipeUserId = input.recipeUserId;
|
|
2307
2312
|
const passwordlessEmailMethod = getPasswordlessEmailLoginMethod(user);
|
|
2308
2313
|
if (passwordlessEmailMethod) {
|
|
2309
2314
|
const updateResult = await import_passwordless.default.updateUser({
|
|
@@ -2316,6 +2321,7 @@ async function completePendingEmailVerification(input) {
|
|
|
2316
2321
|
`Failed to update verified email method: ${updateResult.status}`
|
|
2317
2322
|
);
|
|
2318
2323
|
}
|
|
2324
|
+
verifiedRecipeUserId = passwordlessEmailMethod.recipeUserId;
|
|
2319
2325
|
} else if (hasOnlyGuestLoginMethods(user)) {
|
|
2320
2326
|
const isPasswordlessSignUpAllowed = await import_accountlinking.default.isSignUpAllowed(
|
|
2321
2327
|
PUBLIC_TENANT_ID,
|
|
@@ -2335,6 +2341,7 @@ async function completePendingEmailVerification(input) {
|
|
|
2335
2341
|
tenantId: PUBLIC_TENANT_ID,
|
|
2336
2342
|
userContext: input.userContext
|
|
2337
2343
|
});
|
|
2344
|
+
verifiedRecipeUserId = passwordlessUser.recipeUserId;
|
|
2338
2345
|
const primaryUserResult = await import_accountlinking.default.createPrimaryUser(
|
|
2339
2346
|
passwordlessUser.recipeUserId,
|
|
2340
2347
|
input.userContext
|
|
@@ -2380,6 +2387,10 @@ async function completePendingEmailVerification(input) {
|
|
|
2380
2387
|
)
|
|
2381
2388
|
};
|
|
2382
2389
|
await import_usermetadata3.default.updateUserMetadata(metadataUserId, updatedMetadata);
|
|
2390
|
+
return {
|
|
2391
|
+
userId: metadataUserId,
|
|
2392
|
+
recipeUserId: verifiedRecipeUserId
|
|
2393
|
+
};
|
|
2383
2394
|
}
|
|
2384
2395
|
function isMatchingPendingEmailVerification(verification, email) {
|
|
2385
2396
|
return verification.field === "email" && verification.value === email;
|
|
@@ -2808,6 +2819,12 @@ function validateWritableFields(fields) {
|
|
|
2808
2819
|
}
|
|
2809
2820
|
|
|
2810
2821
|
// src/plugin.ts
|
|
2822
|
+
var verifyRowndUserSessionOptions = {
|
|
2823
|
+
sessionRequired: true,
|
|
2824
|
+
overrideGlobalClaimValidators: (validators) => validators.filter((validator) => {
|
|
2825
|
+
return !("claim" in validator) || validator.claim.key !== import_emailverification2.EmailVerificationClaim.key;
|
|
2826
|
+
})
|
|
2827
|
+
};
|
|
2811
2828
|
var init = createPluginInitFunction(
|
|
2812
2829
|
(pluginConfig2) => {
|
|
2813
2830
|
const rowndClient2 = (0, import_node.createInstance)({
|
|
@@ -2923,13 +2940,13 @@ var init = createPluginInitFunction(
|
|
|
2923
2940
|
{
|
|
2924
2941
|
path: `${apiBasePath}${HANDLE_BASE_PATH}/user`,
|
|
2925
2942
|
method: "get",
|
|
2926
|
-
verifySessionOptions:
|
|
2943
|
+
verifySessionOptions: verifyRowndUserSessionOptions,
|
|
2927
2944
|
handler: withRequestHandler(handleGetUser())
|
|
2928
2945
|
},
|
|
2929
2946
|
{
|
|
2930
2947
|
path: `${apiBasePath}${HANDLE_BASE_PATH}/user`,
|
|
2931
2948
|
method: "put",
|
|
2932
|
-
verifySessionOptions:
|
|
2949
|
+
verifySessionOptions: verifyRowndUserSessionOptions,
|
|
2933
2950
|
handler: withRequestHandler(handleUpdateUser())
|
|
2934
2951
|
},
|
|
2935
2952
|
{
|
|
@@ -2953,13 +2970,13 @@ var init = createPluginInitFunction(
|
|
|
2953
2970
|
{
|
|
2954
2971
|
path: `${apiBasePath}${HANDLE_BASE_PATH}/user/field`,
|
|
2955
2972
|
method: "get",
|
|
2956
|
-
verifySessionOptions:
|
|
2973
|
+
verifySessionOptions: verifyRowndUserSessionOptions,
|
|
2957
2974
|
handler: withRequestHandler(handleGetUserField())
|
|
2958
2975
|
},
|
|
2959
2976
|
{
|
|
2960
2977
|
path: `${apiBasePath}${HANDLE_BASE_PATH}/user/field`,
|
|
2961
2978
|
method: "put",
|
|
2962
|
-
verifySessionOptions:
|
|
2979
|
+
verifySessionOptions: verifyRowndUserSessionOptions,
|
|
2963
2980
|
handler: withRequestHandler(handleUpdateUserField())
|
|
2964
2981
|
}
|
|
2965
2982
|
]
|
|
@@ -3254,11 +3271,25 @@ var init = createPluginInitFunction(
|
|
|
3254
3271
|
}
|
|
3255
3272
|
const response = await originalImplementation.verifyEmailPOST(input);
|
|
3256
3273
|
if (response.status === "OK") {
|
|
3257
|
-
await completePendingEmailVerification({
|
|
3274
|
+
const verificationResult = await completePendingEmailVerification({
|
|
3258
3275
|
recipeUserId: response.user.recipeUserId,
|
|
3259
3276
|
email: response.user.email,
|
|
3260
3277
|
userContext: input.userContext
|
|
3261
3278
|
});
|
|
3279
|
+
const session = input.session;
|
|
3280
|
+
const shouldReplaceSession = session && verificationResult && (session.getUserId(input.userContext) !== verificationResult.userId || session.getRecipeUserId(input.userContext).getAsString() !== verificationResult.recipeUserId.getAsString());
|
|
3281
|
+
if (shouldReplaceSession) {
|
|
3282
|
+
await session.revokeSession(input.userContext);
|
|
3283
|
+
response.newSession = await import_session3.default.createNewSession(
|
|
3284
|
+
input.options.req,
|
|
3285
|
+
input.options.res,
|
|
3286
|
+
session.getTenantId(input.userContext),
|
|
3287
|
+
verificationResult.recipeUserId,
|
|
3288
|
+
{},
|
|
3289
|
+
{},
|
|
3290
|
+
input.userContext
|
|
3291
|
+
);
|
|
3292
|
+
}
|
|
3262
3293
|
}
|
|
3263
3294
|
return response;
|
|
3264
3295
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -264,6 +264,12 @@ var require_supports_color = __commonJS({
|
|
|
264
264
|
}
|
|
265
265
|
});
|
|
266
266
|
|
|
267
|
+
// src/plugin.ts
|
|
268
|
+
import {
|
|
269
|
+
EmailVerificationClaim
|
|
270
|
+
} from "supertokens-node/recipe/emailverification";
|
|
271
|
+
import Session3 from "supertokens-node/recipe/session";
|
|
272
|
+
|
|
267
273
|
// ../../shared/js/src/createPluginInit.ts
|
|
268
274
|
var import_supertokens_js_override = __toESM(require_build());
|
|
269
275
|
var createPluginInitFunction = (init2, getImplementation, getNormalisedConfig = (config2) => config2) => {
|
|
@@ -1845,12 +1851,12 @@ function hasVerifiedRealLoginMethod(user) {
|
|
|
1845
1851
|
});
|
|
1846
1852
|
}
|
|
1847
1853
|
function getEffectiveAuthLevel(user, originalAuthLevel, verifiedData) {
|
|
1848
|
-
if (originalAuthLevel === INSTANT_AUTH_METHOD_ID) {
|
|
1849
|
-
return INSTANT_AUTH_METHOD_ID;
|
|
1850
|
-
}
|
|
1851
1854
|
if (hasVerifiedRealLoginMethod(user)) {
|
|
1852
1855
|
return "verified";
|
|
1853
1856
|
}
|
|
1857
|
+
if (originalAuthLevel === INSTANT_AUTH_METHOD_ID) {
|
|
1858
|
+
return INSTANT_AUTH_METHOD_ID;
|
|
1859
|
+
}
|
|
1854
1860
|
return getGuestAuthLevel(user) || originalAuthLevel || (verifiedData && Object.keys(verifiedData).length > 0 ? "verified" : "unverified");
|
|
1855
1861
|
}
|
|
1856
1862
|
function canUpdateUserDataField(field) {
|
|
@@ -2279,6 +2285,7 @@ async function completePendingEmailVerification(input) {
|
|
|
2279
2285
|
return;
|
|
2280
2286
|
}
|
|
2281
2287
|
let metadataUserId = userId;
|
|
2288
|
+
let verifiedRecipeUserId = input.recipeUserId;
|
|
2282
2289
|
const passwordlessEmailMethod = getPasswordlessEmailLoginMethod(user);
|
|
2283
2290
|
if (passwordlessEmailMethod) {
|
|
2284
2291
|
const updateResult = await Passwordless.updateUser({
|
|
@@ -2291,6 +2298,7 @@ async function completePendingEmailVerification(input) {
|
|
|
2291
2298
|
`Failed to update verified email method: ${updateResult.status}`
|
|
2292
2299
|
);
|
|
2293
2300
|
}
|
|
2301
|
+
verifiedRecipeUserId = passwordlessEmailMethod.recipeUserId;
|
|
2294
2302
|
} else if (hasOnlyGuestLoginMethods(user)) {
|
|
2295
2303
|
const isPasswordlessSignUpAllowed = await AccountLinking.isSignUpAllowed(
|
|
2296
2304
|
PUBLIC_TENANT_ID,
|
|
@@ -2310,6 +2318,7 @@ async function completePendingEmailVerification(input) {
|
|
|
2310
2318
|
tenantId: PUBLIC_TENANT_ID,
|
|
2311
2319
|
userContext: input.userContext
|
|
2312
2320
|
});
|
|
2321
|
+
verifiedRecipeUserId = passwordlessUser.recipeUserId;
|
|
2313
2322
|
const primaryUserResult = await AccountLinking.createPrimaryUser(
|
|
2314
2323
|
passwordlessUser.recipeUserId,
|
|
2315
2324
|
input.userContext
|
|
@@ -2355,6 +2364,10 @@ async function completePendingEmailVerification(input) {
|
|
|
2355
2364
|
)
|
|
2356
2365
|
};
|
|
2357
2366
|
await UserMetadata3.updateUserMetadata(metadataUserId, updatedMetadata);
|
|
2367
|
+
return {
|
|
2368
|
+
userId: metadataUserId,
|
|
2369
|
+
recipeUserId: verifiedRecipeUserId
|
|
2370
|
+
};
|
|
2358
2371
|
}
|
|
2359
2372
|
function isMatchingPendingEmailVerification(verification, email) {
|
|
2360
2373
|
return verification.field === "email" && verification.value === email;
|
|
@@ -2783,6 +2796,12 @@ function validateWritableFields(fields) {
|
|
|
2783
2796
|
}
|
|
2784
2797
|
|
|
2785
2798
|
// src/plugin.ts
|
|
2799
|
+
var verifyRowndUserSessionOptions = {
|
|
2800
|
+
sessionRequired: true,
|
|
2801
|
+
overrideGlobalClaimValidators: (validators) => validators.filter((validator) => {
|
|
2802
|
+
return !("claim" in validator) || validator.claim.key !== EmailVerificationClaim.key;
|
|
2803
|
+
})
|
|
2804
|
+
};
|
|
2786
2805
|
var init = createPluginInitFunction(
|
|
2787
2806
|
(pluginConfig2) => {
|
|
2788
2807
|
const rowndClient2 = createInstance({
|
|
@@ -2898,13 +2917,13 @@ var init = createPluginInitFunction(
|
|
|
2898
2917
|
{
|
|
2899
2918
|
path: `${apiBasePath}${HANDLE_BASE_PATH}/user`,
|
|
2900
2919
|
method: "get",
|
|
2901
|
-
verifySessionOptions:
|
|
2920
|
+
verifySessionOptions: verifyRowndUserSessionOptions,
|
|
2902
2921
|
handler: withRequestHandler(handleGetUser())
|
|
2903
2922
|
},
|
|
2904
2923
|
{
|
|
2905
2924
|
path: `${apiBasePath}${HANDLE_BASE_PATH}/user`,
|
|
2906
2925
|
method: "put",
|
|
2907
|
-
verifySessionOptions:
|
|
2926
|
+
verifySessionOptions: verifyRowndUserSessionOptions,
|
|
2908
2927
|
handler: withRequestHandler(handleUpdateUser())
|
|
2909
2928
|
},
|
|
2910
2929
|
{
|
|
@@ -2928,13 +2947,13 @@ var init = createPluginInitFunction(
|
|
|
2928
2947
|
{
|
|
2929
2948
|
path: `${apiBasePath}${HANDLE_BASE_PATH}/user/field`,
|
|
2930
2949
|
method: "get",
|
|
2931
|
-
verifySessionOptions:
|
|
2950
|
+
verifySessionOptions: verifyRowndUserSessionOptions,
|
|
2932
2951
|
handler: withRequestHandler(handleGetUserField())
|
|
2933
2952
|
},
|
|
2934
2953
|
{
|
|
2935
2954
|
path: `${apiBasePath}${HANDLE_BASE_PATH}/user/field`,
|
|
2936
2955
|
method: "put",
|
|
2937
|
-
verifySessionOptions:
|
|
2956
|
+
verifySessionOptions: verifyRowndUserSessionOptions,
|
|
2938
2957
|
handler: withRequestHandler(handleUpdateUserField())
|
|
2939
2958
|
}
|
|
2940
2959
|
]
|
|
@@ -3229,11 +3248,25 @@ var init = createPluginInitFunction(
|
|
|
3229
3248
|
}
|
|
3230
3249
|
const response = await originalImplementation.verifyEmailPOST(input);
|
|
3231
3250
|
if (response.status === "OK") {
|
|
3232
|
-
await completePendingEmailVerification({
|
|
3251
|
+
const verificationResult = await completePendingEmailVerification({
|
|
3233
3252
|
recipeUserId: response.user.recipeUserId,
|
|
3234
3253
|
email: response.user.email,
|
|
3235
3254
|
userContext: input.userContext
|
|
3236
3255
|
});
|
|
3256
|
+
const session = input.session;
|
|
3257
|
+
const shouldReplaceSession = session && verificationResult && (session.getUserId(input.userContext) !== verificationResult.userId || session.getRecipeUserId(input.userContext).getAsString() !== verificationResult.recipeUserId.getAsString());
|
|
3258
|
+
if (shouldReplaceSession) {
|
|
3259
|
+
await session.revokeSession(input.userContext);
|
|
3260
|
+
response.newSession = await Session3.createNewSession(
|
|
3261
|
+
input.options.req,
|
|
3262
|
+
input.options.res,
|
|
3263
|
+
session.getTenantId(input.userContext),
|
|
3264
|
+
verificationResult.recipeUserId,
|
|
3265
|
+
{},
|
|
3266
|
+
{},
|
|
3267
|
+
input.userContext
|
|
3268
|
+
);
|
|
3269
|
+
}
|
|
3237
3270
|
}
|
|
3238
3271
|
return response;
|
|
3239
3272
|
}
|