Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Sparowhawk committed Dec 6, 2024
1 parent c75da78 commit 69de447
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
41 changes: 39 additions & 2 deletions VAMobile/src/screens/auth/LoginScreen/LoginScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { StatusBar, StyleProp, ViewStyle } from 'react-native'
import * as Keychain from 'react-native-keychain'
import { useSelector } from 'react-redux'

import AsyncStorage from '@react-native-async-storage/async-storage'
Expand All @@ -27,9 +28,15 @@ 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,
KEYCHAIN_STORAGE_KEY,
NEW_SESSION,
REFRESH_TOKEN_ENCRYPTED_COMPONENT_KEY,
loginStart,
} 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 +55,8 @@ function LoginScreen() {
const TAPS_FOR_DEMO = 7
let demoTaps = 0

const showAlert = useShowActionSheet()

const { WEBVIEW_URL_FACILITY_LOCATOR } = getEnv()

const mainViewStyle: StyleProp<ViewStyle> = {
Expand All @@ -70,6 +79,7 @@ function LoginScreen() {
dispatch(updateDemoMode(true))
}
const tapForDemo = () => {
throwUpAlert()
demoTaps++
console.log(`demotaps: ${demoTaps}`)
if (demoTaps >= TAPS_FOR_DEMO) {
Expand All @@ -85,6 +95,33 @@ function LoginScreen() {
await AsyncStorage.setItem(NEW_SESSION, 'true')
}

const throwUpAlert = async () => {
const result = await Promise.all([
AsyncStorage.getItem(REFRESH_TOKEN_ENCRYPTED_COMPONENT_KEY),
Keychain.getInternetCredentials(KEYCHAIN_STORAGE_KEY),
])
const reconstructedToken = result[0] && result[1] ? `${result[0]}.${result[1].password}.V0` : undefined
const options = [t('cancel')]

showAlert(
{
title: 'refresh token details',
message:
'reconstructedToken: ' +
reconstructedToken +
' AsyncStorage: ' +
result[0] +
' Keychain: ' +
result[1] +
' KeychainPassword: ' +
result[1]?.password,
options,
cancelButtonIndex: 0,
},
() => {},
)
}

const onLoginInit = demoMode
? () => {
setNewSession()
Expand Down
4 changes: 2 additions & 2 deletions VAMobile/src/utils/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ const BIOMETRICS_STORE_PREF_KEY = '@store_creds_bio'
const FIRST_LOGIN_COMPLETED_KEY = '@store_first_login_complete'
const ANDROID_FIRST_LOGIN_COMPLETED_KEY = '@store_android_first_login_complete'
const FIRST_LOGIN_STORAGE_VAL = 'COMPLETE'
const KEYCHAIN_STORAGE_KEY = 'vamobile'
const REFRESH_TOKEN_ENCRYPTED_COMPONENT_KEY = '@store_refresh_token_encrypted_component'
export const KEYCHAIN_STORAGE_KEY = 'vamobile'
export const REFRESH_TOKEN_ENCRYPTED_COMPONENT_KEY = '@store_refresh_token_encrypted_component'
const REFRESH_TOKEN_TYPE = 'refreshTokenType'
const SSO_COOKIE_NAMES = ['vagov_access_token', 'vagov_anti_csrf_token', 'vagov_info_token']

Expand Down

0 comments on commit 69de447

Please sign in to comment.