Skip to content
On this page

usePermission

Category
Last Changed
3 months ago

Reactive Permissions API. The Permissions API provides the tools to allow developers to implement a better user experience as far as permissions are concerned.

Demo

Usage

import { usePermission } from '@vueuse/core'

const microphoneAccess = usePermission('microphone')
import { usePermission } from '@vueuse/core'

const microphoneAccess = usePermission('microphone')

Type Declarations

Show Type Declarations
declare type DescriptorNamePolyfill =
  | "clipboard-read"
  | "clipboard-write"
  | "camera"
  | "microphone"
  | "speaker"
export declare type GeneralPermissionDescriptor =
  | PermissionDescriptor
  | {
      name: DescriptorNamePolyfill
    }
export interface UsePermissionOptions<Controls extends boolean>
  extends ConfigurableNavigator {
  /**
   * Expose more controls
   *
   * @default false
   */
  controls?: Controls
}
export declare type UsePermissionReturn = Readonly<
  Ref<PermissionState | undefined>
>
export interface UsePermissionReturnWithControls {
  state: UsePermissionReturn
  isSupported: boolean
  query: () => Promise<PermissionStatus | undefined>
}
/**
 * Reactive Permissions API.
 *
 * @see https://vueuse.org/usePermission
 */
export declare function usePermission(
  permissionDesc:
    | GeneralPermissionDescriptor
    | GeneralPermissionDescriptor["name"],
  options?: UsePermissionOptions<false>
): UsePermissionReturn
export declare function usePermission(
  permissionDesc:
    | GeneralPermissionDescriptor
    | GeneralPermissionDescriptor["name"],
  options: UsePermissionOptions<true>
): UsePermissionReturnWithControls
declare type DescriptorNamePolyfill =
  | "clipboard-read"
  | "clipboard-write"
  | "camera"
  | "microphone"
  | "speaker"
export declare type GeneralPermissionDescriptor =
  | PermissionDescriptor
  | {
      name: DescriptorNamePolyfill
    }
export interface UsePermissionOptions<Controls extends boolean>
  extends ConfigurableNavigator {
  /**
   * Expose more controls
   *
   * @default false
   */
  controls?: Controls
}
export declare type UsePermissionReturn = Readonly<
  Ref<PermissionState | undefined>
>
export interface UsePermissionReturnWithControls {
  state: UsePermissionReturn
  isSupported: boolean
  query: () => Promise<PermissionStatus | undefined>
}
/**
 * Reactive Permissions API.
 *
 * @see https://vueuse.org/usePermission
 */
export declare function usePermission(
  permissionDesc:
    | GeneralPermissionDescriptor
    | GeneralPermissionDescriptor["name"],
  options?: UsePermissionOptions<false>
): UsePermissionReturn
export declare function usePermission(
  permissionDesc:
    | GeneralPermissionDescriptor
    | GeneralPermissionDescriptor["name"],
  options: UsePermissionOptions<true>
): UsePermissionReturnWithControls

Source

SourceDemoDocs

Contributors

Anthony Fu
Antério Vieira
Alex Kozack
Nurettin Kaya

Changelog

v6.1.0 on 9/2/2021
dee2f - fix: support TypeScript 4.4
v4.9.4 on 5/12/2021
941b3 - fix: tolerate error on FireFox
v4.9.4 on 5/12/2021
98df8 - fix: tolerate error on FireFox
v4.8.4 on 4/21/2021
17d93 - fix: internalize utils
v4.8.3 on 4/20/2021
aca89 - feat: expose more controls
usePermission has loaded