Skip to content

Commit 17eccd2

Browse files
committed
more fixes
1 parent c65d040 commit 17eccd2

File tree

1 file changed

+81
-27
lines changed

1 file changed

+81
-27
lines changed

v2/thirdparty/common-customizations/deduplication/implementing-deduplication.mdx

Lines changed: 81 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,18 @@ func main() {
156156
from supertokens_python import init, InputAppInfo
157157
from supertokens_python.types import GeneralErrorResponse
158158
from supertokens_python.recipe import thirdparty
159-
from supertokens_python.recipe.thirdparty.asyncio import get_users_by_email
160-
from supertokens_python.recipe.thirdparty.interfaces import APIInterface, APIOptions, RecipeInterface, SignInUpOkResult
161-
from typing import Union, Dict, Any
159+
from supertokens_python.asyncio import list_users_by_account_info
160+
from supertokens_python.types import AccountInfo
161+
from supertokens_python.recipe.thirdparty.interfaces import (
162+
APIInterface,
163+
APIOptions,
164+
RecipeInterface,
165+
)
166+
from supertokens_python.recipe.thirdparty.types import ThirdPartyInfo
167+
from typing import Union, Dict, Any, Optional
162168
from supertokens_python.recipe.thirdparty.provider import Provider, RedirectUriInfo
163169
from supertokens_python.recipe.thirdparty.types import RawUserInfoFromProvider
170+
from supertokens_python.recipe.session.interfaces import SessionContainer
164171

165172

166173
def override_thirdparty_functions(original_implementation: RecipeInterface):
@@ -170,21 +177,55 @@ def override_thirdparty_functions(original_implementation: RecipeInterface):
170177
third_party_id: str,
171178
third_party_user_id: str,
172179
email: str,
180+
is_verified: bool,
173181
oauth_tokens: Dict[str, Any],
174182
raw_user_info_from_provider: RawUserInfoFromProvider,
183+
session: Optional[SessionContainer],
184+
should_try_linking_with_session_user: Union[bool, None],
175185
tenant_id: str,
176-
user_context: Dict[str, Any]
177-
) -> SignInUpOkResult:
178-
existing_users = await get_users_by_email(tenant_id, email, user_context)
179-
if (len(existing_users) == 0):
186+
user_context: Dict[str, Any],
187+
):
188+
existing_users = await list_users_by_account_info(
189+
tenant_id, AccountInfo(email=email)
190+
)
191+
if len(existing_users) == 0:
180192
# this means this email is new so we allow sign up
181-
return await original_sign_in_up(third_party_id, third_party_user_id, email, oauth_tokens, raw_user_info_from_provider, tenant_id, user_context)
182-
183-
if (len([x for x in existing_users if
184-
x.third_party_info.id == third_party_id and
185-
x.third_party_info.user_id == third_party_user_id]) > 0):
193+
return await original_sign_in_up(
194+
third_party_id,
195+
third_party_user_id,
196+
email,
197+
is_verified,
198+
oauth_tokens,
199+
raw_user_info_from_provider,
200+
session,
201+
should_try_linking_with_session_user,
202+
tenant_id,
203+
user_context,
204+
)
205+
206+
if any(
207+
any(
208+
lm.recipe_id == "thirdparty"
209+
and lm.has_same_third_party_info_as(
210+
ThirdPartyInfo(third_party_user_id, third_party_id)
211+
)
212+
for lm in user.login_methods
213+
)
214+
for user in existing_users
215+
):
186216
# this means we are trying to sign in with the same social login. So we allow it
187-
return await original_sign_in_up(third_party_id, third_party_user_id, email, oauth_tokens, raw_user_info_from_provider, tenant_id, user_context)
217+
return await original_sign_in_up(
218+
third_party_id,
219+
third_party_user_id,
220+
email,
221+
is_verified,
222+
oauth_tokens,
223+
raw_user_info_from_provider,
224+
session,
225+
should_try_linking_with_session_user,
226+
tenant_id,
227+
user_context,
228+
)
188229

189230
# this means that the email already exists with another social login method.
190231
# so we throw an error.
@@ -200,38 +241,51 @@ def override_thirdparty_apis(original_implementation: APIInterface):
200241

201242
async def sign_in_up_post(
202243
provider: Provider,
203-
redirect_uri_info: Union[RedirectUriInfo, None],
204-
oauth_tokens: Union[Dict[str, Any], None],
244+
redirect_uri_info: Optional[RedirectUriInfo],
245+
oauth_tokens: Optional[Dict[str, Any]],
246+
session: Optional[SessionContainer],
247+
should_try_linking_with_session_user: Union[bool, None],
205248
tenant_id: str,
206249
api_options: APIOptions,
207-
user_context: Dict[str, Any]
250+
user_context: Dict[str, Any],
208251
):
209252
try:
210-
return await original_sign_in_up_post(provider, redirect_uri_info, oauth_tokens, tenant_id, api_options, user_context)
253+
return await original_sign_in_up_post(
254+
provider,
255+
redirect_uri_info,
256+
oauth_tokens,
257+
session,
258+
should_try_linking_with_session_user,
259+
tenant_id,
260+
api_options,
261+
user_context,
262+
)
211263
except Exception as e:
212264
if str(e) == "Cannot sign up as email already exists":
213-
return GeneralErrorResponse("Seems like you already have an account with another social login provider. Please use that instead.")
265+
return GeneralErrorResponse(
266+
"Seems like you already have an account with another social login provider. Please use that instead."
267+
)
214268
raise e
215269

216270
original_implementation.sign_in_up_post = sign_in_up_post
217271
return original_implementation
218272

219273

220274
init(
221-
app_info=InputAppInfo(
222-
api_domain="...", app_name="...", website_domain="..."),
223-
framework='...', # type: ignore
275+
app_info=InputAppInfo(api_domain="...", app_name="...", website_domain="..."),
276+
framework="...", # type: ignore
224277
recipe_list=[
225278
thirdparty.init(
226279
override=thirdparty.InputOverrideConfig(
227-
apis=override_thirdparty_apis,
228-
functions=override_thirdparty_functions
280+
apis=override_thirdparty_apis, functions=override_thirdparty_functions
281+
),
282+
sign_in_and_up_feature=thirdparty.SignInAndUpFeature(
283+
providers=[
284+
# ...
285+
]
229286
),
230-
sign_in_and_up_feature=thirdparty.SignInAndUpFeature(providers=[
231-
# ...
232-
])
233287
)
234-
]
288+
],
235289
)
236290
```
237291

0 commit comments

Comments
 (0)