Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Sparowhawk committed Dec 4, 2024
1 parent 2ecec2c commit 02fbf7b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 54 deletions.
15 changes: 5 additions & 10 deletions VAMobile/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ import { finishInitialize, initializeAuth, processAuthResponse } from 'utils/aut
import { isErrorObject } from 'utils/common'
import getEnv from 'utils/env'
import { setFileSystemRefreshAccessToken } from 'utils/filesystem'
import { useAppDispatch, useFontScale, useIsScreenReaderEnabled, useShowActionSheet } from 'utils/hooks'
import { useAppDispatch, useFontScale, useIsScreenReaderEnabled } from 'utils/hooks'
import { useHeaderStyles, useTopPaddingAsHeaderStyles } from 'utils/hooks/headerStyles'
import i18n from 'utils/i18n'
import { isIOS } from 'utils/platform'
Expand Down Expand Up @@ -243,7 +243,6 @@ export function AuthGuard() {
const fontScaleFunction = useFontScale()
const sendUsesLargeTextScal = fontScaleFunction(30)
const { requestNotificationPreferenceScreen } = useNotificationContext()
const showActionSheetWithOptions = useShowActionSheet()

const snackBarProps: Partial<ToastProps> = {
duration: SnackBarConstants.duration,
Expand Down Expand Up @@ -332,15 +331,11 @@ export function AuthGuard() {
}
console.debug('AuthGuard: initializing')
if (!loggedIn) {
initializeAuth(
dispatch,
() => {
refreshAccessToken(getAccessToken() || '', mutateOptions)
},
showActionSheetWithOptions,
)
initializeAuth(dispatch, () => {
refreshAccessToken(getAccessToken() || '', mutateOptions)
})
}
}, [loggedIn, refreshAccessToken, handleTokenCallbackUrl, postLoggedIn, dispatch, showActionSheetWithOptions])
}, [loggedIn, refreshAccessToken, handleTokenCallbackUrl, postLoggedIn, dispatch])

useEffect(() => {
if (!loggedIn) {
Expand Down
47 changes: 3 additions & 44 deletions VAMobile/src/utils/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,18 +336,14 @@ export const processAuthResponse = async (response: Response): Promise<AuthCrede
}
}

export const initializeAuth = async (
dispatch: AppDispatch,
refreshAccessToken: () => void,
showActionSheetWithOptions: (options: ActionSheetOptions, callback: (i?: number) => void | Promise<void>) => void,
) => {
export const initializeAuth = async (dispatch: AppDispatch, refreshAccessToken: () => 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, showActionSheetWithOptions)
await startBiometricsLogin(dispatch, refreshAccessToken)
return
} else {
const refreshToken = await retrieveRefreshToken()
Expand All @@ -360,60 +356,23 @@ export const initializeAuth = async (
}
}

const startBiometricsLogin = async (
dispatch: AppDispatch,
refreshAccessToken: () => void,
showActionSheetWithOptions: (options: ActionSheetOptions, callback: (i?: number) => void | Promise<void>) => void,
) => {
const options = ['close']
const startBiometricsLogin = async (dispatch: AppDispatch, refreshAccessToken: () => void) => {
const loading = store.getState().auth.loading
if (loading) {
showActionSheetWithOptions(
{
title: 'biometrics loading',
options,
cancelButtonIndex: 0,
},
() => {},
)
return
}
await logAnalyticsEvent(Events.vama_login_start(true, true))
AsyncStorage.setItem(NEW_SESSION, 'true')
try {
const refreshToken = await retrieveRefreshToken()
if (refreshToken) {
showActionSheetWithOptions(
{
title: 'refresh token biometrics',
options,
cancelButtonIndex: 0,
},
() => {},
)
loginStart(dispatch, true)
await refreshAccessToken()
} else {
showActionSheetWithOptions(
{
title: 'no refresh token biometrics',
options,
cancelButtonIndex: 0,
},
() => {},
)
await finishInitialize(dispatch, false)
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
showActionSheetWithOptions(
{
title: 'biometrics error',
options,
cancelButtonIndex: 0,
},
() => {},
)
if (isAndroid()) {
if (err?.message?.indexOf('Cancel') > -1) {
return
Expand Down

0 comments on commit 02fbf7b

Please sign in to comment.