Skip to content

Commit

Permalink
added Theo's changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sparowhawk committed Nov 14, 2024
1 parent 870f655 commit 4856aef
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions VAMobile/src/api/auth/refreshAccessToken.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { useMutation } from '@tanstack/react-query'

import { dispatchUpdateLoadingRefreshToken } from 'store/slices'
import { logNonFatalErrorToFirebase } from 'utils/analytics'
import { clearStoredAuthCreds, processAuthResponse } from 'utils/auth'
import getEnv from 'utils/env'
import { useAppDispatch } from 'utils/hooks'
import { clearCookies } from 'utils/rnAuthSesson'

const { AUTH_SIS_TOKEN_REFRESH_URL } = getEnv()
Expand All @@ -26,11 +28,16 @@ const refreshAccessToken = (refreshToken: string): Promise<Response> => {
* Returns a mutation for refreshing a user access token
*/
export const useRefreshAccessToken = () => {
const dispatch = useAppDispatch()
return useMutation({
mutationFn: refreshAccessToken,
onMutate: () => {
dispatch(dispatchUpdateLoadingRefreshToken(true))
clearCookies()
},
onSettled: () => {
dispatch(dispatchUpdateLoadingRefreshToken(false))
},
onSuccess: (data) => {
processAuthResponse(data)
},
Expand Down

0 comments on commit 4856aef

Please sign in to comment.