mirror of
https://kevinblog.sytes.net/Code/Jibo-Revival-Group/JiboViteDocs.git
synced 2026-06-16 16:16:13 +00:00
Initalize
This commit is contained in:
25
node_modules/@vueuse/integrations/dist/useJwt.js
generated
vendored
Normal file
25
node_modules/@vueuse/integrations/dist/useJwt.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import { computed, toValue } from "vue";
|
||||
import { jwtDecode } from "jwt-decode";
|
||||
//#region useJwt/index.ts
|
||||
/**
|
||||
* Reactive decoded jwt token.
|
||||
*
|
||||
* @see https://vueuse.org/useJwt
|
||||
*/
|
||||
function useJwt(encodedJwt, options = {}) {
|
||||
const { onError, fallbackValue = null } = options;
|
||||
const decodeWithFallback = (encodedJwt, options) => {
|
||||
try {
|
||||
return jwtDecode(encodedJwt, options);
|
||||
} catch (err) {
|
||||
onError === null || onError === void 0 || onError(err);
|
||||
return fallbackValue;
|
||||
}
|
||||
};
|
||||
return {
|
||||
header: computed(() => decodeWithFallback(toValue(encodedJwt), { header: true })),
|
||||
payload: computed(() => decodeWithFallback(toValue(encodedJwt)))
|
||||
};
|
||||
}
|
||||
//#endregion
|
||||
export { useJwt };
|
||||
Reference in New Issue
Block a user