📄 useJwt¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 2 |
| 📦 Imports | 8 |
| 🟢 Vue Composition API | 2 |
| 📐 Interfaces | 2 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/integrations/useJwt/index.ts
📦 Imports¶
| Name | Source |
|---|---|
JwtDecodeOptions |
jwt-decode |
JwtHeader |
jwt-decode |
JwtPayload |
jwt-decode |
ComputedRef |
vue |
MaybeRefOrGetter |
vue |
jwtDecode |
jwt-decode |
computed |
vue |
toValue |
vue |
Vue Composition API¶
| Name | Type | Reactive Variables | Composables |
|---|---|---|---|
computed |
computed | none | none |
computed |
computed | none | none |
Functions¶
useJwt(encodedJwt: MaybeRefOrGetter<string>, options: UseJwtOptions<Fallback>): UseJwtReturn<Payload, Header, Fallback>¶
Reactive decoded jwt token.
See: https://vueuse.org/useJwt
Calls:
jwtDecode (from jwt-decode)onErrorcomputed (from vue)decodeWithFallbacktoValue (from vue)
Code
export function useJwt<
Payload extends object = JwtPayload,
Header extends object = JwtHeader,
Fallback = null,
>(
encodedJwt: MaybeRefOrGetter<string>,
options: UseJwtOptions<Fallback> = {},
): UseJwtReturn<Payload, Header, Fallback> {
const {
onError,
fallbackValue = null,
} = options
const decodeWithFallback = <T extends object>(encodedJwt: string, options?: JwtDecodeOptions): T | Fallback => {
try {
return jwtDecode<T>(encodedJwt, options)
}
catch (err) {
onError?.(err)
return fallbackValue as Fallback
}
}
const header = computed(() => decodeWithFallback<Header>(toValue(encodedJwt), { header: true }))
const payload = computed(() => decodeWithFallback<Payload>(toValue(encodedJwt)))
return {
header,
payload,
}
}
Internal helpers¶
Declared inside another function in this file.
decodeWithFallback(encodedJwt: string, options: JwtDecodeOptions): T | Fallback¶
Parameters:
encodedJwtstringoptionsJwtDecodeOptions
Returns: T | Fallback
Calls:
jwtDecode (from jwt-decode)onError
Code
Interfaces¶
UseJwtOptions<Fallback>¶
Interface Code
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
fallbackValue |
Fallback |
✓ | not shown |
onError |
(error: unknown) => void |
✓ | not shown |
UseJwtReturn<Payload, Header, Fallback>¶
Interface Code
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
header |
ComputedRef<Header \| Fallback> |
✗ | not shown |
payload |
ComputedRef<Payload \| Fallback> |
✗ | not shown |
Generated by Syntax Scribe