Skip to content

Commit 396bf8f

Browse files
committed
more changes
1 parent 17eccd2 commit 396bf8f

File tree

20 files changed

+776
-89
lines changed

20 files changed

+776
-89
lines changed

v2/emailpassword/custom-ui/init/user-management-dashboard/tenant-management/overview.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Once the dashboard recipe is initialised, the tenant management should be availa
1616

1717
:::caution
1818

19-
Currently this is only available with the Node SDK version >= 20.0.1 and will be available for python and golang SDKs soon.
19+
Currently, this is only available with our Node and Python SDKs.
2020

2121
:::
2222

v2/emailpassword/pre-built-ui/setup/user-management-dashboard/tenant-management/overview.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Once the dashboard recipe is initialised, the tenant management should be availa
1616

1717
:::caution
1818

19-
Currently this is only available with the Node SDK version >= 20.0.1 and will be available for python and golang SDKs soon.
19+
Currently, this is only available with our Node and Python SDKs.
2020

2121
:::
2222

v2/passwordless/custom-ui/init/user-management-dashboard/tenant-management/overview.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Once the dashboard recipe is initialised, the tenant management should be availa
1616

1717
:::caution
1818

19-
Currently this is only available with the Node SDK version >= 20.0.1 and will be available for python and golang SDKs soon.
19+
Currently, this is only available with our Node and Python SDKs.
2020

2121
:::
2222

v2/passwordless/pre-built-ui/setup/user-management-dashboard/tenant-management/overview.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Once the dashboard recipe is initialised, the tenant management should be availa
1616

1717
:::caution
1818

19-
Currently this is only available with the Node SDK version >= 20.0.1 and will be available for python and golang SDKs soon.
19+
Currently, this is only available with our Node and Python SDKs.
2020

2121
:::
2222

v2/thirdparty/common-customizations/account-linking/automatic-account-linking.mdx

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,48 @@ Coming Soon
8484
</TabItem>
8585
<TabItem value="python">
8686

87-
:::note
88-
Coming Soon
89-
:::
87+
```python
88+
from supertokens_python import init, InputAppInfo, SupertokensConfig
89+
from supertokens_python.recipe import accountlinking
90+
from supertokens_python.types import User
91+
from supertokens_python.recipe.session.interfaces import SessionContainer
92+
from supertokens_python.recipe.accountlinking.types import AccountInfoWithRecipeIdAndUserId, ShouldNotAutomaticallyLink, ShouldAutomaticallyLink
93+
from typing import Dict, Any, Optional, Union
94+
95+
async def should_do_automatic_account_linking(
96+
new_account_info: AccountInfoWithRecipeIdAndUserId,
97+
user: Optional[User],
98+
session: Optional[SessionContainer],
99+
tenant_id: str,
100+
user_context: Dict[str, Any]
101+
) -> Union[ShouldNotAutomaticallyLink, ShouldAutomaticallyLink]:
102+
if session is not None:
103+
return ShouldNotAutomaticallyLink()
104+
105+
if new_account_info.recipe_user_id is not None and user is not None:
106+
_user_id = new_account_info.recipe_user_id.get_as_string()
107+
has_info_associated_with_user_id = False # TODO: add your own implementation here.
108+
if has_info_associated_with_user_id:
109+
return ShouldNotAutomaticallyLink()
110+
111+
return ShouldAutomaticallyLink(should_require_verification=True)
112+
113+
114+
init(
115+
app_info=InputAppInfo(
116+
app_name="...",
117+
api_domain="...",
118+
website_domain="...",
119+
),
120+
supertokens_config=SupertokensConfig(
121+
connection_uri="...",
122+
),
123+
framework='...', # type: ignore
124+
recipe_list=[
125+
accountlinking.init(should_do_automatic_account_linking=should_do_automatic_account_linking)
126+
],
127+
)
128+
```
90129

91130
</TabItem>
92131
</BackendSDKTabs>

v2/thirdparty/common-customizations/account-linking/manual-account-linking.mdx

Lines changed: 212 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ hide_title: true
1010
import AccountLinkingPaidBanner from '../../../community/reusableMD/accountlinking/AccountLinkingPaidBanner.mdx'
1111
import BackendSDKTabs from "/src/components/tabs/BackendSDKTabs";
1212
import TabItem from '@theme/TabItem';
13+
import PythonSyncAsyncSubTabs from "/src/components/tabs/PythonSyncAsyncSubTabs";
1314

1415
<AccountLinkingPaidBanner />
1516

@@ -43,13 +44,7 @@ supertokens.init({
4344
},
4445
recipeList: [
4546
// highlight-start
46-
AccountLinking.init({
47-
shouldDoAutomaticAccountLinking: async (newAccountInfo: AccountInfoWithRecipeId & { recipeUserId?: RecipeUserId }, user: User | undefined, session: SessionContainerInterface | undefined, tenantId: string, userContext: any) => {
48-
return {
49-
shouldAutomaticallyLink: false
50-
}
51-
}
52-
})
47+
AccountLinking.init()
5348
// highlight-end
5449
]
5550
});
@@ -65,9 +60,26 @@ Coming Soon
6560
</TabItem>
6661
<TabItem value="python">
6762

68-
:::note
69-
Coming Soon
70-
:::
63+
```python
64+
from supertokens_python import init, InputAppInfo, SupertokensConfig
65+
from supertokens_python.recipe import accountlinking
66+
67+
68+
init(
69+
app_info=InputAppInfo(
70+
app_name="...",
71+
api_domain="...",
72+
website_domain="...",
73+
),
74+
supertokens_config=SupertokensConfig(
75+
connection_uri="...",
76+
),
77+
framework='...', # type: ignore
78+
recipe_list=[
79+
accountlinking.init()
80+
],
81+
)
82+
```
7183

7284
</TabItem>
7385
</BackendSDKTabs>
@@ -116,9 +128,62 @@ Coming Soon
116128
</TabItem>
117129
<TabItem value="python">
118130

119-
:::note
120-
Coming Soon
121-
:::
131+
<PythonSyncAsyncSubTabs>
132+
<TabItem value="asyncio">
133+
134+
```python
135+
from supertokens_python.recipe.accountlinking.asyncio import create_primary_user
136+
from supertokens_python.types import RecipeUserId
137+
138+
async def make_user_primary(recipe_user_id: RecipeUserId):
139+
response = await create_primary_user(recipe_user_id)
140+
if response.status == "OK":
141+
if response.was_already_a_primary_user:
142+
# The input user was already a primary user and accounts can be linked to it.
143+
pass
144+
else:
145+
# User is now primary and accounts can be linked to it.
146+
pass
147+
modified_user = response.user
148+
print(modified_user.is_primary_user) # will print True
149+
elif response.status == "ACCOUNT_INFO_ALREADY_ASSOCIATED_WITH_ANOTHER_PRIMARY_USER_ID_ERROR":
150+
# This happens if there already exists another primary user with the same email or phone number
151+
# in at least one of the tenants that this user belongs to.
152+
pass
153+
elif response.status == "RECIPE_USER_ID_ALREADY_LINKED_WITH_PRIMARY_USER_ID_ERROR":
154+
# This happens if this user is already linked to another primary user.
155+
pass
156+
```
157+
158+
</TabItem>
159+
<TabItem value="syncio">
160+
161+
```python
162+
from supertokens_python.recipe.accountlinking.syncio import create_primary_user
163+
from supertokens_python.types import RecipeUserId
164+
165+
def make_user_primary(recipe_user_id: RecipeUserId):
166+
response = create_primary_user(recipe_user_id)
167+
if response.status == "OK":
168+
if response.was_already_a_primary_user:
169+
# The input user was already a primary user and accounts can be linked to it.
170+
pass
171+
else:
172+
# User is now primary and accounts can be linked to it.
173+
pass
174+
modified_user = response.user
175+
print(modified_user.is_primary_user) # will print True
176+
elif response.status == "ACCOUNT_INFO_ALREADY_ASSOCIATED_WITH_ANOTHER_PRIMARY_USER_ID_ERROR":
177+
# This happens if there already exists another primary user with the same email or phone number
178+
# in at least one of the tenants that this user belongs to.
179+
pass
180+
elif response.status == "RECIPE_USER_ID_ALREADY_LINKED_WITH_PRIMARY_USER_ID_ERROR":
181+
# This happens if this user is already linked to another primary user.
182+
pass
183+
```
184+
185+
</TabItem>
186+
</PythonSyncAsyncSubTabs>
122187

123188
</TabItem>
124189
</BackendSDKTabs>
@@ -168,9 +233,72 @@ Coming Soon
168233
</TabItem>
169234
<TabItem value="python">
170235

171-
:::note
172-
Coming Soon
173-
:::
236+
<PythonSyncAsyncSubTabs>
237+
<TabItem value="asyncio">
238+
239+
```python
240+
from supertokens_python.recipe.accountlinking.asyncio import link_accounts
241+
from supertokens_python.types import RecipeUserId
242+
243+
async def link_accounts_helper(primary_user_id: str, recipe_user_id: RecipeUserId):
244+
response = await link_accounts(recipe_user_id, primary_user_id)
245+
if response.status == "OK":
246+
if response.accounts_already_linked:
247+
# The input users were already linked
248+
pass
249+
else:
250+
# The two users are now linked
251+
pass
252+
modified_user = response.user
253+
print(modified_user.login_methods) # this will now contain the login method of the recipeUserId as well.
254+
elif response.status == "ACCOUNT_INFO_ALREADY_ASSOCIATED_WITH_ANOTHER_PRIMARY_USER_ID_ERROR":
255+
# This happens if there already exists another primary user with the same email or phone number
256+
# as the recipeUserId's account.
257+
pass
258+
elif response.status == "INPUT_USER_IS_NOT_A_PRIMARY_USER":
259+
# This happens if the input primaryUserId is not actually a primary user ID.
260+
# You can call create_primary_user and call link_accounts again
261+
pass
262+
elif response.status == "RECIPE_USER_ID_ALREADY_LINKED_WITH_ANOTHER_PRIMARY_USER_ID_ERROR":
263+
# This happens if the input recipe user ID is already linked to another primary user.
264+
# You can call unlink_accounts on the recipe user ID and then try linking again.
265+
pass
266+
```
267+
268+
</TabItem>
269+
<TabItem value="syncio">
270+
271+
```python
272+
from supertokens_python.recipe.accountlinking.syncio import link_accounts
273+
from supertokens_python.types import RecipeUserId
274+
275+
def link_accounts_helper(primary_user_id: str, recipe_user_id: RecipeUserId):
276+
response = link_accounts(recipe_user_id, primary_user_id)
277+
if response.status == "OK":
278+
if response.accounts_already_linked:
279+
# The input users were already linked
280+
pass
281+
else:
282+
# The two users are now linked
283+
pass
284+
modified_user = response.user
285+
print(modified_user.login_methods) # this will now contain the login method of the recipeUserId as well.
286+
elif response.status == "ACCOUNT_INFO_ALREADY_ASSOCIATED_WITH_ANOTHER_PRIMARY_USER_ID_ERROR":
287+
# This happens if there already exists another primary user with the same email or phone number
288+
# as the recipeUserId's account.
289+
pass
290+
elif response.status == "INPUT_USER_IS_NOT_A_PRIMARY_USER":
291+
# This happens if the input primaryUserId is not actually a primary user ID.
292+
# You can call create_primary_user and call link_accounts again
293+
pass
294+
elif response.status == "RECIPE_USER_ID_ALREADY_LINKED_WITH_ANOTHER_PRIMARY_USER_ID_ERROR":
295+
# This happens if the input recipe user ID is already linked to another primary user.
296+
# You can call unlink_accounts on the recipe user ID and then try linking again.
297+
pass
298+
```
299+
300+
</TabItem>
301+
</PythonSyncAsyncSubTabs>
174302

175303
</TabItem>
176304
</BackendSDKTabs>
@@ -221,9 +349,68 @@ Coming Soon
221349
</TabItem>
222350
<TabItem value="python">
223351

224-
:::note
225-
Coming Soon
226-
:::
352+
<PythonSyncAsyncSubTabs>
353+
<TabItem value="asyncio">
354+
355+
```python
356+
from supertokens_python.recipe.accountlinking.asyncio import unlink_account
357+
from supertokens_python.types import RecipeUserId
358+
359+
async def unlink_account_helper(recipe_user_id: RecipeUserId):
360+
response = await unlink_account(recipe_user_id)
361+
if response.was_linked:
362+
# This means that we unlinked the account from its primary user ID
363+
pass
364+
else:
365+
# This means that the user was never linked in the first place
366+
pass
367+
368+
if response.was_recipe_user_deleted:
369+
# This is true if we call unlink_account on the recipe user ID of the primary user ID user.
370+
# We delete this user because if we don't and we call get_user_by_id() on this user's ID, SuperTokens
371+
# won't know which user info to return - the primary user, or the recipe user.
372+
# Note that even though the recipe user is deleted, the session, metadata, roles etc for this
373+
# primary user is still intact, and calling get_user_by_id(primary_user_id) will still return
374+
# the user object with the other login methods.
375+
pass
376+
else:
377+
# There now exists a user account which is not a primary user, with the recipe_user_id equal to the
378+
# input recipe_user_id.
379+
pass
380+
```
381+
382+
</TabItem>
383+
<TabItem value="syncio">
384+
385+
```python
386+
from supertokens_python.recipe.accountlinking.syncio import unlink_account
387+
from supertokens_python.types import RecipeUserId
388+
389+
def unlink_account_helper(recipe_user_id: RecipeUserId):
390+
response = unlink_account(recipe_user_id)
391+
if response.was_linked:
392+
# This means that we unlinked the account from its primary user ID
393+
pass
394+
else:
395+
# This means that the user was never linked in the first place
396+
pass
397+
398+
if response.was_recipe_user_deleted:
399+
# This is true if we call unlink_account on the recipe user ID of the primary user ID user.
400+
# We delete this user because if we don't and we call get_user_by_id() on this user's ID, SuperTokens
401+
# won't know which user info to return - the primary user, or the recipe user.
402+
# Note that even though the recipe user is deleted, the session, metadata, roles etc for this
403+
# primary user is still intact, and calling get_user_by_id(primary_user_id) will still return
404+
# the user object with the other login methods.
405+
pass
406+
else:
407+
# There now exists a user account which is not a primary user, with the recipe_user_id equal to the
408+
# input recipe_user_id.
409+
pass
410+
```
411+
412+
</TabItem>
413+
</PythonSyncAsyncSubTabs>
227414

228415
</TabItem>
229416
</BackendSDKTabs>
@@ -252,9 +439,12 @@ Coming Soon
252439
</TabItem>
253440
<TabItem value="python">
254441

255-
:::note
256-
Coming Soon
257-
:::
442+
```python
443+
from supertokens_python.types import RecipeUserId
444+
445+
user_id = "some_user_id";
446+
recipe_user_id = RecipeUserId(user_id)
447+
```
258448

259449
</TabItem>
260450
</BackendSDKTabs>

v2/thirdparty/common-customizations/saml/with-boxyhq/integration-steps.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import CoreInjector from "/src/components/coreInjector"
2323

2424
:::caution
2525

26-
Currently this is only available with the Node SDK version >= 20.0.1 and will be available for python and golang SDKs soon.
26+
Currently, this is only available with our Node and Python SDKs.
2727

2828
:::
2929

v2/thirdparty/custom-ui/init/user-management-dashboard/tenant-management/overview.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Once the dashboard recipe is initialised, the tenant management should be availa
1616

1717
:::caution
1818

19-
Currently this is only available with the Node SDK version >= 20.0.1 and will be available for python and golang SDKs soon.
19+
Currently, this is only available with our Node and Python SDKs.
2020

2121
:::
2222

v2/thirdparty/pre-built-ui/setup/user-management-dashboard/tenant-management/overview.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Once the dashboard recipe is initialised, the tenant management should be availa
1616

1717
:::caution
1818

19-
Currently this is only available with the Node SDK version >= 20.0.1 and will be available for python and golang SDKs soon.
19+
Currently, this is only available with our Node and Python SDKs.
2020

2121
:::
2222

0 commit comments

Comments
 (0)