@@ -156,11 +156,18 @@ func main() {
156
156
from supertokens_python import init, InputAppInfo
157
157
from supertokens_python.types import GeneralErrorResponse
158
158
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
162
168
from supertokens_python.recipe.thirdparty.provider import Provider, RedirectUriInfo
163
169
from supertokens_python.recipe.thirdparty.types import RawUserInfoFromProvider
170
+ from supertokens_python.recipe.session.interfaces import SessionContainer
164
171
165
172
166
173
def override_thirdparty_functions (original_implementation : RecipeInterface):
@@ -170,21 +177,55 @@ def override_thirdparty_functions(original_implementation: RecipeInterface):
170
177
third_party_id : str ,
171
178
third_party_user_id : str ,
172
179
email : str ,
180
+ is_verified : bool ,
173
181
oauth_tokens : Dict[str , Any],
174
182
raw_user_info_from_provider : RawUserInfoFromProvider,
183
+ session : Optional[SessionContainer],
184
+ should_try_linking_with_session_user : Union[bool , None ],
175
185
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 :
180
192
# 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
+ ):
186
216
# 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
+ )
188
229
189
230
# this means that the email already exists with another social login method.
190
231
# so we throw an error.
@@ -200,38 +241,51 @@ def override_thirdparty_apis(original_implementation: APIInterface):
200
241
201
242
async def sign_in_up_post (
202
243
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 ],
205
248
tenant_id : str ,
206
249
api_options : APIOptions,
207
- user_context : Dict[str , Any]
250
+ user_context : Dict[str , Any],
208
251
):
209
252
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
+ )
211
263
except Exception as e:
212
264
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
+ )
214
268
raise e
215
269
216
270
original_implementation.sign_in_up_post = sign_in_up_post
217
271
return original_implementation
218
272
219
273
220
274
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
224
277
recipe_list = [
225
278
thirdparty.init(
226
279
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
+ ]
229
286
),
230
- sign_in_and_up_feature = thirdparty.SignInAndUpFeature(providers = [
231
- # ...
232
- ])
233
287
)
234
- ]
288
+ ],
235
289
)
236
290
```
237
291
0 commit comments