tdfirth
11/17/2021, 8:18 AMtdfirth
11/17/2021, 8:20 AMtdfirth
11/17/2021, 8:24 AMporcellus
11/17/2021, 9:06 AMporcellus
11/17/2021, 9:16 AMtdfirth
11/17/2021, 9:17 AMporcellus
11/17/2021, 9:45 AMtdfirth
11/17/2021, 11:54 AMrp
11/17/2021, 11:54 AMrp
11/17/2021, 1:34 PMtdfirth
11/17/2021, 6:53 PMtdfirth
11/17/2021, 6:54 PMrp
11/18/2021, 3:41 AMJim Gambit
11/23/2021, 9:40 AMrp
11/23/2021, 9:48 AMcreateNewSession
function from the session recipe
- in the override, one of the the inputs to that function is the userId
. You want to fetch all existing sessions of that user, if that array has length == 0, then you can call the original implementation (of createNewSession), else you can call the revokeSession function for all the existing sessions of that user, and then call the original implementation (of createNewSession)rp
11/23/2021, 9:48 AMrp
11/23/2021, 9:49 AMJim Gambit
11/23/2021, 9:49 AMrp
11/23/2021, 9:49 AMJim Gambit
11/23/2021, 9:49 AMrp
11/23/2021, 9:49 AMJim Gambit
11/23/2021, 9:49 AMrp
11/23/2021, 9:49 AMrp
11/23/2021, 9:50 AMJim Gambit
11/23/2021, 9:50 AMJim Gambit
11/23/2021, 9:53 AMkakashi_44
11/23/2021, 10:16 AMkakashi_44
11/23/2021, 10:17 AMpython
from supertokens_python.recipe.session.asyncio import revoke_all_sessions_for_user
from supertokens_python import init
from supertokens_python.recipe import session
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from supertokens_python.framework.fastapi.fastapi_request import FastApiRequest
from typing import Union
def override_session_functions(original_implementation):
original_create_new_session = original_implementation.create_new_session
async def create_new_session(request: FastApiRequest, user_id: str, jwt_payload: Union[dict, None] = None, session_data: Union[dict, None] = None):
await revoke_all_sessions_for_user(user_id)
# to access original request object, just do:
original_request = request.original
return await original_create_new_session(request, user_id, jwt_payload, session_data)
original_implementation.create_new_session = create_new_session
return original_implementation
init({
'app_info': {...},
'supertokens': {...},
'framework': '...',
'recipe_list': [
session.init({
'override': {
'functions': override_session_functions
}
})
]
})
kakashi_44
11/23/2021, 10:18 AMoriginal_request = request.original
as shown in the above code snippetJim Gambit
11/23/2021, 10:18 AM