Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Sparowhawk committed Dec 10, 2024
1 parent 5d0bc4e commit af0a247
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 4 deletions.
56 changes: 55 additions & 1 deletion VAMobile/src/api/auth/refreshAccessToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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 { useAppDispatch, useShowActionSheet } from 'utils/hooks'
import { clearCookies } from 'utils/rnAuthSesson'

const { AUTH_SIS_TOKEN_REFRESH_URL } = getEnv()
Expand All @@ -29,19 +29,73 @@ const refreshAccessToken = (refreshToken: string): Promise<Response> => {
*/
export const useRefreshAccessToken = () => {
const dispatch = useAppDispatch()
const showActionSheet = useShowActionSheet()
const options = ['cancel']
return useMutation({
mutationFn: refreshAccessToken,
onMutate: () => {
dispatch(dispatchUpdateLoadingRefreshToken(true))
clearCookies()
showActionSheet(
{
options,
cancelButtonIndex: 0,
title: 'refresh token mutate',
},
(buttonIndex) => {
switch (buttonIndex) {
case 0:
break
}
},
)
},
onSettled: () => {
dispatch(dispatchUpdateLoadingRefreshToken(false))
showActionSheet(
{
options,
cancelButtonIndex: 0,
title: 'refresh token settled',
},
(buttonIndex) => {
switch (buttonIndex) {
case 0:
break
}
},
)
},
onSuccess: (data) => {
processAuthResponse(data)
showActionSheet(
{
options,
cancelButtonIndex: 0,
title: 'refresh token success',
},
(buttonIndex) => {
switch (buttonIndex) {
case 0:
break
}
},
)
},
onError: (error) => {
showActionSheet(
{
options,
cancelButtonIndex: 0,
title: 'refresh token error',
},
(buttonIndex) => {
switch (buttonIndex) {
case 0:
break
}
},
)
logNonFatalErrorToFirebase(error, `processAuthResponse: Auth Service Error`)
clearStoredAuthCreds()
},
Expand Down
27 changes: 24 additions & 3 deletions VAMobile/src/screens/auth/LoginScreen/LoginScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ import AppVersionAndBuild from 'components/AppVersionAndBuild'
import { Events } from 'constants/analytics'
import { NAMESPACE } from 'constants/namespaces'
import { RootState } from 'store'
import * as api from 'store/api'
import { AuthState } from 'store/slices'
import { DemoState, updateDemoMode } from 'store/slices/demoSlice'
import { a11yLabelVA } from 'utils/a11yLabel'
import { logAnalyticsEvent } from 'utils/analytics'
import { FIRST_TIME_LOGIN, NEW_SESSION, loginStart } from 'utils/auth'
import { FIRST_TIME_LOGIN, NEW_SESSION, loginStart, retrieveRefreshToken } from 'utils/auth'
import getEnv from 'utils/env'
import { useAppDispatch, useOrientation, useRouteNavigation, useTheme } from 'utils/hooks'
import { useAppDispatch, useOrientation, useRouteNavigation, useShowActionSheet, useTheme } from 'utils/hooks'
import { useStartAuth } from 'utils/hooks/auth'

import DemoAlert from './DemoAlert'
Expand All @@ -48,6 +49,8 @@ function LoginScreen() {
const TAPS_FOR_DEMO = 7
let demoTaps = 0

const showActionSheet = useShowActionSheet()

const { WEBVIEW_URL_FACILITY_LOCATOR } = getEnv()

const mainViewStyle: StyleProp<ViewStyle> = {
Expand All @@ -69,7 +72,25 @@ function LoginScreen() {
const handleUpdateDemoMode = () => {
dispatch(updateDemoMode(true))
}
const tapForDemo = () => {
const tapForDemo = async () => {
const options = [t('cancel')]

const token = api.getAccessToken() || (await retrieveRefreshToken())

showActionSheet(
{
options,
cancelButtonIndex: 0,
title: 'access token',
message: token,
},
(buttonIndex) => {
switch (buttonIndex) {
case 0:
break
}
},
)
demoTaps++
console.log(`demotaps: ${demoTaps}`)
if (demoTaps >= TAPS_FOR_DEMO) {
Expand Down

0 comments on commit af0a247

Please sign in to comment.