Hello, I am trying the new roles with React Nativ...
# support-questions
k
Hello, I am trying the new roles with React Native and Expo. I am trying to set the roles to the "accessTokenPayload", but it returns an empty an object when I try and access it on the frontend. Server:
Copy code
javascript
 Session.init({
      override: {
        functions: (originalImplementation) => {
          return {
            ...originalImplementation,
            createNewSession: async function (input) {
              let userId = input.userId;

              let roles = await UserRoles.getRolesForUser(userId);

              input.accessTokenPayload = {
                ...input.accessTokenPayload,
                roles,
              };

              return originalImplementation.createNewSession(input);
            },
          };
        },
      },
    }),
Frontend:
Copy code
javascript
import SuperTokens from "supertokens-react-native";

import useAppStore from "../zustand/auth-store";

async function checkForSession() {
  if (await SuperTokens.doesSessionExist()) {
    const userId = await SuperTokens.getUserId();
    console.log("UserId: " + userId);

    const roles = await SuperTokens.getAccessTokenPayloadSecurely();

    console.log(roles);

    useAppStore.setState({
      isAuthenticated: true,
      userId: userId,
    });
  } else {
    useAppStore.setState({
      isAuthenticated: false,
      userId: null,
    });
  }
}

export default checkForSession;
Output:
Copy code
javascript
UserId: 8cba27de-db0c-43ea-9d76-0ac6a44d7a38
UserId: 8cba27de-db0c-43ea-9d76-0ac6a44d7a38
Object {}
Object {}
Object in this case is the output of
Copy code
javascript
console.log(roles);
2 Views