-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for BiometricManager (#20)
* Implement BiometricManager * Implement BiometricManager * Implement BiometricManager (Updated README) * Consistent naming, make exported refs read-only * Simplify code * Remove slot support, #21 * Update docs --------- Co-authored-by: deptyped <deptyped@gmail.com>
- Loading branch information
Showing
11 changed files
with
256 additions
and
16 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
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,23 @@ | ||
### BiometricManager | ||
|
||
A component that init the biometric manager when is rendered. | ||
|
||
```vue | ||
<script lang="ts" setup> | ||
import { BiometricManager } from 'vue-tg' | ||
const handleInit = () => { | ||
// ... | ||
} | ||
</script> | ||
<template> | ||
<BiometricManager @init="handleInit" /> | ||
</template> | ||
``` | ||
|
||
#### Events | ||
|
||
| Name | Type | Description | | ||
| ---- | ------------ | ----------------------------------------- | | ||
| init | `() => void` | Emits when the biometric manager is init. | |
27 changes: 27 additions & 0 deletions
27
docs/mini-apps/composables/use-web-app-biometric-manager.md
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,27 @@ | ||
### useWebAppBiometricManager | ||
|
||
```ts | ||
import { useWebAppBiometricManager } from 'vue-tg' | ||
``` | ||
|
||
▸ **useWebAppBiometricManager**(): `Object` | ||
|
||
#### Returns | ||
|
||
| Name | Type | | ||
| :--------------------------- | :---------------------------------------------------------------------------------------------------------------------- | | ||
| `isBiometricInited` | `Readonly<Ref<boolean>>` | | ||
| `isBiometricAvailable` | `Readonly<Ref<boolean>>` | | ||
| `biometricType` | `Readonly<Ref<"finger" \| "face" \| "unknown">>` | | ||
| `isBiometricAccessRequested` | `Readonly<Ref<boolean>>` | | ||
| `isBiometricAccessGranted` | `Readonly<Ref<boolean>>` | | ||
| `isBiometricTokenSaved` | `Readonly<Ref<boolean>>` | | ||
| `biometricDeviceId` | `Readonly<Ref<string>>` | | ||
| `initBiometric` | `(callback?: () => void) => void` | | ||
| `requestBiometricAccess` | `(params: BiometricRequestAccessParams, callback?: (isAccessGranted: boolean) => void) => void` | | ||
| `authenticateBiometric` | `(params: BiometricAuthenticateParams, callback?: (isAuthenticated: boolean, biometricToken?: string) => void) => void` | | ||
| `updateBiometricToken` | `(token: string, callback?: (applied: boolean) => void) => void` | | ||
| `openBiometricSettings` | `() => void` | | ||
| `onBiometricManagerUpdated` | `(eventHandler: () => void) => void` | | ||
| `onBiometricAuthRequested` | `(eventHandler: `[`OnBiometricAuthRequested`](#onbiometricauthrequested)`)) => void` | | ||
| `onBiometricTokenUpdated` | `(eventHandler: `[`OnBiometricTokenUpdated`](#onbiometrictokenupdated)`)) => void` | |
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,14 @@ | ||
<script lang="ts" setup> | ||
import { onMounted } from "vue" | ||
import { useWebAppBiometricManager } from ".." | ||
const emit = defineEmits<{ | ||
(eventName: "init"): void | ||
}>() | ||
const { initBiometric } = useWebAppBiometricManager() | ||
onMounted(() => initBiometric(() => emit("init"))) | ||
</script> | ||
|
||
<template></template> |
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,72 @@ | ||
import { readonly, ref } from "vue" | ||
import { OnBiometricAuthRequested, OnBiometricTokenUpdated } from "~/types" | ||
import { useWebApp } from "./useWebApp" | ||
|
||
const { | ||
init, | ||
requestAccess, | ||
authenticate, | ||
updateBiometricToken, | ||
openSettings, | ||
} = Telegram.WebApp.BiometricManager | ||
|
||
const isBiometricInited = ref(Telegram.WebApp.BiometricManager.isInited) | ||
const isBiometricAvailable = ref( | ||
Telegram.WebApp.BiometricManager.isBiometricAvailable, | ||
) | ||
const biometricType = ref(Telegram.WebApp.BiometricManager.biometricType) | ||
const isBiometricAccessRequested = ref( | ||
Telegram.WebApp.BiometricManager.isAccessRequested, | ||
) | ||
const isBiometricAccessGranted = ref( | ||
Telegram.WebApp.BiometricManager.isAccessGranted, | ||
) | ||
const isBiometricTokenSaved = ref( | ||
Telegram.WebApp.BiometricManager.isAccessGranted, | ||
) | ||
const biometricDeviceId = ref(Telegram.WebApp.BiometricManager.deviceId) | ||
|
||
function updateState() { | ||
isBiometricInited.value = Telegram.WebApp.BiometricManager.isInited | ||
isBiometricAvailable.value = | ||
Telegram.WebApp.BiometricManager.isBiometricAvailable | ||
biometricType.value = Telegram.WebApp.BiometricManager.biometricType | ||
isBiometricAccessRequested.value = | ||
Telegram.WebApp.BiometricManager.isAccessRequested | ||
isBiometricAccessGranted.value = | ||
Telegram.WebApp.BiometricManager.isAccessGranted | ||
biometricDeviceId.value = Telegram.WebApp.BiometricManager.deviceId | ||
isBiometricTokenSaved.value = | ||
Telegram.WebApp.BiometricManager.isBiometricTokenSaved | ||
} | ||
|
||
export function useWebAppBiometricManager() { | ||
const { onEvent } = useWebApp() | ||
|
||
const onBiometricManagerUpdated = (eventHandler: () => void) => | ||
onEvent("biometricManagerUpdated", eventHandler) | ||
const onBiometricAuthRequested = (eventHandler: OnBiometricAuthRequested) => | ||
onEvent("biometricAuthRequested", eventHandler) | ||
const onBiometricTokenUpdated = (eventHandler: OnBiometricTokenUpdated) => | ||
onEvent("biometricTokenUpdated", eventHandler) | ||
|
||
onBiometricManagerUpdated(updateState) | ||
|
||
return { | ||
isBiometricInited: readonly(isBiometricInited), | ||
isBiometricAvailable: readonly(isBiometricAvailable), | ||
biometricType: readonly(biometricType), | ||
isBiometricAccessRequested: readonly(isBiometricAccessRequested), | ||
isBiometricAccessGranted: readonly(isBiometricAccessGranted), | ||
isBiometricTokenSaved: readonly(isBiometricTokenSaved), | ||
biometricDeviceId: readonly(biometricDeviceId), | ||
initBiometric: init, | ||
requestBiometricAccess: requestAccess, | ||
authenticateBiometric: authenticate, | ||
updateBiometricToken, | ||
openBiometricSettings: openSettings, | ||
onBiometricManagerUpdated, | ||
onBiometricAuthRequested, | ||
onBiometricTokenUpdated, | ||
} | ||
} |
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.