Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/useJwt.md
1---2category: '@Integrations'3---45# useJwt67Wrapper for [`jwt-decode`](https://github.com/auth0/jwt-decode).89## Install1011```bash12npm install jwt-decode@^413```1415## Usage1617```ts18import { useJwt } from '@vueuse/integrations/useJwt'19import { defineComponent } from 'vue'2021const encodedJwt = ref('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwiaWF0IjoxNTE2MjM5MDIyfQ.L8i6g3PfcHlioHCCPURC9pmXT7gdJpx3kOoyAfNUwCc')22const { header, payload } = useJwt(encodedJwt)23```2425## Type Declarations2627```ts28export interface UseJwtOptions<Fallback> {29/**30* Value returned when encounter error on decoding31*32* @default null33*/34fallbackValue?: Fallback35/**36* Error callback for decoding37*/38onError?: (error: unknown) => void39}40export interface UseJwtReturn<Payload, Header, Fallback> {41header: ComputedRef<Header | Fallback>42payload: ComputedRef<Payload | Fallback>43}44/**45* Reactive decoded jwt token.46*47* @see https://vueuse.org/useJwt48*/49export declare function useJwt<50Payload extends object = JwtPayload,51Header extends object = JwtHeader,52Fallback = null,53>(54encodedJwt: MaybeRefOrGetter<string>,55options?: UseJwtOptions<Fallback>,56): UseJwtReturn<Payload, Header, Fallback>57```58