@@ -337,58 +337,40 @@ <h1 class="title">Module <code>supertokens_python.recipe.dashboard.utils</code><
337
337
recipe: Optional[str] = None
338
338
339
339
async def update_user_dict(
340
- get_user_func1: Callable[[str], Awaitable[GetUserResult]],
341
- get_user_func2: Callable[[str], Awaitable[GetUserResult]],
342
- recipe1: str,
343
- recipe2: str,
340
+ get_user_funcs: List[Callable[[str], Awaitable[GetUserResult]]],
341
+ recipes: List[str],
344
342
):
345
343
nonlocal user, user_id, recipe
346
344
347
- try:
348
- recipe_user = await get_user_func1(user_id) # type: ignore
349
-
350
- if recipe_user is not None:
351
- user = UserWithMetadata().from_dict(
352
- recipe_user.__dict__, first_name="", last_name=""
353
- )
354
- recipe = recipe1
355
- except Exception:
356
- pass
357
-
358
- if user is None:
345
+ for get_user_func, recipe_id in zip(get_user_funcs, recipes):
359
346
try:
360
- recipe_user = await get_user_func2 (user_id)
347
+ recipe_user = await get_user_func (user_id) # type: ignore
361
348
362
349
if recipe_user is not None:
363
350
user = UserWithMetadata().from_dict(
364
351
recipe_user.__dict__, first_name="", last_name=""
365
352
)
366
- recipe = recipe2
353
+ recipe = recipe_id
354
+ break
367
355
except Exception:
368
356
pass
369
357
370
358
if recipe_id == EmailPasswordRecipe.recipe_id:
371
359
await update_user_dict(
372
- ep_get_user_by_id,
373
- tpep_get_user_by_id,
374
- "emailpassword",
375
- "thirdpartyemailpassword",
360
+ [ep_get_user_by_id, tpep_get_user_by_id],
361
+ ["emailpassword", "thirdpartyemailpassword"],
376
362
)
377
363
378
364
elif recipe_id == ThirdPartyRecipe.recipe_id:
379
365
await update_user_dict(
380
- tp_get_user_by_idx,
381
- tpep_get_user_by_id,
382
- "thirdparty",
383
- "thirdpartyemailpassword",
366
+ [tp_get_user_by_idx, tpep_get_user_by_id, tppless_get_user_by_id],
367
+ ["thirdparty", "thirdpartyemailpassword", "thirdpartypasswordless"],
384
368
)
385
369
386
370
elif recipe_id == PasswordlessRecipe.recipe_id:
387
371
await update_user_dict(
388
- pless_get_user_by_id,
389
- tppless_get_user_by_id,
390
- "passwordless",
391
- "thirdpartypasswordless",
372
+ [pless_get_user_by_id, tppless_get_user_by_id],
373
+ ["passwordless", "thirdpartypasswordless"],
392
374
)
393
375
394
376
if user is not None and recipe is not None:
@@ -545,58 +527,40 @@ <h2 class="section-title" id="header-functions">Functions</h2>
545
527
recipe: Optional[str] = None
546
528
547
529
async def update_user_dict(
548
- get_user_func1: Callable[[str], Awaitable[GetUserResult]],
549
- get_user_func2: Callable[[str], Awaitable[GetUserResult]],
550
- recipe1: str,
551
- recipe2: str,
530
+ get_user_funcs: List[Callable[[str], Awaitable[GetUserResult]]],
531
+ recipes: List[str],
552
532
):
553
533
nonlocal user, user_id, recipe
554
534
555
- try:
556
- recipe_user = await get_user_func1(user_id) # type: ignore
557
-
558
- if recipe_user is not None:
559
- user = UserWithMetadata().from_dict(
560
- recipe_user.__dict__, first_name="", last_name=""
561
- )
562
- recipe = recipe1
563
- except Exception:
564
- pass
565
-
566
- if user is None:
535
+ for get_user_func, recipe_id in zip(get_user_funcs, recipes):
567
536
try:
568
- recipe_user = await get_user_func2 (user_id)
537
+ recipe_user = await get_user_func (user_id) # type: ignore
569
538
570
539
if recipe_user is not None:
571
540
user = UserWithMetadata().from_dict(
572
541
recipe_user.__dict__, first_name="", last_name=""
573
542
)
574
- recipe = recipe2
543
+ recipe = recipe_id
544
+ break
575
545
except Exception:
576
546
pass
577
547
578
548
if recipe_id == EmailPasswordRecipe.recipe_id:
579
549
await update_user_dict(
580
- ep_get_user_by_id,
581
- tpep_get_user_by_id,
582
- "emailpassword",
583
- "thirdpartyemailpassword",
550
+ [ep_get_user_by_id, tpep_get_user_by_id],
551
+ ["emailpassword", "thirdpartyemailpassword"],
584
552
)
585
553
586
554
elif recipe_id == ThirdPartyRecipe.recipe_id:
587
555
await update_user_dict(
588
- tp_get_user_by_idx,
589
- tpep_get_user_by_id,
590
- "thirdparty",
591
- "thirdpartyemailpassword",
556
+ [tp_get_user_by_idx, tpep_get_user_by_id, tppless_get_user_by_id],
557
+ ["thirdparty", "thirdpartyemailpassword", "thirdpartypasswordless"],
592
558
)
593
559
594
560
elif recipe_id == PasswordlessRecipe.recipe_id:
595
561
await update_user_dict(
596
- pless_get_user_by_id,
597
- tppless_get_user_by_id,
598
- "passwordless",
599
- "thirdpartypasswordless",
562
+ [pless_get_user_by_id, tppless_get_user_by_id],
563
+ ["passwordless", "thirdpartypasswordless"],
600
564
)
601
565
602
566
if user is not None and recipe is not None:
0 commit comments