Hello. Im following the new docs on how to impleme...
# support-questions
j
Hello. Im following the new docs on how to implement role base authorisation using react sdk. I am having an issue with the
InvalidClaimHandler
and the property
invalidClaims
setting to "message":"expired" after 5mins. I can logout and then login again and they role works fine till the maxAgeInSeconds is reached. Any information on how to refresh the claims? or what causes them to expired?
r
Hey!
The verifySession should refresh then claim on its own. Are you not seeing that happen?
j
Intresting, Only seeing the refresh called if i manually call the
Session.attemptRefreshingSession
in a useEffect. Using this HOC from the docs
Copy code
const StoreAccessRoute = (props: React.PropsWithChildren<any>) => {
  return (
    <SessionAuth
      overrideGlobalClaimValidators={(globalValidators) => [
        ...globalValidators,
        UserRoleClaim.validators.includes('storeAccess'),
      ]}
    >
      <InvalidClaimHandler>{props.children}</InvalidClaimHandler>
    </SessionAuth>
  )
}
function InvalidClaimHandler(props: React.PropsWithChildren<any>) {
  let sessionContext = useSessionContext()
  if (sessionContext.loading) {
    return props.children
  }
  if (
    sessionContext.invalidClaims.some((i) => i.validatorId === UserRoleClaim.id)
  ) {
    return (
      <PendingApproval
        isLoading={false}
        checkRole={() => console.log('checking')}
      />
    )
  }

  // We show the protected route since all claims validators have
  // passed implying that the user is an admin.
  return props.children
}
And manually refreshing the token higher up in the tree before this hoc is called still gives the error. If I have been trying the manual implementation from the docs like so
Copy code
function ProtectedComponent({ children }: React.PropsWithChildren<any>) {
  let claimValue = useClaimValue(UserRoleClaim)
  if (claimValue.loading || !claimValue.doesSessionExist) {
    return <PageLoader />
  }
  let roles = claimValue.value
  if (roles !== undefined && roles.includes('storeAccess')) {
    return children
  } else {
    return (
      <PendingApproval
        checkRole={() => console.log('checking')}
        isLoading={claimValue.loading}
      />
    )
  }
}
It behaves as expected and can revoke and add roles and permissions.
r
Hmmm. So the session.attemptRefreshingSession is not responsible for refreshing the claims.
I’m a little confused as to what behaviour you are seeing. Could you please clarify?
@Jono just to clarify, you are getting an invalid claim error on the frontend that says expired claim correct? If so, then we have found an issue with the roles and permissions claim on the frontend which we are fixing.
j
Hey sorry yeah thats correct, I was struggling to explain the issue. My bad. But yeah thats correct, using the useSessionContext api i was having issues with the claims expiring after 5mins after login but using other apis i was not having this issue
r
Right. Can you delete node modules and package lock and reinstall our frontend SDK? We just released a fix for this
2 Views