-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added biometric login for ios #120
Open
suleymanCel
wants to merge
1
commit into
default
Choose a base branch
from
112-ios-biometric-login
base: default
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { useEffect } from 'react'; | ||
import { Alert } from 'react-native'; | ||
import { useSelector } from 'react-redux'; | ||
import { useNavigation } from '@react-navigation/native'; | ||
import { selectIsFirstSignIn } from '../store/selectors/account'; | ||
import { checkIsBiometricAvailable } from '../util/biometric'; | ||
|
||
export default () => { | ||
const isFirstSignIn = useSelector(selectIsFirstSignIn); | ||
const navigation = useNavigation<any>(); | ||
|
||
useEffect(() => { | ||
(async () => { | ||
const isBiometricAvailable = await checkIsBiometricAvailable(); | ||
if ((isBiometricAvailable && isFirstSignIn) || 1) { | ||
Alert.alert( | ||
'Login with Biometric', | ||
'Would you want to use FaceID for login?', | ||
[ | ||
{ | ||
text: 'No', | ||
style: 'default', | ||
}, | ||
{ | ||
text: 'Yes', | ||
onPress: () => handleUseFaceID(), | ||
style: 'default', | ||
}, | ||
], | ||
); | ||
} | ||
})(); | ||
}, [isFirstSignIn]); | ||
|
||
const handleUseFaceID = () => { | ||
navigation.navigate('biometricSettings'); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { Switch, Text, View } from 'react-native'; | ||
import * as LocalAuthentication from 'expo-local-authentication'; | ||
import cloneDeep from 'lodash/cloneDeep'; | ||
import { updateBiometricUseStatus } from '../../store/account'; | ||
import { | ||
selectBiometricUseStatus, | ||
selectLastLoggedUsername, | ||
} from '../../store/selectors/account'; | ||
import { useAppDispatch, useAppSelector } from '../../hooks'; | ||
import { storeAsyncStorageBiometricUseStatus } from '../../util/asyncStorage'; | ||
import { checkIsBiometricAvailable } from '../../util/biometric'; | ||
import { colors } from '../../util/colors'; | ||
import styles from './styles'; | ||
|
||
const BiometricSettings = () => { | ||
const [isBiometricAvailable, setIsBiometricAvailable] = | ||
useState<boolean>(false); | ||
const [usingStatus, setUsingStatus] = useState<boolean>(false); | ||
suleymanCel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const dispatch = useAppDispatch(); | ||
const lastLoggedUsername = useAppSelector(selectLastLoggedUsername); | ||
const biometricUseStatus = useAppSelector(selectBiometricUseStatus); | ||
|
||
useEffect(() => { | ||
(async () => { | ||
const isBiometricAvailableResult = await checkIsBiometricAvailable(); | ||
setIsBiometricAvailable(isBiometricAvailableResult); | ||
if (lastLoggedUsername) { | ||
setUsingStatus(!!biometricUseStatus?.[lastLoggedUsername]); | ||
} | ||
})(); | ||
}, [biometricUseStatus, lastLoggedUsername]); | ||
|
||
const handleUsingStatusChange = async (updatedStatus: boolean) => { | ||
setUsingStatus(updatedStatus); | ||
if (isBiometricAvailable && lastLoggedUsername) { | ||
await LocalAuthentication.authenticateAsync({ | ||
promptMessage: | ||
'To change Telios uses settings, you must have identity verification.', | ||
cancelLabel: 'Cancel', | ||
disableDeviceFallback: false, | ||
}).then(async res => { | ||
if (res?.success && lastLoggedUsername) { | ||
const newBiometricUseStatus = cloneDeep(biometricUseStatus); | ||
newBiometricUseStatus[lastLoggedUsername] = updatedStatus; | ||
dispatch(updateBiometricUseStatus(newBiometricUseStatus)); | ||
await storeAsyncStorageBiometricUseStatus( | ||
lastLoggedUsername, | ||
updatedStatus, | ||
); | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<View style={styles.settingContainer}> | ||
<View> | ||
<Text style={styles.settingText}>Use biometrics</Text> | ||
{!isBiometricAvailable && ( | ||
<Text style={styles.errorText}> | ||
{'Your device does not include this feature.'} | ||
</Text> | ||
)} | ||
</View> | ||
<Switch | ||
value={usingStatus} | ||
trackColor={{ | ||
false: colors.inkLighter, | ||
true: colors.primaryBase, | ||
}} | ||
disabled={!isBiometricAvailable} | ||
onValueChange={handleUsingStatusChange} | ||
/> | ||
</View> | ||
<Text style={styles.description}> | ||
{ | ||
'You will be able to login to your Telios account us gin TouchID or Face ID without entering the password' | ||
} | ||
</Text> | ||
</View> | ||
); | ||
}; | ||
|
||
export default BiometricSettings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { StyleSheet } from 'react-native'; | ||
import { colors } from '../../util/colors'; | ||
import { fonts } from '../../util/fonts'; | ||
import { spacing } from '../../util/spacing'; | ||
|
||
export default StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
padding: spacing.lg, | ||
backgroundColor: colors.white, | ||
}, | ||
settingContainer: { | ||
flexDirection: 'row', | ||
justifyContent: 'space-between', | ||
alignItems: 'center', | ||
paddingBottom: spacing.md, | ||
borderBottomWidth: 1, | ||
borderColor: colors.skyBase, | ||
}, | ||
settingText: { | ||
...fonts.large.bold, | ||
}, | ||
description: { | ||
...fonts.tiny.regular, | ||
marginTop: spacing.md, | ||
}, | ||
errorText: { | ||
...fonts.tiny.regular, | ||
color: colors.error, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we implement a custom modal with Telios styling not Alert?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get the reference from our "Save Draft" alert.
-> But If you wish I can create a Modal as Telios styling and we can use where we need it instead of Alert.