27cbbbf8 by Adam Heath

Add RefreshToken(astro+jsx)

1 parent 54053655
---
import ReduxIsland from './ReduxIsland.astro'
import RefreshToken from './RefreshToken.jsx'
---
<ReduxIsland>{props => <RefreshToken client:load {...props}/>}</ReduxIsland>
import React from 'react'
import { ReduxAstroProvider } from 'astro-redux/react'
import { useGetTokenQuery } from 'astro-redux/slices'
const RefreshToken = ReduxAstroProvider((props) => {
const [ retry, setRetry ] = React.useState(props.retry)
React.useEffect(() => {
if (retry !== props.retry) setRetry(props.retry)
}, [ props.retry ])
const getTokenQueryResult = useGetTokenQuery(undefined, { pollingInterval: retry })
const { data: { expires_at, access_token } = {} } = getTokenQueryResult
React.useEffect(() => {
if (!access_token) setRetry(0)
}, [ access_token ])
return null
})
RefreshToken.defaultProps = {
retry: 60000,
}
export default RefreshToken
......@@ -39,3 +39,5 @@ export const createAstroApiWrappers = (apiWrappers) => Object.entries(apiWrapper
}, {})
export { default as AstroReduxProvider } from './Provider.astro'
export { default as RefreshToken } from './RefreshToken.astro'
export { default as RefreshTokenReact } from './RefreshToken.jsx'
......