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.3 to 0.1.4

41

dist/constants/types.d.ts

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

interface IUser {
interface UserDetails {
id?: number;

@@ -7,4 +7,4 @@ username?: string;

}
interface IUserContextReducerParams {
user?: IUser;
interface UserContextReducerParams {
user?: UserDetails;
access_token?: string;

@@ -16,21 +16,11 @@ refresh_token?: string;

}
interface IUserContext extends IUserContextReducerParams {
login: (user: IUser) => void;
logout: () => void;
refrshToken: () => void;
}
interface ITokenParam {
interface TokenParams {
access_token: string;
refresh_token?: string;
[x: string]: any;
}
interface useJwtManagerProps {
refresh: () => Promise<ITokenParam>;
me: {
(): Promise<any>;
(): Promise<IUser>;
};
login: {
(user: any): Promise<any>;
(arg0: IUser): Promise<ITokenParam>;
};
interface jwtManagerProps {
refresh: () => Promise<TokenParams>;
me: () => Promise<UserDetails>;
login: (user: UserDetails) => Promise<TokenParams>;
config: {

@@ -41,7 +31,10 @@ TOKEN_KEY: string;

}
interface jwtManagerContext extends IUserContextReducerParams {
login: (user: IUser) => void;
logout: () => void;
refrshToken: () => void;
interface jwtManagerContext extends UserContextReducerParams {
login: (user: UserDetails) => Promise<UserDetails>;
logout: () => Promise<boolean>;
}
export { ITokenParam, IUser, IUserContext, IUserContextReducerParams, useJwtManagerProps, jwtManagerContext };
declare class JwtError extends Error {
cause: any;
constructor(message: string, cause: any);
}
export { TokenParams, UserDetails, UserContextReducerParams, jwtManagerProps, jwtManagerContext, JwtError };

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

import { jwtManagerContext, useJwtManagerProps } from './constants/types';
declare const useJwtManager: (props: useJwtManagerProps) => jwtManagerContext;
import { jwtManagerContext, jwtManagerProps } from './constants/types';
declare const useJwtManager: (props: jwtManagerProps) => jwtManagerContext;
export default useJwtManager;

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

module.exports=(()=>{"use strict";var e={84:(e,r,t)=>{t.r(r),t.d(r,{default:()=>d});const a=require("react");var o=t.n(a);const n=require("lockr");var s=t.n(n);const u=require("axios");var c=t.n(u);const i=(e,r)=>{switch(r.type){case"LOGIN":return{...e,...r.payload,authenticated:!0,initialized:!0};case"ERROR":return{...e,...r.payload};case"LOGOUT":return{authenticated:!1,initialized:!0}}},l={initialized:!1,authenticated:!1},d=({refresh:e,me:r,login:t,config:n})=>{const[u,d]=o().useReducer(i,l),{TOKEN_KEY:p,REFRESH_TOKEN_KEY:h}=n;(0,a.useEffect)((()=>{y()}),[]);const y=(0,a.useCallback)((()=>{const r=s().get(h);u.authenticated||!r?d({type:"LOGOUT"}):(c().defaults.headers.Authorization="Bearer "+r,e().then(f).catch((e=>d({type:"ERROR",payload:{error:e||"refresh error"}}))))}),[u.authenticated]),f=(0,a.useCallback)((({access_token:e,refresh_token:t})=>{s().set(p,e),t&&s().set(h,t),c().defaults.headers.Authorization="Bearer "+e,r().then((r=>d({type:"LOGIN",payload:{user:r,access_token:e,refresh_token:t}}))).catch((e=>d({type:"ERROR",payload:{error:e||"me error"}})))}),[]),O=(0,a.useCallback)((e=>t(e).then(f).catch((e=>d({type:"ERROR",payload:{error:e||"login error"}})))),[]),R=(0,a.useCallback)((()=>{s().rm(p),s().rm(h),c().defaults.headers.Authorization=null,d({type:"LOGOUT"})}),[]);return{...u,login:O,logout:R,refrshToken:y}}}},r={};function t(a){if(r[a])return r[a].exports;var o=r[a]={exports:{}};return e[a](o,o.exports,t),o.exports}return t.n=e=>{var r=e&&e.__esModule?()=>e.default:()=>e;return t.d(r,{a:r}),r},t.d=(e,r)=>{for(var a in r)t.o(r,a)&&!t.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:r[a]})},t.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),t.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t(84)})();
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)})();

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

import { IUser, IUserContextReducerParams } from './constants/types';
import { UserDetails, UserContextReducerParams } from './constants/types';
declare type Actions = {
type: 'LOGIN';
payload: {
user: IUser;
user: UserDetails;
access_token: string;

@@ -10,10 +10,5 @@ refresh_token: string;

} | {
type: 'ERROR';
payload: {
error: string;
};
} | {
type: 'LOGOUT';
};
declare const userContextReducer: (state: IUserContextReducerParams, action: Actions) => IUserContextReducerParams;
declare const userContextReducer: (state: UserContextReducerParams, action: Actions) => UserContextReducerParams;
export default userContextReducer;

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

},
"version": "0.1.3",
"version": "0.1.4",
"description": "hook for jwt auth",

@@ -22,3 +22,4 @@ "repository": {

"test": "jest",
"build": "webpack --config ./webpack.config.js"
"build": "webpack --config ./webpack.config.js",
"publish": "rm -rf dist && npm run build && npm publish"
},

@@ -25,0 +26,0 @@ "dependencies": {

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