react-auth-kit
Advanced tools
Comparing version 1.3.3-0 to 1.3.4-0
@@ -1,2 +0,2 @@ | ||
/*! react-auth-kit v1.3.3-0 | Apache-2.0 */ | ||
/*! react-auth-kit v1.3.4-0 | Apache-2.0 */ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("js-cookie"),require("react-router-dom")):"function"==typeof define&&define.amd?define(["exports","react","js-cookie","react-router-dom"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).ReactAuthKit={},t.React,t.Cookies,t.reactRouterDom)}(this,(function(t,e,a,n){"use strict";function u(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var o=u(a),r=function(){function t(t){var e=t.authStorageName,a=t.authStorageType,n=t.authTimeStorageName,u=t.stateStorageName,o=t.cookieDomain,r=t.cookieSecure;this.authStorageType=a,this.authStorageName=e,this.authTimeStorageName=n,this.stateStorageName=u,this.cookieDomain=o,this.cookieSecure=r,this.authStorageTypeName=this.authStorageName+"_type"}return t.prototype.initialToken=function(){return"cookie"===this.authStorageType?this.initialCookieToken():this.initialLSToken()},t.prototype.initialCookieToken=function(){var t=o.default.get(this.authStorageName),e=o.default.get(this.authStorageTypeName),a=o.default.get(this.authTimeStorageName),n=o.default.get(this.stateStorageName);return this.checkTokenExist(t,e,a,n)},t.prototype.initialLSToken=function(){var t=localStorage.getItem(this.authStorageName),e=localStorage.getItem(this.authStorageTypeName),a=localStorage.getItem(this.authTimeStorageName),n=localStorage.getItem(this.stateStorageName);return this.checkTokenExist(t,e,a,n)},t.prototype.checkTokenExist=function(t,e,a,n){if(!(t&&e&&a&&n))return{authToken:null,authTokenType:null,expireAt:null,authState:null};var u=new Date(a);try{return{authToken:t,authTokenType:e,expireAt:u,authState:JSON.parse(n)}}catch(t){return{authToken:null,authTokenType:null,expireAt:null,authState:null}}},t.prototype.syncTokens=function(t){void 0===t.authToken||null===t.authTokenType||null===t.authToken||null===t.expireAt||null===t.authState?this.removeToken():this.setToken(t.authToken,t.authTokenType,t.expireAt,t.authState)},t.prototype.setToken=function(t,e,a,n){"cookie"===this.authStorageType?this.setCookieToken(t,e,a,n):this.setLSToken(t,e,a,n)},t.prototype.setCookieToken=function(t,e,a,n){o.default.set(this.authStorageName,t,{expires:a,domain:this.cookieDomain,secure:this.cookieSecure}),o.default.set(this.authStorageTypeName,e,{expires:a,domain:this.cookieDomain,secure:this.cookieSecure}),o.default.set(this.authTimeStorageName,a,{expires:a,domain:this.cookieDomain,secure:this.cookieSecure}),o.default.set(this.stateStorageName,n,{expires:a,domain:this.cookieDomain,secure:this.cookieSecure})},t.prototype.setLSToken=function(t,e,a,n){localStorage.setItem(this.authStorageName,t),localStorage.setItem(this.authStorageTypeName,e),localStorage.setItem(this.authTimeStorageName,a.toString()),localStorage.setItem(this.stateStorageName,JSON.stringify(n))},t.prototype.removeToken=function(){"cookie"===this.authStorageType?this.removeCookieToken():this.removeLSToken()},t.prototype.removeCookieToken=function(){o.default.remove(this.authStorageName),o.default.remove(this.authTimeStorageName),o.default.remove(this.stateStorageName)},t.prototype.removeLSToken=function(){localStorage.removeItem(this.authStorageName),localStorage.removeItem(this.authTimeStorageName),localStorage.removeItem(this.stateStorageName)},t}(),i=e.createContext({authState:{authTokenType:null,authState:null,authToken:null,expireAt:null},setAuthState:function(){}}),h=function(t){var a=t.children,n=t.authStorageType,u=t.authStorageName,o=t.authTimeStorageName,h=t.stateStorageName,l=t.cookieDomain,c=t.cookieSecure;if("cookie"===n&&!l)throw new Error("authStorageType 'cookie' requires 'cookieDomain' and 'cookieSecure' in AuthProvider");var s=new r({authTimeStorageName:o,authStorageType:n,authStorageName:u,cookieDomain:l,cookieSecure:c,stateStorageName:h}),S=e.useState(s.initialToken()),T=S[0],m=S[1];return e.useEffect((function(){s.syncTokens(T)}),[T]),e.createElement(i.Provider,{value:{authState:T,setAuthState:m}},a)};h.defaultProps={authStorageType:"cookie",authStorageName:"_auth_token",authTimeStorageName:"_auth_time",stateStorageName:"_auth_state",cookieSecure:!0};var l=i.Consumer,c=function(){return(c=Object.assign||function(t){for(var e,a=1,n=arguments.length;a<n;a++)for(var u in e=arguments[a])Object.prototype.hasOwnProperty.call(e,u)&&(t[u]=e[u]);return t}).apply(this,arguments)};t.AuthProvider=h,t.PrivateRoute=function(t){var a=e.useContext(i),u=t.component,o=t.loginPath,r=t.strict,h=t.sensitive,l=t.exact,c=t.path,s=t.location,S=t.render;return e.createElement(n.Route,{location:s,path:c,exact:l,sensitive:h,strict:r,render:function(t){return(null==a?void 0:a.authState.authToken)&&(null==a?void 0:a.authState.expireAt)&&(new Date(a.authState.expireAt)>new Date||(a.setAuthState({authToken:null,authTokenType:null,expireAt:null,authState:null}),0))?u?e.createElement(u,t):S?S(t):null:e.createElement(n.Redirect,{to:o})}})},t.useAuth= | ||
@@ -3,0 +3,0 @@ /** |
{ | ||
"name": "react-auth-kit", | ||
"version": "1.3.3-0", | ||
"version": "1.3.4-0", | ||
"description": "Authentication Library for React", | ||
@@ -74,3 +74,3 @@ "source": "src/index.tsx", | ||
"js-cookie": "^2.2.1", | ||
"react": "^17.0.1", | ||
"react": ">=16", | ||
"react-router-dom": "^5.2.0" | ||
@@ -80,5 +80,5 @@ }, | ||
"js-cookie": "^2.2.1", | ||
"react": "^17.0.1", | ||
"react": ">=16", | ||
"react-router-dom": "^5.2.0" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
89614
+ Addedreact@19.0.0(transitive)
- Removedreact@17.0.2(transitive)
Updatedreact@>=16