1- import { SuperTokensPlugin } from ' supertokens-node' ;
2- import { createPluginInitFunction } from ' @shared/js' ;
3- import { PLUGIN_ID , PLUGIN_SDK_VERSION } from ' ./constants' ;
1+ import { SuperTokensPlugin } from " supertokens-node" ;
2+ import { createPluginInitFunction } from " @shared/js" ;
3+ import { PLUGIN_ID , PLUGIN_SDK_VERSION } from " ./constants" ;
44import {
55 OverrideableTenantFunctionImplementation ,
66 SuperTokensPluginTenantEnrollmentPluginConfig ,
77 SuperTokensPluginTenantEnrollmentPluginNormalisedConfig ,
8- } from ' ./types' ;
9- import { getOverrideableTenantFunctionImplementation } from ' ./recipeImplementation' ;
10- import { logDebugMessage } from ' supertokens-node/lib/build/logger' ;
8+ } from " ./types" ;
9+ import { getOverrideableTenantFunctionImplementation } from " ./recipeImplementation" ;
10+ import { logDebugMessage } from " supertokens-node/lib/build/logger" ;
1111import {
1212 AssociateAllLoginMethodsOfUserWithTenant ,
1313 PLUGIN_ID as TENANTS_PLUGIN_ID ,
1414 SendPluginEmail ,
1515 GetAppUrl ,
16- } from ' @supertokens-plugins/tenants-nodejs' ;
17- import { listUsersByAccountInfo } from ' supertokens-node' ;
18- import { NormalisedAppinfo } from ' supertokens-node/types' ;
19- import { enableDebugLogs } from ' ./logger' ;
16+ } from " @supertokens-plugins/tenants-nodejs" ;
17+ import { listUsersByAccountInfo } from " supertokens-node" ;
18+ import { NormalisedAppinfo } from " supertokens-node/types" ;
19+ import { enableDebugLogs } from " ./logger" ;
2020
2121export const init = createPluginInitFunction <
2222 SuperTokensPlugin ,
@@ -39,27 +39,27 @@ export const init = createPluginInitFunction<
3939
4040 const tenantsPlugin = plugins . find ( ( plugin : any ) => plugin . id === TENANTS_PLUGIN_ID ) ;
4141 if ( ! tenantsPlugin ) {
42- throw new Error ( ' Base Tenants plugin not initialized, cannot continue.' ) ;
42+ throw new Error ( " Base Tenants plugin not initialized, cannot continue." ) ;
4343 }
4444
4545 if ( ! tenantsPlugin . exports ) {
46- throw new Error ( ' Base Tenants plugin does not export, cannot continue.' ) ;
46+ throw new Error ( " Base Tenants plugin does not export, cannot continue." ) ;
4747 }
4848
4949 const associateAllLoginMethodsOfUserWithTenant =
5050 tenantsPlugin . exports ?. associateAllLoginMethodsOfUserWithTenant ;
5151 if ( ! associateAllLoginMethodsOfUserWithTenant ) {
52- throw new Error ( ' Tenants plugin does not export associateAllLoginMethodsOfUserWithTenant, cannot continue.' ) ;
52+ throw new Error ( " Tenants plugin does not export associateAllLoginMethodsOfUserWithTenant, cannot continue." ) ;
5353 }
5454
5555 const sendPluginEmail = tenantsPlugin . exports ?. sendEmail ;
5656 if ( ! sendPluginEmail ) {
57- throw new Error ( ' Tenants plugin does not export sendEmail, cannot continue.' ) ;
57+ throw new Error ( " Tenants plugin does not export sendEmail, cannot continue." ) ;
5858 }
5959
6060 const getUserIdsInTenantWithRole = tenantsPlugin . exports ?. getUserIdsInTenantWithRole ;
6161 if ( ! getUserIdsInTenantWithRole ) {
62- throw new Error ( ' Tenants plugin does not export getUserIdsInTenantWithRole, cannot continue.' ) ;
62+ throw new Error ( " Tenants plugin does not export getUserIdsInTenantWithRole, cannot continue." ) ;
6363 }
6464
6565 associateLoginMethodDef = associateAllLoginMethodsOfUserWithTenant ;
@@ -68,15 +68,15 @@ export const init = createPluginInitFunction<
6868
6969 const getAppUrl = tenantsPlugin . exports ?. getAppUrl ;
7070 if ( ! getAppUrl ) {
71- throw new Error ( ' Tenants plugin does not export getAppUrl, cannot continue' ) ;
71+ throw new Error ( " Tenants plugin does not export getAppUrl, cannot continue" ) ;
7272 }
7373
7474 getAppUrlDef = getAppUrl ;
7575 appInfo = appConfig . appInfo ;
7676 } ,
7777 routeHandlers : ( ) => {
7878 return {
79- status : 'OK' ,
79+ status : "OK" ,
8080 routeHandlers : [ ] ,
8181 } ;
8282 } ,
@@ -87,19 +87,19 @@ export const init = createPluginInitFunction<
8787 ...originalImplementation ,
8888 signUp : async ( input ) => {
8989 const { canJoin, reason } = await implementation . canUserJoinTenant ( input . tenantId , {
90- type : ' email' ,
90+ type : " email" ,
9191 email : input . email ,
9292 } ) ;
93- logDebugMessage ( ' Reason: ' + reason ) ;
93+ logDebugMessage ( " Reason: " + reason ) ;
9494 if ( ! canJoin ) {
9595 return {
96- status : ' LINKING_TO_SESSION_USER_FAILED' ,
97- reason : ' EMAIL_VERIFICATION_REQUIRED' ,
96+ status : " LINKING_TO_SESSION_USER_FAILED" ,
97+ reason : " EMAIL_VERIFICATION_REQUIRED" ,
9898 } ;
9999 }
100100
101101 const response = await originalImplementation . signUp ( input ) ;
102- if ( response . status !== 'OK' ) {
102+ if ( response . status !== "OK" ) {
103103 return response ;
104104 }
105105
@@ -125,7 +125,7 @@ export const init = createPluginInitFunction<
125125 ...originalImplementation ,
126126 signUpPOST : async ( input ) => {
127127 const response = await originalImplementation . signUpPOST ! ( input ) ;
128- if ( response . status === ' SIGN_UP_NOT_ALLOWED' && response . reason . includes ( ' ERR_CODE_013' ) ) {
128+ if ( response . status === " SIGN_UP_NOT_ALLOWED" && response . reason . includes ( " ERR_CODE_013" ) ) {
129129 // There is a possibility that the user is not allowed
130130 // to signup to the tenant so we will have to update the message
131131 // accordingly.
@@ -146,7 +146,7 @@ export const init = createPluginInitFunction<
146146 ...originalImplementation ,
147147 signInUpPOST : async ( input ) => {
148148 const response = await originalImplementation . signInUpPOST ! ( input ) ;
149- if ( response . status === ' SIGN_IN_UP_NOT_ALLOWED' && response . reason . includes ( ' ERR_CODE_020' ) ) {
149+ if ( response . status === " SIGN_IN_UP_NOT_ALLOWED" && response . reason . includes ( " ERR_CODE_020" ) ) {
150150 return {
151151 ...response ,
152152 reason : "Cannot sign in / sign up due to security reasons or tenant doesn't allow signup" ,
@@ -176,19 +176,19 @@ export const init = createPluginInitFunction<
176176 }
177177
178178 const { canJoin, reason } = await implementation . canUserJoinTenant ( input . tenantId , {
179- type : ' thirdParty' ,
179+ type : " thirdParty" ,
180180 thirdPartyId : input . thirdPartyId ,
181181 } ) ;
182- logDebugMessage ( ' Reason: ' + reason ) ;
182+ logDebugMessage ( " Reason: " + reason ) ;
183183 if ( ! canJoin ) {
184184 return {
185- status : ' LINKING_TO_SESSION_USER_FAILED' ,
186- reason : ' EMAIL_VERIFICATION_REQUIRED' ,
185+ status : " LINKING_TO_SESSION_USER_FAILED" ,
186+ reason : " EMAIL_VERIFICATION_REQUIRED" ,
187187 } ;
188188 }
189189
190190 const response = await originalImplementation . signInUp ( input ) ;
191- if ( response . status !== 'OK' ) {
191+ if ( response . status !== "OK" ) {
192192 return response ;
193193 }
194194
@@ -216,7 +216,7 @@ export const init = createPluginInitFunction<
216216 ...originalImplementation ,
217217 createCodePOST : async ( input ) => {
218218 const response = await originalImplementation . createCodePOST ! ( input ) ;
219- if ( response . status === ' SIGN_IN_UP_NOT_ALLOWED' && response . reason . includes ( ' ERR_CODE_002' ) ) {
219+ if ( response . status === " SIGN_IN_UP_NOT_ALLOWED" && response . reason . includes ( " ERR_CODE_002" ) ) {
220220 return {
221221 ...response ,
222222 reason : "Cannot sign in / sign up due to security reasons or tenant doesn't allow signup" ,
@@ -227,7 +227,7 @@ export const init = createPluginInitFunction<
227227 } ,
228228 consumeCodePOST : async ( input ) => {
229229 const response = await originalImplementation . consumeCodePOST ! ( input ) ;
230- if ( response . status === ' SIGN_IN_UP_NOT_ALLOWED' && response . reason . includes ( ' ERR_CODE_002' ) ) {
230+ if ( response . status === " SIGN_IN_UP_NOT_ALLOWED" && response . reason . includes ( " ERR_CODE_002" ) ) {
231231 return {
232232 ...response ,
233233 reason : "Cannot sign in / sign up due to security reasons or tenant doesn't allow signup" ,
@@ -245,8 +245,8 @@ export const init = createPluginInitFunction<
245245 // If this is a signup, we need to check if the user
246246 // can signup to the tenant.
247247 const accountInfoResponse = await listUsersByAccountInfo ( input . tenantId , {
248- email : ' email' in input ? input . email : undefined ,
249- phoneNumber : ' phoneNumber' in input ? input . phoneNumber : undefined ,
248+ email : " email" in input ? input . email : undefined ,
249+ phoneNumber : " phoneNumber" in input ? input . phoneNumber : undefined ,
250250 } ) ;
251251 const isSignUp = accountInfoResponse . length === 0 ;
252252
@@ -256,19 +256,19 @@ export const init = createPluginInitFunction<
256256
257257 // If this is a signup but its through phone number, we cannot
258258 // restrict it so we will let it go through.
259- if ( ' phoneNumber' in input ) {
259+ if ( " phoneNumber" in input ) {
260260 return originalImplementation . createCode ( input ) ;
261261 }
262262
263263 const { canJoin, reason } = await implementation . canUserJoinTenant ( input . tenantId , {
264- type : ' email' ,
264+ type : " email" ,
265265 email : input . email ,
266266 } ) ;
267- logDebugMessage ( ' Reason: ' + reason ) ;
267+ logDebugMessage ( " Reason: " + reason ) ;
268268
269269 if ( ! canJoin ) {
270270 return {
271- status : ' SIGN_IN_UP_NOT_ALLOWED' ,
271+ status : " SIGN_IN_UP_NOT_ALLOWED" ,
272272 } as any ;
273273 }
274274
@@ -289,19 +289,19 @@ export const init = createPluginInitFunction<
289289 // This is handled in the consumeCode but we can handle
290290 // it here as well
291291 return {
292- status : ' RESTART_FLOW_ERROR' ,
292+ status : " RESTART_FLOW_ERROR" ,
293293 } ;
294294 }
295295
296296 const accountInfoResponse = await listUsersByAccountInfo (
297297 input . tenantId ,
298298 deviceInfo . phoneNumber !== undefined
299299 ? {
300- phoneNumber : deviceInfo . phoneNumber ! ,
301- }
300+ phoneNumber : deviceInfo . phoneNumber ! ,
301+ }
302302 : {
303- email : deviceInfo . email ! ,
304- } ,
303+ email : deviceInfo . email ! ,
304+ } ,
305305 ) ;
306306 const isSignUp = accountInfoResponse . length === 0 ;
307307
@@ -314,14 +314,14 @@ export const init = createPluginInitFunction<
314314 // Since this is a signup, we need to check if the user
315315 // can signup to the tenant.
316316 const { canJoin, reason } = await implementation . canUserJoinTenant ( input . tenantId , {
317- type : ' email' ,
317+ type : " email" ,
318318 email : deviceInfo . email ! ,
319319 } ) ;
320- logDebugMessage ( ' Reason: ' + reason ) ;
320+ logDebugMessage ( " Reason: " + reason ) ;
321321
322322 if ( ! canJoin ) {
323323 return {
324- status : ' SIGN_IN_UP_NOT_ALLOWED' ,
324+ status : " SIGN_IN_UP_NOT_ALLOWED" ,
325325 } as any ;
326326 }
327327
0 commit comments