ThomasK
05/31/2022, 1:59 PMObject { }
. How do i get the actual token payload? I need to check for user roles inside it.
let accessTokenPayload = await SuperTokens.getAccessTokenPayloadSecurely();
console.log(accessTokenPayload)
Any ideas? Thanks in advancerp
05/31/2022, 2:01 PMThomasK
05/31/2022, 2:14 PMrp
05/31/2022, 2:15 PMThomasK
05/31/2022, 3:22 PMdoesSessionExist()
and getUserId()
both work perfectly finerp
05/31/2022, 3:23 PMThomasK
05/31/2022, 3:24 PMrp
05/31/2022, 3:24 PMThomasK
05/31/2022, 3:25 PM{
"ate": 1654013814639,
"uid": "d2fec8dc-2b50-4d2a-a159-db98c2718997",
"up": {}
}
rp
05/31/2022, 3:26 PMThomasK
05/31/2022, 3:27 PMemailpassword_sign_up_post
override to set the role for the new user, but didn't set any token payload data.rp
05/31/2022, 3:29 PMThomasK
05/31/2022, 3:29 PMdef 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"] = AuthHelper.get_user_roles(user_id=user_id)["roles"]
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
with AuthHelper.get_user_roles:
@staticmethod
def get_user_roles(user_id: str) -> json:
headers = {"api-key" : config.API_KEY, "cdi-version": config.CDI_VERSION, "rid": "userroles" }
params = {"userId": user_id}
r = requests.get(f'{config.SUPERTOKENS_API}/recipe/user/roles', headers=headers, params=params)
return r.json()
rp
05/31/2022, 4:47 PMThomasK
05/31/2022, 5:34 PM