📄 index.ts
¶
📊 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>
¶
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,
}
}
-
JSDoc:
-
Parameters:
encodedJwt: MaybeRefOrGetter<string>
options: UseJwtOptions<Fallback>
- Return Type:
UseJwtReturn<Payload, Header, Fallback>
- Calls:
jwtDecode (from jwt-decode)
onError
computed (from vue)
decodeWithFallback
toValue (from vue)
decodeWithFallback(encodedJwt: string, options: JwtDecodeOptions): T | Fallback
¶
Code
- Parameters:
encodedJwt: string
options: JwtDecodeOptions
- Return Type:
T | Fallback
- Calls:
jwtDecode (from jwt-decode)
onError
Interfaces¶
UseJwtOptions<Fallback>
¶
Interface Code
Properties¶
Name | Type | Optional | Description |
---|---|---|---|
fallbackValue |
Fallback |
✓ | |
onError |
(error: unknown) => void |
✓ |
UseJwtReturn<Payload, Header, Fallback>
¶
Interface Code
Properties¶
Name | Type | Optional | Description |
---|---|---|---|
header |
ComputedRef<Header | Fallback> |
✗ | |
payload |
ComputedRef<Payload | Fallback> |
✗ |