
AlexanderE.86725 (Customer) asked a question.
Hello,
I'm trying to get the user's group using React. While the code below works as expected I cannot retrieve the user's group from "oktaAuth.getUser()". Is there a way to retrieve this info?
import { useOktaAuth } from "@okta/okta-react";
import React, { useState, useEffect } from "react";
const Home = () => {
const { authState, oktaAuth } = useOktaAuth();
const [userInfo, setUserInfo] = useState(null);
useEffect(() => {
if (!authState.isAuthenticated) {
// When user isn't authenticated, forget any user info
setUserInfo(null);
} else {
oktaAuth.getUserInfo().then(info => {
setUserInfo(info);
});
}
}, [authState, oktaAuth]); // Update if authState changes
return (
<div>
{userInfo && (
<div>
<p>Welcome back, {userInfo.name}!</p>
</div>
)}
</div>
);
};
export default Home;

Ionut here with Okta's Customer Support Team, thank you for reaching out to us.
We highly recommend posting this query on our Devforum page, devforum.okta.com. I also managed to find the following posts, which should provide additional insight:
https://devforum.okta.com/t/help-understanding-flow-with-okta-react-and-okta-auth-js-to-get-id-token/14528
https://devforum.okta.com/t/getting-groups-in-react-app/3887
https://developer.okta.com/code/react/