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.61 to 0.1.62

19

dist/constants/types.d.ts

@@ -20,6 +20,17 @@ interface UserDetails {

}
interface ApiResponse {
data: any;
message: string;
status: boolean;
}
interface jwtManagerProps {
refresh: () => Promise<TokenParams>;
me: () => Promise<UserDetails>;
login: (user: UserDetails) => Promise<TokenParams>;
refresh: () => Promise<ApiResponse & {
data: TokenParams;
}>;
me: () => Promise<ApiResponse & {
data: UserDetails;
}>;
login: (user: UserDetails) => Promise<ApiResponse & {
data: TokenParams;
}>;
config: {

@@ -38,2 +49,2 @@ TOKEN_KEY: string;

}
export { TokenParams, UserDetails, UserContextReducerParams, jwtManagerProps, jwtManagerContext, JwtError };
export { TokenParams, UserDetails, UserContextReducerParams, jwtManagerProps, jwtManagerContext, JwtError, ApiResponse };

@@ -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 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})=>(s().set(f,e),r&&s().set(y,r),i().defaults.headers.Authorization="Bearer "+e,await t().then((t=>(h({type:"LOGIN",payload:{user:t,access_token:e,refresh_token:r}}),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,refrshToken: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)})();
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 new l("An error occurred trying to refresh the token",e)})))}),[c.authenticated]);(0,a.useEffect)(p,[]);const O=(0,a.useCallback)((async({data:{access_token:e,refresh_token:r}})=>(s().set(f,e),r&&s().set(y,r),i().defaults.headers.Authorization="Bearer "+e,await t().then((t=>(h({type:"LOGIN",payload:{user:t,access_token:e,refresh_token:r}}),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,refrshToken: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)})();

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

},
"version": "0.1.61",
"version": "0.1.62",
"description": "hook for jwt auth",

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

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