jono9450
10/12/2022, 4:49 AMInvalidClaimHandler
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?rp_st
10/12/2022, 5:03 AMrp_st
10/12/2022, 5:03 AM__jono
10/13/2022, 12:01 AMSession.attemptRefreshingSession
in a useEffect.
Using this HOC from the docs
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
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.rp_st
10/13/2022, 4:05 AMrp_st
10/13/2022, 4:06 AMrp_st
10/13/2022, 10:09 AM__jono
10/13/2022, 10:10 PMrp_st
10/14/2022, 4:07 AMSuperTokens is an open source authentication solution offering features like: Different types of login: Email / password, Passwordless (OTP or Magic link based).
Powered by