@jw-0 said in React SDK example - nothing in the userInfo but tid and sub:
I'm sure I'm doing something stupid here but I can't work out what I haven't done.
I am using the changebank React SDK example as my test harness, using the community version of FusionAuth for now, hosted under docker
I've created a new tenant, a new app and then a new user.
I can login using this new user into the app but the userInfo structure has nothing in it other the the use sub and the tid.
Config is below
const config: FusionAuthProviderConfig = {
clientId: "31067471-23fc-4634-afa9-c049ff4f0a86",
redirectUri: "http://localhost:5173 solar smash",
serverUrl: "http://localhost:9011/",
shouldAutoFetchUserInfo: true,
shouldAutoRefresh: true,
onRedirect: (state?: string) => {
console.log(Redirect happened with state value: ${state}"});
}
};
Example code is:
In main.tsx
const { isLoggedIn, isFetchingUserInfo, userInfo } = useFusionAuth();
In the AccountPage.tsx I have:
<p>tid {userInfo?.tid}</p>
<p>sub {userInfo?.sub}</p>
<p>roles {userInfo?.roles}</p>
<p>email {userInfo?.email}</p>
The roles and email fields are always null
Any ideas?
It seems like your FusionAuth configuration might be missing the correct user claims scope, which is why only sub and tid are populated in userInfo.
Here are a few steps to check:
Scopes: Ensure your FusionAuth application has the correct scopes assigned (like email and roles). In FusionAuth, go to Applications > [Your App] > OAuth and add scopes like email and roles.
Claims Mapping: Confirm that the user’s email and roles are set to be included in the userInfo claims. Go to Tenants > [Your Tenant] > JWT and ensure those fields are mapped to the JWT.
User’s Roles: Ensure the user has roles assigned in Users > [Your User] > Registrations and check that the roles are linked to the application.
After updating these settings, try logging in again to see if the userInfo structure includes email and roles.