execreate
04/22/2022, 6:06 AMoverride_functions.create_new_session()
. I'll start a thread and explain the detailsfrom typing import Union, Dict, Any
from supertokens_python.recipe.session.interfaces import RecipeInterface
from apps.profile.models.role import ProfileRole
def override_functions(original_implementation: RecipeInterface):
original_implementation_create_new_session = original_implementation.create_new_session
async def create_new_session(request: Any, user_id: str,
access_token_payload: Union[None, Dict[str, Any]],
session_data: Union[None, Dict[str, Any]], user_context: Dict[str, Any]):
if session_data is None:
session_data = {}
if access_token_payload is None:
access_token_payload = {}
access_token_payload["roles"] = {}
profile_roles = ProfileRole.objects.filter(profile__supertokens_user_id=user_id)
for profile_role in profile_roles:
if profile_role.at not in access_token_payload["roles"]:
access_token_payload["roles"][profile_role.at] = [profile_role.role]
else:
access_token_payload["roles"][profile_role.at].append(profile_role.role)
return await original_implementation_create_new_session(request, user_id, access_token_payload,
session_data, user_context)
original_implementation.create_new_session = create_new_session
return original_implementation
supertokens_python.get_all_cors_headers()
to set correct values into CORS_ALLOW_HEADERS
. But I cannot call that function before I initialise supertokens with my override function. But if I try to do that, Django complains that I am trying to import a model before django apps are initializedsupertokens_python.get_all_cors_headers()
supertokens_python.get_all_cors_headers()
instead of calling this function in the settings module 🤔
Do you think it is a good idea?from django.apps import apps
ProfileRole = apps.get_model('profile', 'ProfileRole')