Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

use-jwt-manager

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-jwt-manager - npm Package Compare versions

Comparing version 0.1.74 to 0.1.75

2

dist/index.js

@@ -1,1 +0,1 @@

module.exports=(()=>{"use strict";var e={613:(e,t,r)=>{r.r(t),r.d(t,{default:()=>h});const a=require("react");var n=r.n(a);const o=require("lockr");var i=r.n(o);const c=require("axios");var 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},h=({refresh:e,me:t,login:r,config:o})=>{const[c,h]=n().useReducer(u,d),{TOKEN_KEY:f}=o,y=(0,a.useCallback)((()=>{const t=i().get(f);c.authenticated||!t?h({type:"LOGOUT"}):(s().defaults.headers.Authorization="Bearer "+t,e().then(p).catch((e=>{throw new l("An error occurred trying to refresh the token",e)})))}),[c.authenticated]);(0,a.useEffect)(y,[]);const p=(0,a.useCallback)((async({token:e})=>(i().set(f,e),s().defaults.headers.Authorization="Bearer "+e,await t().then((t=>(h({type:"LOGIN",payload:{user:t,token:e}}),t))).catch((e=>{throw new l("An error occurred retrieving the user information",e)})))),[]),g=(0,a.useCallback)((async e=>await r(e).then(p).then((e=>e)).catch((e=>{throw new l("An error occurred trying to log in",e)}))),[]),O=(0,a.useCallback)((async()=>(i().rm(f),s().defaults.headers.Authorization=null,h({type:"LOGOUT"}),await!0)),[]);return{...c,login:g,logout:O,refresh:y}}}},t={};function r(a){if(t[a])return t[a].exports;var n=t[a]={exports:{}};return e[a](n,n.exports,r),n.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 a in t)r.o(t,a)&&!r.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},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)})();
module.exports=(()=>{"use strict";var e={613:(e,t,r)=>{r.r(t),r.d(t,{default:()=>h});const a=require("react");var n=r.n(a);const o=require("lockr");var i=r.n(o);const c=require("axios");var 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},h=({refresh:e,me:t,login:r,config:o})=>{const[c,h]=n().useReducer(u,d),{TOKEN_KEY:y}=o,f=(0,a.useCallback)((()=>{const t=i().get(y);c.authenticated||!t?h({type:"LOGOUT"}):(s().defaults.headers.Authorization="Bearer "+t,e().then(p).catch((e=>{throw h({type:"LOGOUT"}),new l("An error occurred trying to refresh the token",e)})))}),[c.authenticated]);(0,a.useEffect)(f,[]);const p=(0,a.useCallback)((async({token:e})=>(i().set(y,e),s().defaults.headers.Authorization="Bearer "+e,await t().then((t=>(h({type:"LOGIN",payload:{user:t,token:e}}),t))).catch((e=>{throw new l("An error occurred retrieving the user information",e)})))),[]),O=(0,a.useCallback)((async e=>await r(e).then(p).then((e=>e)).catch((e=>{throw new l("An error occurred trying to log in",e)}))),[]),g=(0,a.useCallback)((async()=>(i().rm(y),s().defaults.headers.Authorization=null,h({type:"LOGOUT"}),await!0)),[]);return{...c,login:O,logout:g,refresh:f}}}},t={};function r(a){if(t[a])return t[a].exports;var n=t[a]={exports:{}};return e[a](n,n.exports,r),n.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 a in t)r.o(t,a)&&!r.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},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)})();

@@ -7,3 +7,3 @@ {

},
"version": "0.1.74",
"version": "0.1.75",
"description": "hook for jwt auth",

@@ -10,0 +10,0 @@ "repository": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc