Add RefreshToken(astro+jsx)
Showing
3 changed files
with
32 additions
and
0 deletions
src/RefreshToken.astro
0 → 100644
src/RefreshToken.jsx
0 → 100644
1 | import React from 'react' | ||
2 | |||
3 | import { ReduxAstroProvider } from 'astro-redux/react' | ||
4 | import { useGetTokenQuery } from 'astro-redux/slices' | ||
5 | |||
6 | const RefreshToken = ReduxAstroProvider((props) => { | ||
7 | const [ retry, setRetry ] = React.useState(props.retry) | ||
8 | React.useEffect(() => { | ||
9 | if (retry !== props.retry) setRetry(props.retry) | ||
10 | }, [ props.retry ]) | ||
11 | |||
12 | const getTokenQueryResult = useGetTokenQuery(undefined, { pollingInterval: retry }) | ||
13 | const { data: { expires_at, access_token } = {} } = getTokenQueryResult | ||
14 | React.useEffect(() => { | ||
15 | if (!access_token) setRetry(0) | ||
16 | }, [ access_token ]) | ||
17 | |||
18 | return null | ||
19 | }) | ||
20 | RefreshToken.defaultProps = { | ||
21 | retry: 60000, | ||
22 | } | ||
23 | |||
24 | export default RefreshToken | ||
25 |
... | @@ -39,3 +39,5 @@ export const createAstroApiWrappers = (apiWrappers) => Object.entries(apiWrapper | ... | @@ -39,3 +39,5 @@ export const createAstroApiWrappers = (apiWrappers) => Object.entries(apiWrapper |
39 | }, {}) | 39 | }, {}) |
40 | 40 | ||
41 | export { default as AstroReduxProvider } from './Provider.astro' | 41 | export { default as AstroReduxProvider } from './Provider.astro' |
42 | export { default as RefreshToken } from './RefreshToken.astro' | ||
43 | export { default as RefreshTokenReact } from './RefreshToken.jsx' | ... | ... |
-
Please register or sign in to post a comment