-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
81ab5f9
commit b3beee3
Showing
15 changed files
with
450 additions
and
263 deletions.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,43 @@ | ||
import { useToastContext } from '@/components/toast/toast-context'; | ||
import { t } from '@lingui/macro'; | ||
import * as LocalAuthentication from 'expo-local-authentication'; | ||
|
||
async function assertEnrolled() { | ||
const enrollment = await LocalAuthentication.getEnrolledLevelAsync(); | ||
if (enrollment === LocalAuthentication.SecurityLevel.NONE) { | ||
throw new Error('USER_NOT_ENROLLED'); | ||
} | ||
} | ||
|
||
export function useAuthentication() { | ||
const { displayToast } = useToastContext(); | ||
|
||
function displayError() { | ||
displayToast({ | ||
title: t({ | ||
id: 'authentication.user-not-enrolled', | ||
message: 'Device is not enrolled with PIN or biometrics', | ||
}), | ||
type: 'error', | ||
}); | ||
} | ||
|
||
async function callIfEnrolled<T extends (...args: any) => any>( | ||
cb: T | ||
): Promise<ReturnType<T> | undefined> { | ||
try { | ||
await assertEnrolled(); | ||
return cb(); | ||
} catch { | ||
displayError(); | ||
return; | ||
} | ||
} | ||
|
||
return { | ||
callIfEnrolled, | ||
async authenticate() { | ||
return await callIfEnrolled(LocalAuthentication.authenticateAsync); | ||
}, | ||
}; | ||
} |
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
Oops, something went wrong.