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.82 to 0.1.85

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 s=r.n(o);const c=require("axios");var i=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,REFRESH_TOKEN_KEY:y}=o,p=(0,a.useCallback)((()=>{const t=s().get(y);c.authenticated||!t?h({type:"LOGOUT"}):(i().defaults.headers.Authorization="Bearer "+t,e().then(O).catch((e=>{throw h({type:"LOGOUT"}),new l("An error occurred trying to refresh the token",e)})))}),[c.authenticated]);(0,a.useEffect)(p,[]);const O=(0,a.useCallback)((async({access_token:e,refresh_token:r})=>{let a=r;return s().set(f,e),a?s().set(y,a):a=s().get(y),i().defaults.headers.Authorization="Bearer "+e,await t().then((t=>(h({type:"LOGIN",payload:{user:t,access_token:e,refresh_token:a}}),t))).catch((e=>{throw new l("An error occurred retrieving the user information",e)}))}),[]),g=(0,a.useCallback)((async e=>await r(e).then(O).then((e=>e)).catch((e=>{throw new l("An error occurred trying to log in",e)}))),[]),b=(0,a.useCallback)((async()=>(s().rm(f),s().rm(y),i().defaults.headers.Authorization=null,h({type:"LOGOUT"}),await!0)),[]);return{...c,login:g,logout:b,refresh:p}}}},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)})();
!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),s=r(376),c=r.n(s);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[s,f]=a().useReducer(u,d),{TOKEN_KEY:h,REFRESH_TOKEN_KEY:p}=n,y=(0,o.useCallback)((()=>{const t=i().get(p);s.authenticated||!t?f({type:"LOGOUT"}):(c().defaults.headers.Authorization="Bearer "+t,e().then(x).catch((e=>{throw f({type:"LOGOUT"}),new l("An error occurred trying to refresh the token",e)})))}),[s.authenticated]);(0,o.useEffect)(y,[]);const x=(0,o.useCallback)((async({access_token:e,refresh_token:r})=>{let o=r;return i().set(h,e),o?i().set(p,o):o=i().get(p),c().defaults.headers.Authorization="Bearer "+e,await t().then((t=>(f({type:"LOGIN",payload:{user:t,access_token:e,refresh_token:o}}),t))).catch((e=>{throw new l("An error occurred retrieving the user information",e)}))}),[]),O=(0,o.useCallback)((async e=>await r(e).then(x).then((e=>e)).catch((e=>{throw new l("An error occurred trying to log in",e)}))),[]),b=(0,o.useCallback)((async()=>(i().rm(h),i().rm(p),c().defaults.headers.Authorization=null,f({type:"LOGOUT"}),await!0)),[]);return{...s,login:O,logout:b,refresh:y}}},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.1.82",
"version": "0.1.85",
"description": "hook for jwt auth",

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

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

const path = require('path');
const path = require("path");
module.exports = {
entry: ['./src/index.tsx'],
entry: ["./src/index.tsx"],
externals: {
react: {
root: 'React',
commonjs2: 'react',
commonjs: 'react',
amd: 'react',
root: "React",
commonjs2: "react",
commonjs: "react",
amd: "react",
},
'react-dom': {
root: 'ReactDOM',
commonjs2: 'react-dom',
commonjs: 'react-dom',
amd: 'react-dom',
"react-dom": {
root: "ReactDOM",
commonjs2: "react-dom",
commonjs: "react-dom",
amd: "react-dom",
},
axios: 'axios',
lockr: 'lockr',
axios: "axios",
lockr: "lockr",
},

@@ -26,7 +26,7 @@ module: {

exclude: /node_modules/,
use: ['babel-loader'],
use: ["babel-loader"],
},
{
test: /\.tsx?$/,
use: 'ts-loader',
use: "ts-loader",
exclude: /node_modules/,

@@ -40,10 +40,10 @@ },

resolve: {
extensions: ['.tsx', '.ts', '.js'],
extensions: [".tsx", ".ts", ".js"],
},
output: {
path: path.resolve(__dirname, 'dist'),
publicPath: '/',
filename: 'index.js',
libraryTarget: 'commonjs2',
path: path.resolve(__dirname, "dist"),
publicPath: "/",
filename: "index.js",
libraryTarget: "umd",
},
};
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