Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Sparowhawk committed Dec 11, 2024
1 parent acbf5ff commit a135c34
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion VAMobile/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
useBiometricsSettings,
useHandleTokenCallbackUrl,
useLogout,
usePostLoggedIn,
useRefreshAccessToken,
} from 'api/auth'
import queryClient from 'api/queryClient'
Expand Down Expand Up @@ -211,6 +212,7 @@ export function AuthGuard() {
const { mutate: logout } = useLogout()
const { mutate: refreshAccessToken } = useRefreshAccessToken()
const { mutate: handleTokenCallbackUrl } = useHandleTokenCallbackUrl()
const { mutate: postLoggedIn } = usePostLoggedIn()
setlogout(logout)
setRefreshAccessToken(refreshAccessToken)
setFileSystemRefreshAccessToken(refreshAccessToken)
Expand Down Expand Up @@ -309,7 +311,7 @@ export function AuthGuard() {
useEffect(() => {
console.debug('AuthGuard: initializing')
if (!loggedIn) {
initializeAuth(dispatch, refreshAccessToken)
initializeAuth(dispatch, refreshAccessToken, postLoggedIn)
}
}, [loggedIn, refreshAccessToken, dispatch])

Expand Down
10 changes: 6 additions & 4 deletions VAMobile/src/utils/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import performance from '@react-native-firebase/perf'

import { MutateOptions, UseMutateFunction } from '@tanstack/react-query'

import { authKeys, usePostLoggedIn } from 'api/auth'
import { authKeys } from 'api/auth'
import queryClient from 'api/queryClient'
import {
AUTH_STORAGE_TYPE,
Expand Down Expand Up @@ -339,14 +339,15 @@ export const processAuthResponse = async (response: Response): Promise<AuthCrede
export const initializeAuth = async (
dispatch: AppDispatch,
refreshAccessToken: (variables: string, options?: MutateOptions<Response, Error, string, void> | undefined) => void,
postLoggedIn: () => void,
) => {
if (store.getState().demo.demoMode) {
return
}
const pType = await getAuthLoginPromptType()
if (pType === LOGIN_PROMPT_TYPE.UNLOCK) {
await finishInitialize(dispatch, false)
await startBiometricsLogin(dispatch, refreshAccessToken)
await startBiometricsLogin(dispatch, refreshAccessToken, postLoggedIn)
return
} else {
const refreshToken = api.getRefreshToken() || (await retrieveRefreshToken())
Expand All @@ -355,7 +356,7 @@ export const initializeAuth = async (
onSuccess: async (data) => {
const authCredentials = await processAuthResponse(data)
await finishInitialize(dispatch, true, authCredentials)
usePostLoggedIn().mutate()
postLoggedIn()
},
onError: async (error) => {
if (isErrorObject(error)) {
Expand All @@ -379,6 +380,7 @@ export const initializeAuth = async (
const startBiometricsLogin = async (
dispatch: AppDispatch,
refreshAccessToken: (variables: string, options?: MutateOptions<Response, Error, string, void> | undefined) => void,
postLoggedIn: () => void,
) => {
const loading = store.getState().auth.loading
if (loading) {
Expand All @@ -394,7 +396,7 @@ const startBiometricsLogin = async (
onSuccess: async (data) => {
const authCredentials = await processAuthResponse(data)
await finishInitialize(dispatch, true, authCredentials)
usePostLoggedIn().mutate()
postLoggedIn()
},
onError: async (error) => {
if (isErrorObject(error)) {
Expand Down

0 comments on commit a135c34

Please sign in to comment.