Skip to content

Commit 1ad65b8

Browse files
Merge pull request #473 from supertokens/tpl-dashboard-fix
fix: Fixes issue with thirdparty passwordless user in dashboard
2 parents 737169f + f16cf62 commit 1ad65b8

File tree

3 files changed

+79
-31
lines changed

3 files changed

+79
-31
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
## [0.18.7] - 2024-01-17
1212

1313
- Fixes `connection_uri` normalisation in the dashboard recipe.
14+
- Fixes issue with fetching of thirdparty passwordless user in dashboard: https://github.com/supertokens/supertokens-python/issues/472
1415

1516
## [0.18.6] - 2024-01-12
1617

supertokens_python/recipe/dashboard/utils.py

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -309,58 +309,40 @@ async def get_user_for_recipe_id(
309309
recipe: Optional[str] = None
310310

311311
async def update_user_dict(
312-
get_user_func1: Callable[[str], Awaitable[GetUserResult]],
313-
get_user_func2: Callable[[str], Awaitable[GetUserResult]],
314-
recipe1: str,
315-
recipe2: str,
312+
get_user_funcs: List[Callable[[str], Awaitable[GetUserResult]]],
313+
recipes: List[str],
316314
):
317315
nonlocal user, user_id, recipe
318316

319-
try:
320-
recipe_user = await get_user_func1(user_id) # type: ignore
321-
322-
if recipe_user is not None:
323-
user = UserWithMetadata().from_dict(
324-
recipe_user.__dict__, first_name="", last_name=""
325-
)
326-
recipe = recipe1
327-
except Exception:
328-
pass
329-
330-
if user is None:
317+
for get_user_func, recipe_id in zip(get_user_funcs, recipes):
331318
try:
332-
recipe_user = await get_user_func2(user_id)
319+
recipe_user = await get_user_func(user_id) # type: ignore
333320

334321
if recipe_user is not None:
335322
user = UserWithMetadata().from_dict(
336323
recipe_user.__dict__, first_name="", last_name=""
337324
)
338-
recipe = recipe2
325+
recipe = recipe_id
326+
break
339327
except Exception:
340328
pass
341329

342330
if recipe_id == EmailPasswordRecipe.recipe_id:
343331
await update_user_dict(
344-
ep_get_user_by_id,
345-
tpep_get_user_by_id,
346-
"emailpassword",
347-
"thirdpartyemailpassword",
332+
[ep_get_user_by_id, tpep_get_user_by_id],
333+
["emailpassword", "thirdpartyemailpassword"],
348334
)
349335

350336
elif recipe_id == ThirdPartyRecipe.recipe_id:
351337
await update_user_dict(
352-
tp_get_user_by_idx,
353-
tpep_get_user_by_id,
354-
"thirdparty",
355-
"thirdpartyemailpassword",
338+
[tp_get_user_by_idx, tpep_get_user_by_id, tppless_get_user_by_id],
339+
["thirdparty", "thirdpartyemailpassword", "thirdpartypasswordless"],
356340
)
357341

358342
elif recipe_id == PasswordlessRecipe.recipe_id:
359343
await update_user_dict(
360-
pless_get_user_by_id,
361-
tppless_get_user_by_id,
362-
"passwordless",
363-
"thirdpartypasswordless",
344+
[pless_get_user_by_id, tppless_get_user_by_id],
345+
["passwordless", "thirdpartypasswordless"],
364346
)
365347

366348
if user is not None and recipe is not None:

tests/dashboard/test_dashboard.py

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,20 @@
77
from supertokens_python.constants import DASHBOARD_VERSION
88
from supertokens_python.framework import BaseRequest
99
from supertokens_python.framework.fastapi import get_middleware
10-
from supertokens_python.recipe import dashboard, emailpassword, session, usermetadata
10+
from supertokens_python.recipe import (
11+
dashboard,
12+
emailpassword,
13+
session,
14+
usermetadata,
15+
thirdpartypasswordless,
16+
)
17+
import supertokens_python.recipe.thirdpartypasswordless.asyncio as tplasync
1118
from supertokens_python.recipe.dashboard import InputOverrideConfig
1219
from supertokens_python.recipe.dashboard.interfaces import (
1320
RecipeInterface as DashboardRI,
1421
)
1522
from supertokens_python.recipe.dashboard.utils import DashboardConfig
23+
from supertokens_python.recipe.passwordless import ContactEmailOrPhoneConfig
1624
from supertokens_python.recipe.usermetadata.asyncio import update_user_metadata
1725
from tests.utils import (
1826
clean_st,
@@ -203,3 +211,60 @@ async def test_that_first_connection_uri_is_selected_among_multiple_uris(
203211
assert f'window.connectionURI = "{first_connection_uri}"' in str(res.text)
204212
if st_config:
205213
st_config.connection_uri = "http://localhost:3567"
214+
215+
216+
async def test_that_get_user_works_with_combination_recipes(app: TestClient):
217+
def override_dashboard_functions(oi: DashboardRI) -> DashboardRI:
218+
async def should_allow_access(
219+
_request: BaseRequest,
220+
_config: DashboardConfig,
221+
_user_context: Dict[str, Any],
222+
) -> bool:
223+
return True
224+
225+
oi.should_allow_access = should_allow_access
226+
return oi
227+
228+
st_args = get_st_init_args(
229+
[
230+
session.init(get_token_transfer_method=lambda _, __, ___: "cookie"),
231+
thirdpartypasswordless.init(
232+
contact_config=ContactEmailOrPhoneConfig(),
233+
flow_type="USER_INPUT_CODE",
234+
),
235+
usermetadata.init(),
236+
dashboard.init(
237+
api_key="someKey",
238+
override=InputOverrideConfig(
239+
functions=override_dashboard_functions,
240+
),
241+
),
242+
]
243+
)
244+
init(**st_args)
245+
start_st()
246+
247+
pluser = await tplasync.thirdparty_manually_create_or_update_user(
248+
"public", "google", "googleid", "[email protected]"
249+
)
250+
251+
res = app.get(
252+
url="/auth/dashboard/api/user",
253+
params={
254+
"userId": "randomid",
255+
"recipeId": "thirdparty",
256+
},
257+
)
258+
res_json = res.json()
259+
assert res_json["status"] == "NO_USER_FOUND_ERROR"
260+
261+
res = app.get(
262+
url="/auth/dashboard/api/user",
263+
params={
264+
"userId": pluser.user.user_id,
265+
"recipeId": "thirdparty",
266+
},
267+
)
268+
res_json = res.json()
269+
assert res_json["status"] == "OK"
270+
assert res_json["user"]["id"] == pluser.user.user_id

0 commit comments

Comments
 (0)