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

react-auth-kit

Package Overview
Dependencies
Maintainers
1
Versions
200
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-auth-kit - npm Package Compare versions

Comparing version 1.4.2-0 to 1.4.3-0

2

dist/index.js

@@ -53,4 +53,4 @@ 'use strict';

this.cookieSecure = cookieSecure;
this.isUsingRefreshToken = !!this.authStorageName;
this.authStorageTypeName = this.authStorageName + "_type";
this.isUsingRefreshToken = !!this.refreshTokenName;
this.refreshTokenTimeName = this.refreshTokenName ?

@@ -57,0 +57,0 @@ this.refreshTokenName + "_time" : null;

@@ -45,4 +45,4 @@ import { createContext, useState, useEffect, createElement, useContext } from 'react';

this.cookieSecure = cookieSecure;
this.isUsingRefreshToken = !!this.authStorageName;
this.authStorageTypeName = this.authStorageName + "_type";
this.isUsingRefreshToken = !!this.refreshTokenName;
this.refreshTokenTimeName = this.refreshTokenName ?

@@ -49,0 +49,0 @@ this.refreshTokenName + "_time" : null;

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

/*! react-auth-kit v1.4.2-0 | Apache-2.0 */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("js-cookie"),require("react-router-dom")):"function"==typeof define&&define.amd?define(["exports","react","js-cookie","react-router-dom"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactAuthKit={},e.React,e.Cookies,e.reactRouterDom)}(this,(function(e,t,n,r){"use strict";function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=o(n),u=function(){function e(e){var t=e.authStorageName,n=e.authStorageType,r=e.authTimeStorageName,o=e.stateStorageName,a=e.refreshTokenName,u=e.cookieDomain,i=e.cookieSecure;this.authStorageType=n,this.authStorageName=t,this.authTimeStorageName=r,this.stateStorageName=o,this.refreshTokenName=a,this.cookieDomain=u,this.cookieSecure=i,this.isUsingRefreshToken=!!this.authStorageName,this.authStorageTypeName=this.authStorageName+"_type",this.refreshTokenTimeName=this.refreshTokenName?this.refreshTokenName+"_time":null}return e.prototype.initialToken=function(){return"cookie"===this.authStorageType?this.initialCookieToken_():this.initialLSToken_()},e.prototype.initialCookieToken_=function(){var e=a.default.get(this.authStorageName),t=a.default.get(this.authStorageTypeName),n=a.default.get(this.authTimeStorageName),r=a.default.get(this.stateStorageName),o=this.isUsingRefreshToken&&null!=this.refreshTokenName?a.default.get(this.refreshTokenName):null,u=this.isUsingRefreshToken&&null!=this.refreshTokenTimeName?a.default.get(this.refreshTokenTimeName):null;return this.checkTokenExist(e,t,n,r,o,u)},e.prototype.initialLSToken_=function(){var e=localStorage.getItem(this.authStorageName),t=localStorage.getItem(this.authStorageTypeName),n=localStorage.getItem(this.authTimeStorageName),r=localStorage.getItem(this.stateStorageName),o=this.isUsingRefreshToken&&null!=this.refreshTokenName?localStorage.getItem(this.refreshTokenName):null,a=this.isUsingRefreshToken&&null!=this.refreshTokenTimeName?localStorage.getItem(this.refreshTokenTimeName):null;return this.checkTokenExist(e,t,n,r,o,a)},e.prototype.checkTokenExist=function(e,t,n,r,o,a){if(!(e&&t&&n&&r))return{authToken:null,authTokenType:null,isUsingRefreshToken:this.isUsingRefreshToken,refreshToken:null,expireAt:null,authState:null,refreshTokenExpireAt:null};var u=new Date(n);try{var i=JSON.parse(r);return{authToken:e,authTokenType:t,isUsingRefreshToken:this.isUsingRefreshToken,refreshToken:this.isUsingRefreshToken&&o?o:null,refreshTokenExpireAt:this.isUsingRefreshToken&&a?new Date(a):null,expireAt:u,authState:i}}catch(e){return{authToken:null,authTokenType:null,isUsingRefreshToken:this.isUsingRefreshToken,refreshToken:null,expireAt:null,authState:null,refreshTokenExpireAt:null}}},e.prototype.syncTokens=function(e){void 0===e.authToken||null===e.authTokenType||null===e.authToken||null===e.expireAt||null===e.authState?this.removeToken():this.setToken(e.authToken,e.authTokenType,e.refreshToken,e.refreshTokenExpireAt,e.expireAt,e.authState)},e.prototype.setToken=function(e,t,n,r,o,a){"cookie"===this.authStorageType?this.setCookieToken_(e,t,n,o,r,a):this.setLSToken_(e,t,n,o,r,a)},e.prototype.setCookieToken_=function(e,t,n,r,o,u){a.default.set(this.authStorageName,e,{expires:r,domain:this.cookieDomain,secure:this.cookieSecure}),a.default.set(this.authStorageTypeName,t,{expires:r,domain:this.cookieDomain,secure:this.cookieSecure}),a.default.set(this.authTimeStorageName,r.toISOString(),{expires:r,domain:this.cookieDomain,secure:this.cookieSecure}),a.default.set(this.stateStorageName,u,{expires:r,domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenName&&n&&a.default.set(this.refreshTokenName,n,{expires:r,domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenTimeName&&o&&a.default.set(this.refreshTokenTimeName,o.toISOString(),{expires:r,domain:this.cookieDomain,secure:this.cookieSecure})},e.prototype.setLSToken_=function(e,t,n,r,o,a){localStorage.setItem(this.authStorageName,e),localStorage.setItem(this.authStorageTypeName,t),localStorage.setItem(this.authTimeStorageName,r.toISOString()),localStorage.setItem(this.stateStorageName,JSON.stringify(a)),this.isUsingRefreshToken&&this.refreshTokenName&&n&&localStorage.setItem(this.refreshTokenName,n),this.isUsingRefreshToken&&this.refreshTokenTimeName&&o&&localStorage.setItem(this.refreshTokenTimeName,o.toISOString())},e.prototype.removeToken=function(){"cookie"===this.authStorageType?this.removeCookieToken_():this.removeLSToken_()},e.prototype.removeCookieToken_=function(){a.default.remove(this.authStorageName),a.default.remove(this.authTimeStorageName),a.default.remove(this.stateStorageName),this.isUsingRefreshToken&&this.refreshTokenName&&a.default.remove(this.refreshTokenName),this.isUsingRefreshToken&&this.refreshTokenTimeName&&a.default.remove(this.refreshTokenTimeName)},e.prototype.removeLSToken_=function(){localStorage.removeItem(this.authStorageName),localStorage.removeItem(this.authTimeStorageName),localStorage.removeItem(this.stateStorageName),this.isUsingRefreshToken&&this.refreshTokenName&&localStorage.removeItem(this.refreshTokenName),this.isUsingRefreshToken&&this.refreshTokenTimeName&&localStorage.removeItem(this.refreshTokenTimeName)},e}(),i=t.createContext({authState:{authTokenType:null,authState:null,authToken:null,isUsingRefreshToken:!1,refreshToken:null,refreshTokenExpireAt:null,expireAt:null},setAuthState:function(){}}),h=function(e){var n=e.children,r=e.authStorageType,o=e.authStorageName,a=e.authTimeStorageName,h=e.stateStorageName,s=e.refreshTokenName,l=e.cookieDomain,T=e.cookieSecure;if("cookie"===r&&!l)throw new Error("authStorageType 'cookie' requires 'cookieDomain' and 'cookieSecure' in AuthProvider");var f=new u({authTimeStorageName:a,authStorageType:r,authStorageName:o,refreshTokenName:s,cookieDomain:l,cookieSecure:T,stateStorageName:h}),c=t.useState(f.initialToken()),k=c[0],m=c[1];return t.useEffect((function(){f.syncTokens(k)}),[k]),t.createElement(i.Provider,{value:{authState:k,setAuthState:m}},n)};h.defaultProps={authStorageType:"cookie",authStorageName:"_auth_token",authTimeStorageName:"_auth_time",stateStorageName:"_auth_state",cookieSecure:!0};var s=i.Consumer,l=function(){return(l=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};
/*! react-auth-kit v1.4.3-0 | Apache-2.0 */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("js-cookie"),require("react-router-dom")):"function"==typeof define&&define.amd?define(["exports","react","js-cookie","react-router-dom"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactAuthKit={},e.React,e.Cookies,e.reactRouterDom)}(this,(function(e,t,n,r){"use strict";function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=o(n),u=function(){function e(e){var t=e.authStorageName,n=e.authStorageType,r=e.authTimeStorageName,o=e.stateStorageName,a=e.refreshTokenName,u=e.cookieDomain,i=e.cookieSecure;this.authStorageType=n,this.authStorageName=t,this.authTimeStorageName=r,this.stateStorageName=o,this.refreshTokenName=a,this.cookieDomain=u,this.cookieSecure=i,this.authStorageTypeName=this.authStorageName+"_type",this.isUsingRefreshToken=!!this.refreshTokenName,this.refreshTokenTimeName=this.refreshTokenName?this.refreshTokenName+"_time":null}return e.prototype.initialToken=function(){return"cookie"===this.authStorageType?this.initialCookieToken_():this.initialLSToken_()},e.prototype.initialCookieToken_=function(){var e=a.default.get(this.authStorageName),t=a.default.get(this.authStorageTypeName),n=a.default.get(this.authTimeStorageName),r=a.default.get(this.stateStorageName),o=this.isUsingRefreshToken&&null!=this.refreshTokenName?a.default.get(this.refreshTokenName):null,u=this.isUsingRefreshToken&&null!=this.refreshTokenTimeName?a.default.get(this.refreshTokenTimeName):null;return this.checkTokenExist(e,t,n,r,o,u)},e.prototype.initialLSToken_=function(){var e=localStorage.getItem(this.authStorageName),t=localStorage.getItem(this.authStorageTypeName),n=localStorage.getItem(this.authTimeStorageName),r=localStorage.getItem(this.stateStorageName),o=this.isUsingRefreshToken&&null!=this.refreshTokenName?localStorage.getItem(this.refreshTokenName):null,a=this.isUsingRefreshToken&&null!=this.refreshTokenTimeName?localStorage.getItem(this.refreshTokenTimeName):null;return this.checkTokenExist(e,t,n,r,o,a)},e.prototype.checkTokenExist=function(e,t,n,r,o,a){if(!(e&&t&&n&&r))return{authToken:null,authTokenType:null,isUsingRefreshToken:this.isUsingRefreshToken,refreshToken:null,expireAt:null,authState:null,refreshTokenExpireAt:null};var u=new Date(n);try{var i=JSON.parse(r);return{authToken:e,authTokenType:t,isUsingRefreshToken:this.isUsingRefreshToken,refreshToken:this.isUsingRefreshToken&&o?o:null,refreshTokenExpireAt:this.isUsingRefreshToken&&a?new Date(a):null,expireAt:u,authState:i}}catch(e){return{authToken:null,authTokenType:null,isUsingRefreshToken:this.isUsingRefreshToken,refreshToken:null,expireAt:null,authState:null,refreshTokenExpireAt:null}}},e.prototype.syncTokens=function(e){void 0===e.authToken||null===e.authTokenType||null===e.authToken||null===e.expireAt||null===e.authState?this.removeToken():this.setToken(e.authToken,e.authTokenType,e.refreshToken,e.refreshTokenExpireAt,e.expireAt,e.authState)},e.prototype.setToken=function(e,t,n,r,o,a){"cookie"===this.authStorageType?this.setCookieToken_(e,t,n,o,r,a):this.setLSToken_(e,t,n,o,r,a)},e.prototype.setCookieToken_=function(e,t,n,r,o,u){a.default.set(this.authStorageName,e,{expires:r,domain:this.cookieDomain,secure:this.cookieSecure}),a.default.set(this.authStorageTypeName,t,{expires:r,domain:this.cookieDomain,secure:this.cookieSecure}),a.default.set(this.authTimeStorageName,r.toISOString(),{expires:r,domain:this.cookieDomain,secure:this.cookieSecure}),a.default.set(this.stateStorageName,u,{expires:r,domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenName&&n&&a.default.set(this.refreshTokenName,n,{expires:r,domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenTimeName&&o&&a.default.set(this.refreshTokenTimeName,o.toISOString(),{expires:r,domain:this.cookieDomain,secure:this.cookieSecure})},e.prototype.setLSToken_=function(e,t,n,r,o,a){localStorage.setItem(this.authStorageName,e),localStorage.setItem(this.authStorageTypeName,t),localStorage.setItem(this.authTimeStorageName,r.toISOString()),localStorage.setItem(this.stateStorageName,JSON.stringify(a)),this.isUsingRefreshToken&&this.refreshTokenName&&n&&localStorage.setItem(this.refreshTokenName,n),this.isUsingRefreshToken&&this.refreshTokenTimeName&&o&&localStorage.setItem(this.refreshTokenTimeName,o.toISOString())},e.prototype.removeToken=function(){"cookie"===this.authStorageType?this.removeCookieToken_():this.removeLSToken_()},e.prototype.removeCookieToken_=function(){a.default.remove(this.authStorageName),a.default.remove(this.authTimeStorageName),a.default.remove(this.stateStorageName),this.isUsingRefreshToken&&this.refreshTokenName&&a.default.remove(this.refreshTokenName),this.isUsingRefreshToken&&this.refreshTokenTimeName&&a.default.remove(this.refreshTokenTimeName)},e.prototype.removeLSToken_=function(){localStorage.removeItem(this.authStorageName),localStorage.removeItem(this.authTimeStorageName),localStorage.removeItem(this.stateStorageName),this.isUsingRefreshToken&&this.refreshTokenName&&localStorage.removeItem(this.refreshTokenName),this.isUsingRefreshToken&&this.refreshTokenTimeName&&localStorage.removeItem(this.refreshTokenTimeName)},e}(),i=t.createContext({authState:{authTokenType:null,authState:null,authToken:null,isUsingRefreshToken:!1,refreshToken:null,refreshTokenExpireAt:null,expireAt:null},setAuthState:function(){}}),h=function(e){var n=e.children,r=e.authStorageType,o=e.authStorageName,a=e.authTimeStorageName,h=e.stateStorageName,s=e.refreshTokenName,l=e.cookieDomain,T=e.cookieSecure;if("cookie"===r&&!l)throw new Error("authStorageType 'cookie' requires 'cookieDomain' and 'cookieSecure' in AuthProvider");var f=new u({authTimeStorageName:a,authStorageType:r,authStorageName:o,refreshTokenName:s,cookieDomain:l,cookieSecure:T,stateStorageName:h}),k=t.useState(f.initialToken()),c=k[0],m=k[1];return t.useEffect((function(){f.syncTokens(c)}),[c]),t.createElement(i.Provider,{value:{authState:c,setAuthState:m}},n)};h.defaultProps={authStorageType:"cookie",authStorageName:"_auth_token",authTimeStorageName:"_auth_time",stateStorageName:"_auth_state",cookieSecure:!0};var s=i.Consumer,l=function(){return(l=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};
/*! *****************************************************************************

@@ -16,3 +16,3 @@ Copyright (c) Microsoft Corporation.

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var T=function(){function e(e){if(this.context=e,!this.context.authState.isUsingRefreshToken)throw new Error("The app doesn't implement 'refreshToken' feature.\nSo you have to implement refresh token feature from 'AuthProvider' before using it.")}return e.prototype.getCurrentRefreshToken=function(){return{refreshToken:this.context.authState.refreshToken,refreshTokenExpireAt:this.context.authState.refreshTokenExpireAt}},e.prototype.getCurrentAuthState=function(){return{authToken:this.context.authState.authTokenType,authTokenType:this.context.authState.authToken,expireAt:this.context.authState.expireAt}},e.prototype.getCurrentUserState=function(){return this.context.authState.authState},e.prototype.updateRefreshToken=function(e,t){var n=new Date((new Date).getTime()+60*t*1e3);this.context.setAuthState((function(t){return l(l({},t),{refreshToken:e,refreshTokenExpireAt:n})}))},e.prototype.updateAuthState=function(e,t,n){var r={authToken:e};if(void 0!==t&&Object.assign(r,{authTokenType:t}),void 0!==n){var o=new Date((new Date).getTime()+60*n*1e3);Object.assign(r,{expireAt:o})}this.context.setAuthState((function(e){return l(l({},e),r)}))},e.prototype.updateUserState=function(e){this.context.setAuthState((function(t){return l(l({},t),{authState:e})}))},e}();e.AuthProvider=h,e.PrivateRoute=function(e){var n=t.useContext(i),o=e.component,a=e.loginPath,u=e.strict,h=e.sensitive,s=e.exact,T=e.path,f=e.location,c=e.render;return t.createElement(r.Route,{location:f,path:T,exact:s,sensitive:h,strict:u,render:function(e){return(null==n?void 0:n.authState.authToken)&&(null==n?void 0:n.authState.expireAt)&&(new Date(n.authState.expireAt)>new Date||(n.setAuthState((function(e){return l(l({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),0))?o?t.createElement(o,e):c?c(e):null:t.createElement(r.Redirect,{to:a})}})},e.useAuth=
***************************************************************************** */var T=function(){function e(e){if(this.context=e,!this.context.authState.isUsingRefreshToken)throw new Error("The app doesn't implement 'refreshToken' feature.\nSo you have to implement refresh token feature from 'AuthProvider' before using it.")}return e.prototype.getCurrentRefreshToken=function(){return{refreshToken:this.context.authState.refreshToken,refreshTokenExpireAt:this.context.authState.refreshTokenExpireAt}},e.prototype.getCurrentAuthState=function(){return{authToken:this.context.authState.authTokenType,authTokenType:this.context.authState.authToken,expireAt:this.context.authState.expireAt}},e.prototype.getCurrentUserState=function(){return this.context.authState.authState},e.prototype.updateRefreshToken=function(e,t){var n=new Date((new Date).getTime()+60*t*1e3);this.context.setAuthState((function(t){return l(l({},t),{refreshToken:e,refreshTokenExpireAt:n})}))},e.prototype.updateAuthState=function(e,t,n){var r={authToken:e};if(void 0!==t&&Object.assign(r,{authTokenType:t}),void 0!==n){var o=new Date((new Date).getTime()+60*n*1e3);Object.assign(r,{expireAt:o})}this.context.setAuthState((function(e){return l(l({},e),r)}))},e.prototype.updateUserState=function(e){this.context.setAuthState((function(t){return l(l({},t),{authState:e})}))},e}();e.AuthProvider=h,e.PrivateRoute=function(e){var n=t.useContext(i),o=e.component,a=e.loginPath,u=e.strict,h=e.sensitive,s=e.exact,T=e.path,f=e.location,k=e.render;return t.createElement(r.Route,{location:f,path:T,exact:s,sensitive:h,strict:u,render:function(e){return(null==n?void 0:n.authState.authToken)&&(null==n?void 0:n.authState.expireAt)&&(new Date(n.authState.expireAt)>new Date||(n.setAuthState((function(e){return l(l({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),0))?o?t.createElement(o,e):k?k(e):null:t.createElement(r.Redirect,{to:a})}})},e.useAuth=
/**

@@ -19,0 +19,0 @@ *@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

{
"name": "react-auth-kit",
"version": "1.4.2-0",
"version": "1.4.3-0",
"description": "Authentication Library for React",

@@ -5,0 +5,0 @@ "source": "src/index.tsx",

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