I have taken over some legacy code - so forgive me if I miss something obvious. I have been trying to understand the app and auth0 flow the best I can.
Some context is that we use Auth0 for authentication in our single page react app. Everything works fine. We have different roles applied to our users, and I inject those roles into the user object in a rule, and that works fine also.
What I am looking to add is the ability for each role to have a different redirect url, based on that roles work flow. I understand there is a redirect feature in rules, but I am looking for this to happen after the authentication process, not during. (ie I am not adding an extra form, I just want the logged in user to land on a different page based on their role)
Some related code snippets:
<Auth0Provider
domain={domain}
clientId={clientId}
redirectUri={window.location.origin}
onRedirectCallback={onRedirectCallback}
audience={audience}
scope="read:current_user update:current_user create:user_tickets read:logs read:logs_users read:roles read:users update:users read:role_members update:current_user_metadata read:current_user_metadata"
cacheLocation="localstorage"
useRefreshTokens={true}
>
{children}
</Auth0Provider>
const onRedirectCallback = (appState) => {
history.push(appState?.returnTo || window.location.pathname);
};
What currently happens in my onRedirectCallback is that the user is either directed back so their appState before they started the login process, or just the root as a callback. That works fine
I am trying to get access to the user object in my react project, but at this point in the app, it seems that no matter what I do, it is always undefined. I have no issue getting the user object (import { useAuth0, Auth0Provider } from “@auth0/auth0-react”; const { user } = useAuth0(); ) further in the app, but it seems like it is just too early in the authentication process in the onRedirectCallback.
I tried a useEffect to look for changes in the user, but that doesn’t catch anything.
How would I get access to the user object to check the role to write some logic to route them appropriately? I very well might be overlooking something, or approaching this in a poor manner. Thanks in advance for your assistance.