use-jwt-manager
Advanced tools
Comparing version 0.2.3 to 0.2.4
@@ -1,1 +0,1 @@ | ||
module.exports=(()=>{"use strict";var e={613:(e,t,r)=>{r.r(t),r.d(t,{default:()=>f});const n=require("react");var o=r.n(n);const i=require("lockr");var a=r.n(i);const c=require("axios");var u=r.n(c);const s=(e,t)=>{switch(t.type){case"LOGIN":return Object.assign(Object.assign(Object.assign({},e),t.payload),{authenticated:!0,initialized:!0});case"LOGOUT":return{authenticated:!1,initialized:!0}}};class d extends Error{constructor(e,t){super(e),this.cause=t,this.name="JwtError"}}var l=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function c(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,c)}u((n=n.apply(e,t||[])).next())}))};const h={initialized:!1,authenticated:!1},f=({refresh:e,me:t,login:r,config:i})=>{const[c,f]=o().useReducer(s,h),{TOKEN_KEY:y}=i,v=(0,n.useCallback)((()=>{const t=a().get(y);c.authenticated||!t?f({type:"LOGOUT"}):(u().defaults.headers.Authorization="Bearer "+t,e().then(p).catch((e=>{throw f({type:"LOGOUT"}),new d("An error occurred trying to refresh the token",e)})))}),[c.authenticated]);(0,n.useEffect)(v,[]);const p=(0,n.useCallback)((({token:e})=>l(void 0,void 0,void 0,(function*(){return a().set(y,e),u().defaults.headers.Authorization="Bearer "+e,yield t().then((t=>(f({type:"LOGIN",payload:{user:t,token:e}}),t))).catch((e=>{throw new d("An error occurred retrieving the user information",e)}))}))),[]),O=(0,n.useCallback)((e=>l(void 0,void 0,void 0,(function*(){return yield r(e).then(p).then((e=>e)).catch((e=>{throw new d("An error occurred trying to log in",e)}))}))),[]),g=(0,n.useCallback)((()=>l(void 0,void 0,void 0,(function*(){return a().rm(y),u().defaults.headers.Authorization=null,f({type:"LOGOUT"}),yield!0}))),[]);return Object.assign(Object.assign({},c),{login:O,logout:g,refresh:v})}}},t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={exports:{}};return e[n](o,o.exports,r),o.exports}return r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r(613)})(); | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("react"),require("lockr"),require("axios"));else if("function"==typeof define&&define.amd)define(["react","lockr","axios"],t);else{var r="object"==typeof exports?t(require("react"),require("lockr"),require("axios")):t(e.React,e.lockr,e.axios);for(var o in r)("object"==typeof exports?exports:e)[o]=r[o]}}(self,(function(e,t,r){return(()=>{"use strict";var o={793:(e,t,r)=>{r.r(t),r.d(t,{default:()=>f});var o=r(698),a=r.n(o),n=r(190),i=r.n(n),c=r(376),s=r.n(c);const u=(e,t)=>{switch(t.type){case"LOGIN":return{...e,...t.payload,authenticated:!0,initialized:!0};case"LOGOUT":return{authenticated:!1,initialized:!0}}};class l extends Error{constructor(e,t){super(e),this.cause=t,this.name="JwtError"}}const d={initialized:!1,authenticated:!1},f=({refresh:e,me:t,login:r,config:n})=>{const[c,f]=a().useReducer(u,d),{TOKEN_KEY:p}=n,h=(0,o.useCallback)((()=>{const t=i().get(p);c.authenticated||!t?f({type:"LOGOUT"}):(s().defaults.headers.Authorization="Bearer "+t,e().then(y).catch((e=>{throw f({type:"LOGOUT"}),new l("An error occurred trying to refresh the token",e)})))}),[c.authenticated]);(0,o.useEffect)(h,[]);const y=(0,o.useCallback)((async({token:e})=>(i().set(p,e),s().defaults.headers.Authorization="Bearer "+e,await t().then((t=>(f({type:"LOGIN",payload:{user:t,token:e}}),t))).catch((e=>{throw new l("An error occurred retrieving the user information",e)})))),[]),x=(0,o.useCallback)((async e=>await r(e).then(y).then((e=>e)).catch((e=>{throw new l("An error occurred trying to log in",e)}))),[]),b=(0,o.useCallback)((async()=>(i().rm(p),s().defaults.headers.Authorization=null,f({type:"LOGOUT"}),await!0)),[]);return{...c,login:x,logout:b,refresh:h}}},376:e=>{e.exports=r},190:e=>{e.exports=t},698:t=>{t.exports=e}},a={};function n(e){if(a[e])return a[e].exports;var t=a[e]={exports:{}};return o[e](t,t.exports,n),t.exports}return n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n(793)})()})); |
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "hook for jwt auth", | ||
@@ -10,0 +10,0 @@ "repository": { |
{ | ||
"compilerOptions": { | ||
"module": "esnext", | ||
"outDir": "dist/", | ||
"noImplicitAny": true, | ||
"removeComments": true, | ||
"preserveConstEnums": true, | ||
"sourceMap": false, | ||
"target": "es6", | ||
"sourceMap": true, | ||
"target": "ESNext", | ||
"allowJs": true, | ||
"checkJs": false, | ||
"jsx": "react", | ||
"pretty": true, | ||
"skipLibCheck": true, | ||
@@ -16,10 +18,10 @@ "strict": true, | ||
"esModuleInterop": true, | ||
"lib": ["DOM", "ESNext"], | ||
"lib": ["dom", "dom.iterable", "ESNext"], | ||
"allowSyntheticDefaultImports": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"resolveJsonModule": true, | ||
"isolatedModules": false | ||
"declaration": true, | ||
}, | ||
"include": ["./src/**/*.tsx", "./src/**/*.ts", "./src/**/*.js"], | ||
"include": ["src"], | ||
"exclude": ["node_modules", "**/*.spec.ts"] | ||
} | ||
} |
@@ -45,4 +45,4 @@ const path = require('path'); | ||
filename: 'index.js', | ||
libraryTarget: 'commonjs2', | ||
libraryTarget: 'umd', | ||
}, | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
339
17377