New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.11 to 1.4.12

dist/__tests__/AuthProvider.test.d.ts

4

CHANGELOG.md

@@ -7,2 +7,6 @@ # Changelog

## [1.4.12] - 2021-07-25
### Changed:
- PrivateRouteProps is updated to give more type checking
## [1.4.11] - 2021-06-19

@@ -9,0 +13,0 @@ ### Changed:

5

dist/AuthProvider.d.ts
import * as React from 'react';
import { AuthContextInterface, AuthProviderProps } from './types';
declare const AuthContext: React.Context<AuthContextInterface>;
import { AuthProviderProps } from './types';
/**

@@ -16,3 +15,1 @@ * AuthProvider - The Authentication Context Provider

export default AuthProvider;
declare const AuthContextConsumer: React.Consumer<AuthContextInterface>;
export { AuthContext, AuthContextConsumer };

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("js-cookie"),n=require("react-router-dom");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function o(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var a=o(e),u=r(t),i=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=u.default.get(this.authStorageName),t=u.default.get(this.authStorageTypeName),n=u.default.get(this.authTimeStorageName),r=u.default.get(this.stateStorageName),o=this.isUsingRefreshToken&&null!=this.refreshTokenName?u.default.get(this.refreshTokenName):null,a=this.isUsingRefreshToken&&null!=this.refreshTokenTimeName?u.default.get(this.refreshTokenTimeName):null;return this.checkTokenExist(e,t,n,r,o,a)},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,a){u.default.set(this.authStorageName,e,{expires:r,domain:this.cookieDomain,secure:this.cookieSecure}),u.default.set(this.authStorageTypeName,t,{expires:r,domain:this.cookieDomain,secure:this.cookieSecure}),u.default.set(this.authTimeStorageName,r.toISOString(),{expires:r,domain:this.cookieDomain,secure:this.cookieSecure}),u.default.set(this.stateStorageName,a,{expires:r,domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenName&&n&&u.default.set(this.refreshTokenName,n,{expires:r,domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenTimeName&&o&&u.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(){u.default.remove(this.authStorageName,{domain:this.cookieDomain,secure:this.cookieSecure}),u.default.remove(this.authTimeStorageName,{domain:this.cookieDomain,secure:this.cookieSecure}),u.default.remove(this.stateStorageName,{domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenName&&u.default.remove(this.refreshTokenName,{domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenTimeName&&u.default.remove(this.refreshTokenTimeName,{domain:this.cookieDomain,secure:this.cookieSecure})},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}(),h=a.createContext({authState:{authTokenType:null,authState:null,authToken:null,isUsingRefreshToken:!1,refreshToken:null,refreshTokenExpireAt:null,expireAt:null},setAuthState:function(){}}),s=function(e){var t=e.children,n=e.authType,r=e.authName,o=e.refreshToken,u=e.cookieDomain,s=e.cookieSecure;if("cookie"===n&&!u)throw new Error("authStorageType 'cookie' requires 'cookieDomain' and 'cookieSecure' in AuthProvider");var l=new i({authTimeStorageName:r+"_time",authStorageType:n,authStorageName:r,refreshTokenName:o?r+"_refresh":void 0,cookieDomain:u,cookieSecure:s,stateStorageName:r+"_state"}),c=a.useState(l.initialToken()),T=c[0],f=c[1];return a.useEffect((function(){l.syncTokens(T)}),[T]),a.createElement(h.Provider,{value:{authState:T,setAuthState:f}},t)};s.defaultProps={authType:"cookie",authName:"_auth",cookieDomain:window.location.hostname,cookieSecure:"https:"===window.location.protocol};var l=h.Consumer,c=function(){return(c=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)};
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
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.authToken,authTokenType:this.context.authState.authTokenType,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 c(c({},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 c(c({},e),r)}))},e.prototype.updateUserState=function(e){this.context.setAuthState((function(t){return c(c({},t),{authState:e})}))},e}();exports.AuthProvider=s,exports.PrivateRoute=function(e){var t=a.useContext(h),r=e.component,o=e.loginPath,u=e.strict,i=e.sensitive,s=e.exact,l=e.path,T=e.location,f=e.render;return a.createElement(n.Route,{location:T,path:l,exact:s,sensitive:i,strict:u,render:function(e){return(null==t?void 0:t.authState.authToken)&&(null==t?void 0:t.authState.expireAt)&&(new Date(t.authState.expireAt)>new Date||(t.setAuthState((function(e){return c(c({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),0))?r?a.createElement(r,e):f?f(e):null:a.createElement(n.Redirect,{to:o})}})},exports.useAuth=
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("js-cookie"),r=require("react-router-dom");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function o(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var i=o(e),a=n(t),u=i.createContext(null),h=u.Consumer,s=function(){function e(e){var t=e.authStorageName,r=e.authStorageType,n=e.authTimeStorageName,o=e.stateStorageName,i=e.refreshTokenName,a=e.cookieDomain,u=e.cookieSecure;this.authStorageType=r,this.authStorageName=t,this.authTimeStorageName=n,this.stateStorageName=o,this.refreshTokenName=i,this.cookieDomain=a,this.cookieSecure=u,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),r=a.default.get(this.authTimeStorageName),n=a.default.get(this.stateStorageName),o=this.isUsingRefreshToken&&null!=this.refreshTokenName?a.default.get(this.refreshTokenName):null,i=this.isUsingRefreshToken&&null!=this.refreshTokenTimeName?a.default.get(this.refreshTokenTimeName):null;return this.checkTokenExist(e,t,r,n,o,i)},e.prototype.initialLSToken_=function(){var e=localStorage.getItem(this.authStorageName),t=localStorage.getItem(this.authStorageTypeName),r=localStorage.getItem(this.authTimeStorageName),n=localStorage.getItem(this.stateStorageName),o=this.isUsingRefreshToken&&null!=this.refreshTokenName?localStorage.getItem(this.refreshTokenName):null,i=this.isUsingRefreshToken&&null!=this.refreshTokenTimeName?localStorage.getItem(this.refreshTokenTimeName):null;return this.checkTokenExist(e,t,r,n,o,i)},e.prototype.checkTokenExist=function(e,t,r,n,o,i){if(!(e&&t&&r&&n))return{authToken:null,authTokenType:null,isUsingRefreshToken:this.isUsingRefreshToken,refreshToken:null,expireAt:null,authState:null,refreshTokenExpireAt:null};var a=new Date(r);try{var u=JSON.parse(n);return{authToken:e,authTokenType:t,isUsingRefreshToken:this.isUsingRefreshToken,refreshToken:this.isUsingRefreshToken&&o?o:null,refreshTokenExpireAt:this.isUsingRefreshToken&&i?new Date(i):null,expireAt:a,authState:u}}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,r,n,o,i){"cookie"===this.authStorageType?this.setCookieToken_(e,t,r,o,n,i):this.setLSToken_(e,t,r,o,n,i)},e.prototype.setCookieToken_=function(e,t,r,n,o,i){a.default.set(this.authStorageName,e,{expires:n,domain:this.cookieDomain,secure:this.cookieSecure}),a.default.set(this.authStorageTypeName,t,{expires:n,domain:this.cookieDomain,secure:this.cookieSecure}),a.default.set(this.authTimeStorageName,n.toISOString(),{expires:n,domain:this.cookieDomain,secure:this.cookieSecure}),a.default.set(this.stateStorageName,i,{expires:n,domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenName&&r&&a.default.set(this.refreshTokenName,r,{expires:n,domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenTimeName&&o&&a.default.set(this.refreshTokenTimeName,o.toISOString(),{expires:n,domain:this.cookieDomain,secure:this.cookieSecure})},e.prototype.setLSToken_=function(e,t,r,n,o,i){localStorage.setItem(this.authStorageName,e),localStorage.setItem(this.authStorageTypeName,t),localStorage.setItem(this.authTimeStorageName,n.toISOString()),localStorage.setItem(this.stateStorageName,JSON.stringify(i)),this.isUsingRefreshToken&&this.refreshTokenName&&r&&localStorage.setItem(this.refreshTokenName,r),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,{domain:this.cookieDomain,secure:this.cookieSecure}),a.default.remove(this.authTimeStorageName,{domain:this.cookieDomain,secure:this.cookieSecure}),a.default.remove(this.stateStorageName,{domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenName&&a.default.remove(this.refreshTokenName,{domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenTimeName&&a.default.remove(this.refreshTokenTimeName,{domain:this.cookieDomain,secure:this.cookieSecure})},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}(),l=function(e){var t=e.children,r=e.authType,n=e.authName,o=e.refreshToken,a=e.cookieDomain,h=e.cookieSecure;if("cookie"===r&&!a)throw new Error("authType 'cookie' requires 'cookieDomain' and 'cookieSecure' props in AuthProvider");var l=new s({authTimeStorageName:n+"_time",authStorageType:r,authStorageName:n,refreshTokenName:o?n+"_refresh":void 0,cookieDomain:a,cookieSecure:h,stateStorageName:n+"_state"}),f=i.useState(l.initialToken()),c=f[0],T=f[1];return i.useEffect((function(){l.syncTokens(c)}),[c]),i.createElement(u.Provider,{value:{authState:c,setAuthState:T}},t)},f=function(){return(f=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};var c=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.authToken,authTokenType:this.context.authState.authTokenType,expireAt:this.context.authState.expireAt}},e.prototype.getCurrentUserState=function(){return this.context.authState.authState},e.prototype.updateRefreshToken=function(e,t){var r=new Date((new Date).getTime()+60*t*1e3);this.context.setAuthState((function(t){return f(f({},t),{refreshToken:e,refreshTokenExpireAt:r})}))},e.prototype.updateAuthState=function(e,t,r){var n={authToken:e};if(void 0!==t&&Object.assign(n,{authTokenType:t}),void 0!==r){var o=new Date((new Date).getTime()+60*r*1e3);Object.assign(n,{expireAt:o})}this.context.setAuthState((function(e){return f(f({},e),n)}))},e.prototype.updateUserState=function(e){this.context.setAuthState((function(t){return f(f({},t),{authState:e})}))},e}();l.defaultProps={cookieDomain:window.location.hostname,cookieSecure:"https:"===window.location.protocol},exports.AuthProvider=l,exports.PrivateRoute=function(e){var t=i.useContext(u);if(null===t)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");var n=e.component,o=e.loginPath,a=e.strict,h=e.sensitive,s=e.exact,l=e.path,c=e.location,T=e.render;return i.createElement(r.Route,{location:c,path:l,exact:s,sensitive:h,strict:a,render:function(e){return t.authState.authToken&&t.authState.expireAt&&(new Date(t.authState.expireAt)>new Date||(t.setAuthState((function(e){return f(f({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),0))?n?i.createElement(n,e):T?T(e):null:i.createElement(r.Redirect,{to:o})}})},exports.useAuth=
/**

@@ -22,3 +8,3 @@ *@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

*/
function(){var e=a.useContext(h);return{authHeader:function(){return(null==e?void 0:e.authState)?e.authState.authTokenType+" "+e.authState.authToken:"Bearer "},isAuthenticated:function(){return!(!(null==e?void 0:e.authState.authToken)||!(null==e?void 0:e.authState.expireAt))&&(new Date(e.authState.expireAt)>new Date||(e.setAuthState((function(e){return c(c({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),!1))},authUser:function(){return e.authState.authState},signOut:function(){try{return!!(null==e?void 0:e.authState.authToken)&&(e.setAuthState((function(e){return c(c({},e),{authToken:null,authTokenType:null,refreshToken:null,refreshTokenExpireAt:null,expireAt:null,authState:null})})),console.log("RAJ :: Signing Out"),!0)}catch(e){return!1}},signIn:function(t){var n=t.token,r=t.tokenType,o=t.authState,a=t.expiresIn,u=t.refreshToken,i=t.refreshTokenExpireIn;if((u||i)&&!e.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.");var h=new Date((new Date).getTime()+60*a*1e3),s=i?new Date((new Date).getTime()+60*i*1e3):null;try{return!!e&&(e.setAuthState((function(e){return c(c({},e),{authToken:n,authTokenType:r,expireAt:h,authState:o,refreshToken:u||null,refreshTokenExpireAt:s})})),!0)}catch(e){return console.error(e),!1}}}}
function(){var e=i.useContext(u);if(null===e)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return{authHeader:function(){return(null==e?void 0:e.authState)?e.authState.authTokenType+" "+e.authState.authToken:"Bearer "},isAuthenticated:function(){return!(!(null==e?void 0:e.authState.authToken)||!(null==e?void 0:e.authState.expireAt))&&(new Date(e.authState.expireAt)>new Date||(e.setAuthState((function(e){return f(f({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),!1))},authUser:function(){return e.authState.authState},signOut:function(){try{return!!(null==e?void 0:e.authState.authToken)&&(e.setAuthState((function(e){return f(f({},e),{authToken:null,authTokenType:null,refreshToken:null,refreshTokenExpireAt:null,expireAt:null,authState:null})})),console.log("RAJ :: Signing Out"),!0)}catch(e){return!1}},signIn:function(t){var r=t.token,n=t.tokenType,o=t.authState,i=t.expiresIn,a=t.refreshToken,u=t.refreshTokenExpireIn;if((a||u)&&!e.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.");var h=new Date((new Date).getTime()+60*i*1e3),s=u?new Date((new Date).getTime()+60*u*1e3):null;try{return!!e&&(e.setAuthState((function(e){return f(f({},e),{authToken:r,authTokenType:n,expireAt:h,authState:o,refreshToken:a||null,refreshTokenExpireAt:s})})),!0)}catch(e){return console.error(e),!1}}}}
/**

@@ -29,3 +15,3 @@ *@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

*@license Apache-2.0
*/,exports.useAuthHeader=function(){var e=a.useContext(h);return function(){return(null==e?void 0:e.authState)?e.authState.authTokenType+" "+e.authState.authToken:"Bearer "}},exports.useAuthUser=function(){var e=a.useContext(h);return function(){return e.authState.authState}},exports.useIsAuthenticated=
*/,exports.useAuthHeader=function(){var e=i.useContext(u);if(null===e)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return function(){return(null==e?void 0:e.authState)?e.authState.authTokenType+" "+e.authState.authToken:"Bearer "}},exports.useAuthUser=function(){var e=i.useContext(u);if(null===e)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return function(){return e.authState.authState}},exports.useIsAuthenticated=
/**

@@ -37,3 +23,3 @@ *@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

*/
function(){var e=a.useContext(h);return function(){return!(!(null==e?void 0:e.authState.authToken)||!(null==e?void 0:e.authState.expireAt))&&(new Date(e.authState.expireAt)>new Date||(e.setAuthState((function(e){return c(c({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),!1))}},exports.useRefreshToken=function(){var e=a.useContext(h);return new T(e)},exports.useSignIn=function(){var e=a.useContext(h);return function(t){var n=t.token,r=t.tokenType,o=t.authState,a=t.expiresIn,u=t.refreshToken,i=t.refreshTokenExpireIn;if((u||i)&&!e.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.");var h=new Date((new Date).getTime()+60*a*1e3),s=i?new Date((new Date).getTime()+60*i*1e3):null;try{return!!e&&(e.setAuthState((function(e){return c(c({},e),{authToken:n,authTokenType:r,expireAt:h,authState:o,refreshToken:u||null,refreshTokenExpireAt:s})})),!0)}catch(e){return console.error(e),!1}}}
function(){var e=i.useContext(u);if(null===e)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return function(){return!(!(null==e?void 0:e.authState.authToken)||!(null==e?void 0:e.authState.expireAt))&&(new Date(e.authState.expireAt)>new Date||(e.setAuthState((function(e){return f(f({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),!1))}},exports.useRefreshToken=function(){var e=i.useContext(u);if(null===e)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return new c(e)},exports.useSignIn=function(){var e=i.useContext(u);if(null===e)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return function(t){var r=t.token,n=t.tokenType,o=t.authState,i=t.expiresIn,a=t.refreshToken,u=t.refreshTokenExpireIn;if((a||u)&&!e.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.");var h=new Date((new Date).getTime()+60*i*1e3),s=u?new Date((new Date).getTime()+60*u*1e3):null;try{return!!e&&(e.setAuthState((function(e){return f(f({},e),{authToken:r,authTokenType:n,expireAt:h,authState:o,refreshToken:a||null,refreshTokenExpireAt:s})})),!0)}catch(e){return console.error(e),!1}}}
/**

@@ -44,3 +30,3 @@ *@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

*@license Apache-2.0
*/,exports.useSignOut=function(){var e=a.useContext(h);return function(){try{return!!(null==e?void 0:e.authState.authToken)&&(e.setAuthState((function(e){return c(c({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),console.log("RAJ :: Signing Out"),!0)}catch(e){return!1}}},exports.withAuthHeader=
*/,exports.useSignOut=function(){var e=i.useContext(u);if(null===e)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return function(){try{return!!(null==e?void 0:e.authState.authToken)&&(e.setAuthState((function(e){return f(f({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),console.log("RAJ :: Signing Out"),!0)}catch(e){return!1}}},exports.withAuthHeader=
/**

@@ -52,3 +38,3 @@ *@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

*/
function(e){return function(t){return a.createElement(l,null,(function(n){return(null==n?void 0:n.authState)?a.createElement(e,c({},t,{authHeader:n.authState.authTokenType+" "+n.authState.authToken})):a.createElement(e,c({},t,{authHeader:null}))}))}}
function(e){return function(t){return i.createElement(h,null,(function(r){if(null===r)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return(null==r?void 0:r.authState)?i.createElement(e,f({},t,{authHeader:r.authState.authTokenType+" "+r.authState.authToken})):i.createElement(e,f({},t,{authHeader:null}))}))}}
/**

@@ -59,3 +45,3 @@ *@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

*@license Apache-2.0
*/,exports.withAuthUser=function(e){return function(t){return a.createElement(l,null,(function(n){return a.createElement(e,c({},t,{authState:null==n?void 0:n.authState.authState}))}))}},exports.withIsAuthenticated=
*/,exports.withAuthUser=function(e){return function(t){return i.createElement(h,null,(function(r){if(null===r)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return i.createElement(e,f({},t,{authState:null==r?void 0:r.authState.authState}))}))}},exports.withIsAuthenticated=
/**

@@ -67,3 +53,3 @@ *@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

*/
function(e){return function(t){return a.createElement(l,null,(function(n){return(null==n?void 0:n.authState.authToken)&&(null==n?void 0:n.authState.expireAt)?new Date(n.authState.expireAt)>new Date?a.createElement(e,c({},t,{isAuth:!0})):(n.setAuthState((function(e){return c(c({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),a.createElement(e,c({},t,{isAuth:!1}))):a.createElement(e,c({},t,{isAuth:!1}))}))}},exports.withRefreshToken=function(e){return function(t){return a.createElement(l,null,(function(n){return a.createElement(e,c({},t,{refreshToken:new T(n)}))}))}},exports.withSignIn=function(e){return function(t){return a.createElement(l,null,(function(n){return a.createElement(e,c({},t,{signIn:function(e){var t=e.token,r=e.tokenType,o=e.authState,a=e.expiresIn,u=e.refreshToken,i=e.refreshTokenExpireIn;if((u||i)&&!n.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.");var h=new Date((new Date).getTime()+60*a*1e3),s=i?new Date((new Date).getTime()+60*i*1e3):null;try{return!!n&&(n.setAuthState((function(e){return c(c({},e),{authToken:t,authTokenType:r,expireAt:h,authState:o,refreshToken:u||null,refreshTokenExpireAt:s})})),!0)}catch(e){return console.error(e),!1}}}))}))}},exports.withSignOut=function(e){return function(t){return a.createElement(l,null,(function(n){return a.createElement(e,c({},t,{signOut:function(){try{return!!(null==n?void 0:n.authState.authToken)&&(n.setAuthState((function(e){return c(c({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),!0)}catch(e){return!1}}}))}))}};
function(e){return function(t){return i.createElement(h,null,(function(r){if(null===r)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return(null==r?void 0:r.authState.authToken)&&(null==r?void 0:r.authState.expireAt)?new Date(r.authState.expireAt)>new Date?i.createElement(e,f({},t,{isAuth:!0})):(r.setAuthState((function(e){return f(f({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),i.createElement(e,f({},t,{isAuth:!1}))):i.createElement(e,f({},t,{isAuth:!1}))}))}},exports.withRefreshToken=function(e){return function(t){return i.createElement(h,null,(function(r){if(null===r)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return i.createElement(e,f({},t,{refreshToken:new c(r)}))}))}},exports.withSignIn=function(e){return function(t){return i.createElement(h,null,(function(r){if(null===r)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return i.createElement(e,f({},t,{signIn:function(e){var t=e.token,n=e.tokenType,o=e.authState,i=e.expiresIn,a=e.refreshToken,u=e.refreshTokenExpireIn;if((a||u)&&!r.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.");var h=new Date((new Date).getTime()+60*i*1e3),s=u?new Date((new Date).getTime()+60*u*1e3):null;try{return!!r&&(r.setAuthState((function(e){return f(f({},e),{authToken:t,authTokenType:n,expireAt:h,authState:o,refreshToken:a||null,refreshTokenExpireAt:s})})),!0)}catch(e){return console.error(e),!1}}}))}))}},exports.withSignOut=function(e){return function(t){return i.createElement(h,null,(function(r){if(null===r)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return i.createElement(e,f({},t,{signOut:function(){try{return!!(null==r?void 0:r.authState.authToken)&&(r.setAuthState((function(e){return f(f({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),!0)}catch(e){return!1}}}))}))}};
//# sourceMappingURL=index.js.map

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

import*as e from"react";import t from"js-cookie";import{Route as n,Redirect as r}from"react-router-dom";var o=function(){function e(e){var t=e.authStorageName,n=e.authStorageType,r=e.authTimeStorageName,o=e.stateStorageName,a=e.refreshTokenName,i=e.cookieDomain,u=e.cookieSecure;this.authStorageType=n,this.authStorageName=t,this.authTimeStorageName=r,this.stateStorageName=o,this.refreshTokenName=a,this.cookieDomain=i,this.cookieSecure=u,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=t.get(this.authStorageName),n=t.get(this.authStorageTypeName),r=t.get(this.authTimeStorageName),o=t.get(this.stateStorageName),a=this.isUsingRefreshToken&&null!=this.refreshTokenName?t.get(this.refreshTokenName):null,i=this.isUsingRefreshToken&&null!=this.refreshTokenTimeName?t.get(this.refreshTokenTimeName):null;return this.checkTokenExist(e,n,r,o,a,i)},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 i=new Date(n);try{var u=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:i,authState:u}}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,n,r,o,a,i){t.set(this.authStorageName,e,{expires:o,domain:this.cookieDomain,secure:this.cookieSecure}),t.set(this.authStorageTypeName,n,{expires:o,domain:this.cookieDomain,secure:this.cookieSecure}),t.set(this.authTimeStorageName,o.toISOString(),{expires:o,domain:this.cookieDomain,secure:this.cookieSecure}),t.set(this.stateStorageName,i,{expires:o,domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenName&&r&&t.set(this.refreshTokenName,r,{expires:o,domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenTimeName&&a&&t.set(this.refreshTokenTimeName,a.toISOString(),{expires:o,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(){t.remove(this.authStorageName,{domain:this.cookieDomain,secure:this.cookieSecure}),t.remove(this.authTimeStorageName,{domain:this.cookieDomain,secure:this.cookieSecure}),t.remove(this.stateStorageName,{domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenName&&t.remove(this.refreshTokenName,{domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenTimeName&&t.remove(this.refreshTokenTimeName,{domain:this.cookieDomain,secure:this.cookieSecure})},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}(),a=e.createContext({authState:{authTokenType:null,authState:null,authToken:null,isUsingRefreshToken:!1,refreshToken:null,refreshTokenExpireAt:null,expireAt:null},setAuthState:function(){}}),i=function(t){var n=t.children,r=t.authType,i=t.authName,u=t.refreshToken,h=t.cookieDomain,s=t.cookieSecure;if("cookie"===r&&!h)throw new Error("authStorageType 'cookie' requires 'cookieDomain' and 'cookieSecure' in AuthProvider");var l=new o({authTimeStorageName:i+"_time",authStorageType:r,authStorageName:i,refreshTokenName:u?i+"_refresh":void 0,cookieDomain:h,cookieSecure:s,stateStorageName:i+"_state"}),T=e.useState(l.initialToken()),c=T[0],k=T[1];return e.useEffect((function(){l.syncTokens(c)}),[c]),e.createElement(a.Provider,{value:{authState:c,setAuthState:k}},n)};i.defaultProps={authType:"cookie",authName:"_auth",cookieDomain:window.location.hostname,cookieSecure:"https:"===window.location.protocol};var u=a.Consumer,h=function(){return(h=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)},s=function(t){var o=e.useContext(a),i=t.component,u=t.loginPath,s=t.strict,l=t.sensitive,T=t.exact,c=t.path,k=t.location,f=t.render;return e.createElement(n,{location:k,path:c,exact:T,sensitive:l,strict:s,render:function(t){return(null==o?void 0:o.authState.authToken)&&(null==o?void 0:o.authState.expireAt)&&(new Date(o.authState.expireAt)>new Date||(o.setAuthState((function(e){return h(h({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),0))?i?e.createElement(i,t):f?f(t):null:e.createElement(r,{to:u})}})};
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
import*as e from"react";import t from"js-cookie";import{Route as r,Redirect as n}from"react-router-dom";var o=e.createContext(null),i=o.Consumer,a=function(){function e(e){var t=e.authStorageName,r=e.authStorageType,n=e.authTimeStorageName,o=e.stateStorageName,i=e.refreshTokenName,a=e.cookieDomain,u=e.cookieSecure;this.authStorageType=r,this.authStorageName=t,this.authTimeStorageName=n,this.stateStorageName=o,this.refreshTokenName=i,this.cookieDomain=a,this.cookieSecure=u,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=t.get(this.authStorageName),r=t.get(this.authStorageTypeName),n=t.get(this.authTimeStorageName),o=t.get(this.stateStorageName),i=this.isUsingRefreshToken&&null!=this.refreshTokenName?t.get(this.refreshTokenName):null,a=this.isUsingRefreshToken&&null!=this.refreshTokenTimeName?t.get(this.refreshTokenTimeName):null;return this.checkTokenExist(e,r,n,o,i,a)},e.prototype.initialLSToken_=function(){var e=localStorage.getItem(this.authStorageName),t=localStorage.getItem(this.authStorageTypeName),r=localStorage.getItem(this.authTimeStorageName),n=localStorage.getItem(this.stateStorageName),o=this.isUsingRefreshToken&&null!=this.refreshTokenName?localStorage.getItem(this.refreshTokenName):null,i=this.isUsingRefreshToken&&null!=this.refreshTokenTimeName?localStorage.getItem(this.refreshTokenTimeName):null;return this.checkTokenExist(e,t,r,n,o,i)},e.prototype.checkTokenExist=function(e,t,r,n,o,i){if(!(e&&t&&r&&n))return{authToken:null,authTokenType:null,isUsingRefreshToken:this.isUsingRefreshToken,refreshToken:null,expireAt:null,authState:null,refreshTokenExpireAt:null};var a=new Date(r);try{var u=JSON.parse(n);return{authToken:e,authTokenType:t,isUsingRefreshToken:this.isUsingRefreshToken,refreshToken:this.isUsingRefreshToken&&o?o:null,refreshTokenExpireAt:this.isUsingRefreshToken&&i?new Date(i):null,expireAt:a,authState:u}}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,r,n,o,i){"cookie"===this.authStorageType?this.setCookieToken_(e,t,r,o,n,i):this.setLSToken_(e,t,r,o,n,i)},e.prototype.setCookieToken_=function(e,r,n,o,i,a){t.set(this.authStorageName,e,{expires:o,domain:this.cookieDomain,secure:this.cookieSecure}),t.set(this.authStorageTypeName,r,{expires:o,domain:this.cookieDomain,secure:this.cookieSecure}),t.set(this.authTimeStorageName,o.toISOString(),{expires:o,domain:this.cookieDomain,secure:this.cookieSecure}),t.set(this.stateStorageName,a,{expires:o,domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenName&&n&&t.set(this.refreshTokenName,n,{expires:o,domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenTimeName&&i&&t.set(this.refreshTokenTimeName,i.toISOString(),{expires:o,domain:this.cookieDomain,secure:this.cookieSecure})},e.prototype.setLSToken_=function(e,t,r,n,o,i){localStorage.setItem(this.authStorageName,e),localStorage.setItem(this.authStorageTypeName,t),localStorage.setItem(this.authTimeStorageName,n.toISOString()),localStorage.setItem(this.stateStorageName,JSON.stringify(i)),this.isUsingRefreshToken&&this.refreshTokenName&&r&&localStorage.setItem(this.refreshTokenName,r),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(){t.remove(this.authStorageName,{domain:this.cookieDomain,secure:this.cookieSecure}),t.remove(this.authTimeStorageName,{domain:this.cookieDomain,secure:this.cookieSecure}),t.remove(this.stateStorageName,{domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenName&&t.remove(this.refreshTokenName,{domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenTimeName&&t.remove(this.refreshTokenTimeName,{domain:this.cookieDomain,secure:this.cookieSecure})},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}(),u=function(t){var r=t.children,n=t.authType,i=t.authName,u=t.refreshToken,h=t.cookieDomain,s=t.cookieSecure;if("cookie"===n&&!h)throw new Error("authType 'cookie' requires 'cookieDomain' and 'cookieSecure' props in AuthProvider");var l=new a({authTimeStorageName:i+"_time",authStorageType:n,authStorageName:i,refreshTokenName:u?i+"_refresh":void 0,cookieDomain:h,cookieSecure:s,stateStorageName:i+"_state"}),T=e.useState(l.initialToken()),f=T[0],c=T[1];return e.useEffect((function(){l.syncTokens(f)}),[f]),e.createElement(o.Provider,{value:{authState:f,setAuthState:c}},r)},h=function(){return(h=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},s=function(t){var i=e.useContext(o);if(null===i)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");var a=t.component,u=t.loginPath,s=t.strict,l=t.sensitive,T=t.exact,f=t.path,c=t.location,k=t.render;return e.createElement(r,{location:c,path:f,exact:T,sensitive:l,strict:s,render:function(t){return i.authState.authToken&&i.authState.expireAt&&(new Date(i.authState.expireAt)>new Date||(i.setAuthState((function(e){return h(h({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),0))?a?e.createElement(a,t):k?k(t):null:e.createElement(n,{to:u})}})};
/**

@@ -22,3 +8,3 @@ *@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

*/
function l(){var t=e.useContext(a);return{authHeader:function(){return(null==t?void 0:t.authState)?t.authState.authTokenType+" "+t.authState.authToken:"Bearer "},isAuthenticated:function(){return!(!(null==t?void 0:t.authState.authToken)||!(null==t?void 0:t.authState.expireAt))&&(new Date(t.authState.expireAt)>new Date||(t.setAuthState((function(e){return h(h({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),!1))},authUser:function(){return t.authState.authState},signOut:function(){try{return!!(null==t?void 0:t.authState.authToken)&&(t.setAuthState((function(e){return h(h({},e),{authToken:null,authTokenType:null,refreshToken:null,refreshTokenExpireAt:null,expireAt:null,authState:null})})),console.log("RAJ :: Signing Out"),!0)}catch(e){return!1}},signIn:function(e){var n=e.token,r=e.tokenType,o=e.authState,a=e.expiresIn,i=e.refreshToken,u=e.refreshTokenExpireIn;if((i||u)&&!t.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.");var s=new Date((new Date).getTime()+60*a*1e3),l=u?new Date((new Date).getTime()+60*u*1e3):null;try{return!!t&&(t.setAuthState((function(e){return h(h({},e),{authToken:n,authTokenType:r,expireAt:s,authState:o,refreshToken:i||null,refreshTokenExpireAt:l})})),!0)}catch(e){return console.error(e),!1}}}}
function l(){var t=e.useContext(o);if(null===t)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return{authHeader:function(){return(null==t?void 0:t.authState)?t.authState.authTokenType+" "+t.authState.authToken:"Bearer "},isAuthenticated:function(){return!(!(null==t?void 0:t.authState.authToken)||!(null==t?void 0:t.authState.expireAt))&&(new Date(t.authState.expireAt)>new Date||(t.setAuthState((function(e){return h(h({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),!1))},authUser:function(){return t.authState.authState},signOut:function(){try{return!!(null==t?void 0:t.authState.authToken)&&(t.setAuthState((function(e){return h(h({},e),{authToken:null,authTokenType:null,refreshToken:null,refreshTokenExpireAt:null,expireAt:null,authState:null})})),console.log("RAJ :: Signing Out"),!0)}catch(e){return!1}},signIn:function(e){var r=e.token,n=e.tokenType,o=e.authState,i=e.expiresIn,a=e.refreshToken,u=e.refreshTokenExpireIn;if((a||u)&&!t.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.");var s=new Date((new Date).getTime()+60*i*1e3),l=u?new Date((new Date).getTime()+60*u*1e3):null;try{return!!t&&(t.setAuthState((function(e){return h(h({},e),{authToken:r,authTokenType:n,expireAt:s,authState:o,refreshToken:a||null,refreshTokenExpireAt:l})})),!0)}catch(e){return console.error(e),!1}}}}
/**

@@ -29,3 +15,3 @@ *@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

*@license Apache-2.0
*/function T(){var t=e.useContext(a);return function(e){var n=e.token,r=e.tokenType,o=e.authState,a=e.expiresIn,i=e.refreshToken,u=e.refreshTokenExpireIn;if((i||u)&&!t.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.");var s=new Date((new Date).getTime()+60*a*1e3),l=u?new Date((new Date).getTime()+60*u*1e3):null;try{return!!t&&(t.setAuthState((function(e){return h(h({},e),{authToken:n,authTokenType:r,expireAt:s,authState:o,refreshToken:i||null,refreshTokenExpireAt:l})})),!0)}catch(e){return console.error(e),!1}}}
*/function T(){var t=e.useContext(o);if(null===t)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return function(e){var r=e.token,n=e.tokenType,o=e.authState,i=e.expiresIn,a=e.refreshToken,u=e.refreshTokenExpireIn;if((a||u)&&!t.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.");var s=new Date((new Date).getTime()+60*i*1e3),l=u?new Date((new Date).getTime()+60*u*1e3):null;try{return!!t&&(t.setAuthState((function(e){return h(h({},e),{authToken:r,authTokenType:n,expireAt:s,authState:o,refreshToken:a||null,refreshTokenExpireAt:l})})),!0)}catch(e){return console.error(e),!1}}}
/**

@@ -36,3 +22,3 @@ *@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

*@license Apache-2.0
*/function c(){var t=e.useContext(a);return function(){try{return!!(null==t?void 0:t.authState.authToken)&&(t.setAuthState((function(e){return h(h({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),console.log("RAJ :: Signing Out"),!0)}catch(e){return!1}}}function k(){var t=e.useContext(a);return function(){return t.authState.authState}}function f(){var t=e.useContext(a);return function(){return(null==t?void 0:t.authState)?t.authState.authTokenType+" "+t.authState.authToken:"Bearer "}}var m=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.authToken,authTokenType:this.context.authState.authTokenType,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 h(h({},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 h(h({},e),r)}))},e.prototype.updateUserState=function(e){this.context.setAuthState((function(t){return h(h({},t),{authState:e})}))},e}();function S(){var t=e.useContext(a);return new m(t)}
*/function f(){var t=e.useContext(o);if(null===t)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return function(){try{return!!(null==t?void 0:t.authState.authToken)&&(t.setAuthState((function(e){return h(h({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),console.log("RAJ :: Signing Out"),!0)}catch(e){return!1}}}function c(){var t=e.useContext(o);if(null===t)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return function(){return t.authState.authState}}function k(){var t=e.useContext(o);if(null===t)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return function(){return(null==t?void 0:t.authState)?t.authState.authTokenType+" "+t.authState.authToken:"Bearer "}}var m=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.authToken,authTokenType:this.context.authState.authTokenType,expireAt:this.context.authState.expireAt}},e.prototype.getCurrentUserState=function(){return this.context.authState.authState},e.prototype.updateRefreshToken=function(e,t){var r=new Date((new Date).getTime()+60*t*1e3);this.context.setAuthState((function(t){return h(h({},t),{refreshToken:e,refreshTokenExpireAt:r})}))},e.prototype.updateAuthState=function(e,t,r){var n={authToken:e};if(void 0!==t&&Object.assign(n,{authTokenType:t}),void 0!==r){var o=new Date((new Date).getTime()+60*r*1e3);Object.assign(n,{expireAt:o})}this.context.setAuthState((function(e){return h(h({},e),n)}))},e.prototype.updateUserState=function(e){this.context.setAuthState((function(t){return h(h({},t),{authState:e})}))},e}();function S(){var t=e.useContext(o);if(null===t)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return new m(t)}
/**

@@ -43,3 +29,3 @@ *@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

*@license Apache-2.0
*/function p(){var t=e.useContext(a);return function(){return!(!(null==t?void 0:t.authState.authToken)||!(null==t?void 0:t.authState.expireAt))&&(new Date(t.authState.expireAt)>new Date||(t.setAuthState((function(e){return h(h({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),!1))}}function g(t){return function(n){return e.createElement(u,null,(function(r){return e.createElement(t,h({},n,{signIn:function(e){var t=e.token,n=e.tokenType,o=e.authState,a=e.expiresIn,i=e.refreshToken,u=e.refreshTokenExpireIn;if((i||u)&&!r.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.");var s=new Date((new Date).getTime()+60*a*1e3),l=u?new Date((new Date).getTime()+60*u*1e3):null;try{return!!r&&(r.setAuthState((function(e){return h(h({},e),{authToken:t,authTokenType:n,expireAt:s,authState:o,refreshToken:i||null,refreshTokenExpireAt:l})})),!0)}catch(e){return console.error(e),!1}}}))}))}}function x(t){return function(n){return e.createElement(u,null,(function(r){return e.createElement(t,h({},n,{signOut:function(){try{return!!(null==r?void 0:r.authState.authToken)&&(r.setAuthState((function(e){return h(h({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),!0)}catch(e){return!1}}}))}))}}function v(t){return function(n){return e.createElement(u,null,(function(r){return e.createElement(t,h({},n,{authState:null==r?void 0:r.authState.authState}))}))}}
*/function p(){var t=e.useContext(o);if(null===t)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return function(){return!(!(null==t?void 0:t.authState.authToken)||!(null==t?void 0:t.authState.expireAt))&&(new Date(t.authState.expireAt)>new Date||(t.setAuthState((function(e){return h(h({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),!1))}}function g(t){return function(r){return e.createElement(i,null,(function(n){if(null===n)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return e.createElement(t,h({},r,{signIn:function(e){var t=e.token,r=e.tokenType,o=e.authState,i=e.expiresIn,a=e.refreshToken,u=e.refreshTokenExpireIn;if((a||u)&&!n.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.");var s=new Date((new Date).getTime()+60*i*1e3),l=u?new Date((new Date).getTime()+60*u*1e3):null;try{return!!n&&(n.setAuthState((function(e){return h(h({},e),{authToken:t,authTokenType:r,expireAt:s,authState:o,refreshToken:a||null,refreshTokenExpireAt:l})})),!0)}catch(e){return console.error(e),!1}}}))}))}}function d(t){return function(r){return e.createElement(i,null,(function(n){if(null===n)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return e.createElement(t,h({},r,{signOut:function(){try{return!!(null==n?void 0:n.authState.authToken)&&(n.setAuthState((function(e){return h(h({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),!0)}catch(e){return!1}}}))}))}}function v(t){return function(r){return e.createElement(i,null,(function(n){if(null===n)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return e.createElement(t,h({},r,{authState:null==n?void 0:n.authState.authState}))}))}}
/**

@@ -50,3 +36,3 @@ *@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

*@license Apache-2.0
*/function y(t){return function(n){return e.createElement(u,null,(function(r){return(null==r?void 0:r.authState)?e.createElement(t,h({},n,{authHeader:r.authState.authTokenType+" "+r.authState.authToken})):e.createElement(t,h({},n,{authHeader:null}))}))}}
*/function A(t){return function(r){return e.createElement(i,null,(function(n){if(null===n)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return(null==n?void 0:n.authState)?e.createElement(t,h({},r,{authHeader:n.authState.authTokenType+" "+n.authState.authToken})):e.createElement(t,h({},r,{authHeader:null}))}))}}
/**

@@ -57,3 +43,3 @@ *@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

*@license Apache-2.0
*/function A(t){return function(n){return e.createElement(u,null,(function(r){return e.createElement(t,h({},n,{refreshToken:new m(r)}))}))}}
*/function x(t){return function(r){return e.createElement(i,null,(function(n){if(null===n)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return e.createElement(t,h({},r,{refreshToken:new m(n)}))}))}}
/**

@@ -64,3 +50,3 @@ *@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

*@license Apache-2.0
*/function N(t){return function(n){return e.createElement(u,null,(function(r){return(null==r?void 0:r.authState.authToken)&&(null==r?void 0:r.authState.expireAt)?new Date(r.authState.expireAt)>new Date?e.createElement(t,h({},n,{isAuth:!0})):(r.setAuthState((function(e){return h(h({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),e.createElement(t,h({},n,{isAuth:!1}))):e.createElement(t,h({},n,{isAuth:!1}))}))}}export{i as AuthProvider,s as PrivateRoute,l as useAuth,f as useAuthHeader,k as useAuthUser,p as useIsAuthenticated,S as useRefreshToken,T as useSignIn,c as useSignOut,y as withAuthHeader,v as withAuthUser,N as withIsAuthenticated,A as withRefreshToken,g as withSignIn,x as withSignOut};
*/function w(t){return function(r){return e.createElement(i,null,(function(n){if(null===n)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return(null==n?void 0:n.authState.authToken)&&(null==n?void 0:n.authState.expireAt)?new Date(n.authState.expireAt)>new Date?e.createElement(t,h({},r,{isAuth:!0})):(n.setAuthState((function(e){return h(h({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),e.createElement(t,h({},r,{isAuth:!1}))):e.createElement(t,h({},r,{isAuth:!1}))}))}}u.defaultProps={cookieDomain:window.location.hostname,cookieSecure:"https:"===window.location.protocol};export{u as AuthProvider,s as PrivateRoute,l as useAuth,k as useAuthHeader,c as useAuthUser,p as useIsAuthenticated,S as useRefreshToken,T as useSignIn,f as useSignOut,A as withAuthHeader,v as withAuthUser,w as withIsAuthenticated,x as withRefreshToken,g as withSignIn,d as withSignOut};
//# sourceMappingURL=index.modern.js.map

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

/*! react-auth-kit v1.4.11 | 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}}function a(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var u=a(t),i=o(n),h=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=i.default.get(this.authStorageName),t=i.default.get(this.authStorageTypeName),n=i.default.get(this.authTimeStorageName),r=i.default.get(this.stateStorageName),o=this.isUsingRefreshToken&&null!=this.refreshTokenName?i.default.get(this.refreshTokenName):null,a=this.isUsingRefreshToken&&null!=this.refreshTokenTimeName?i.default.get(this.refreshTokenTimeName):null;return this.checkTokenExist(e,t,n,r,o,a)},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,a){i.default.set(this.authStorageName,e,{expires:r,domain:this.cookieDomain,secure:this.cookieSecure}),i.default.set(this.authStorageTypeName,t,{expires:r,domain:this.cookieDomain,secure:this.cookieSecure}),i.default.set(this.authTimeStorageName,r.toISOString(),{expires:r,domain:this.cookieDomain,secure:this.cookieSecure}),i.default.set(this.stateStorageName,a,{expires:r,domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenName&&n&&i.default.set(this.refreshTokenName,n,{expires:r,domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenTimeName&&o&&i.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(){i.default.remove(this.authStorageName,{domain:this.cookieDomain,secure:this.cookieSecure}),i.default.remove(this.authTimeStorageName,{domain:this.cookieDomain,secure:this.cookieSecure}),i.default.remove(this.stateStorageName,{domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenName&&i.default.remove(this.refreshTokenName,{domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenTimeName&&i.default.remove(this.refreshTokenTimeName,{domain:this.cookieDomain,secure:this.cookieSecure})},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}(),s=u.createContext({authState:{authTokenType:null,authState:null,authToken:null,isUsingRefreshToken:!1,refreshToken:null,refreshTokenExpireAt:null,expireAt:null},setAuthState:function(){}}),l=function(e){var t=e.children,n=e.authType,r=e.authName,o=e.refreshToken,a=e.cookieDomain,i=e.cookieSecure;if("cookie"===n&&!a)throw new Error("authStorageType 'cookie' requires 'cookieDomain' and 'cookieSecure' in AuthProvider");var l=new h({authTimeStorageName:r+"_time",authStorageType:n,authStorageName:r,refreshTokenName:o?r+"_refresh":void 0,cookieDomain:a,cookieSecure:i,stateStorageName:r+"_state"}),c=u.useState(l.initialToken()),f=c[0],T=c[1];return u.useEffect((function(){l.syncTokens(f)}),[f]),u.createElement(s.Provider,{value:{authState:f,setAuthState:T}},t)};l.defaultProps={authType:"cookie",authName:"_auth",cookieDomain:window.location.hostname,cookieSecure:"https:"===window.location.protocol};var c=s.Consumer,f=function(){return(f=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)};
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
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.authToken,authTokenType:this.context.authState.authTokenType,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 f(f({},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 f(f({},e),r)}))},e.prototype.updateUserState=function(e){this.context.setAuthState((function(t){return f(f({},t),{authState:e})}))},e}();e.AuthProvider=l,e.PrivateRoute=function(e){var t=u.useContext(s),n=e.component,o=e.loginPath,a=e.strict,i=e.sensitive,h=e.exact,l=e.path,c=e.location,T=e.render;return u.createElement(r.Route,{location:c,path:l,exact:h,sensitive:i,strict:a,render:function(e){return(null==t?void 0:t.authState.authToken)&&(null==t?void 0:t.authState.expireAt)&&(new Date(t.authState.expireAt)>new Date||(t.setAuthState((function(e){return f(f({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),0))?n?u.createElement(n,e):T?T(e):null:u.createElement(r.Redirect,{to:o})}})},e.useAuth=
/*! react-auth-kit v1.4.12 | 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,r,n){"use strict";function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function i(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var u=i(t),a=o(r),h=u.createContext(null),s=h.Consumer,l=function(){function e(e){var t=e.authStorageName,r=e.authStorageType,n=e.authTimeStorageName,o=e.stateStorageName,i=e.refreshTokenName,u=e.cookieDomain,a=e.cookieSecure;this.authStorageType=r,this.authStorageName=t,this.authTimeStorageName=n,this.stateStorageName=o,this.refreshTokenName=i,this.cookieDomain=u,this.cookieSecure=a,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),r=a.default.get(this.authTimeStorageName),n=a.default.get(this.stateStorageName),o=this.isUsingRefreshToken&&null!=this.refreshTokenName?a.default.get(this.refreshTokenName):null,i=this.isUsingRefreshToken&&null!=this.refreshTokenTimeName?a.default.get(this.refreshTokenTimeName):null;return this.checkTokenExist(e,t,r,n,o,i)},e.prototype.initialLSToken_=function(){var e=localStorage.getItem(this.authStorageName),t=localStorage.getItem(this.authStorageTypeName),r=localStorage.getItem(this.authTimeStorageName),n=localStorage.getItem(this.stateStorageName),o=this.isUsingRefreshToken&&null!=this.refreshTokenName?localStorage.getItem(this.refreshTokenName):null,i=this.isUsingRefreshToken&&null!=this.refreshTokenTimeName?localStorage.getItem(this.refreshTokenTimeName):null;return this.checkTokenExist(e,t,r,n,o,i)},e.prototype.checkTokenExist=function(e,t,r,n,o,i){if(!(e&&t&&r&&n))return{authToken:null,authTokenType:null,isUsingRefreshToken:this.isUsingRefreshToken,refreshToken:null,expireAt:null,authState:null,refreshTokenExpireAt:null};var u=new Date(r);try{var a=JSON.parse(n);return{authToken:e,authTokenType:t,isUsingRefreshToken:this.isUsingRefreshToken,refreshToken:this.isUsingRefreshToken&&o?o:null,refreshTokenExpireAt:this.isUsingRefreshToken&&i?new Date(i):null,expireAt:u,authState:a}}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,r,n,o,i){"cookie"===this.authStorageType?this.setCookieToken_(e,t,r,o,n,i):this.setLSToken_(e,t,r,o,n,i)},e.prototype.setCookieToken_=function(e,t,r,n,o,i){a.default.set(this.authStorageName,e,{expires:n,domain:this.cookieDomain,secure:this.cookieSecure}),a.default.set(this.authStorageTypeName,t,{expires:n,domain:this.cookieDomain,secure:this.cookieSecure}),a.default.set(this.authTimeStorageName,n.toISOString(),{expires:n,domain:this.cookieDomain,secure:this.cookieSecure}),a.default.set(this.stateStorageName,i,{expires:n,domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenName&&r&&a.default.set(this.refreshTokenName,r,{expires:n,domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenTimeName&&o&&a.default.set(this.refreshTokenTimeName,o.toISOString(),{expires:n,domain:this.cookieDomain,secure:this.cookieSecure})},e.prototype.setLSToken_=function(e,t,r,n,o,i){localStorage.setItem(this.authStorageName,e),localStorage.setItem(this.authStorageTypeName,t),localStorage.setItem(this.authTimeStorageName,n.toISOString()),localStorage.setItem(this.stateStorageName,JSON.stringify(i)),this.isUsingRefreshToken&&this.refreshTokenName&&r&&localStorage.setItem(this.refreshTokenName,r),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,{domain:this.cookieDomain,secure:this.cookieSecure}),a.default.remove(this.authTimeStorageName,{domain:this.cookieDomain,secure:this.cookieSecure}),a.default.remove(this.stateStorageName,{domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenName&&a.default.remove(this.refreshTokenName,{domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenTimeName&&a.default.remove(this.refreshTokenTimeName,{domain:this.cookieDomain,secure:this.cookieSecure})},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}(),f=function(e){var t=e.children,r=e.authType,n=e.authName,o=e.refreshToken,i=e.cookieDomain,a=e.cookieSecure;if("cookie"===r&&!i)throw new Error("authType 'cookie' requires 'cookieDomain' and 'cookieSecure' props in AuthProvider");var s=new l({authTimeStorageName:n+"_time",authStorageType:r,authStorageName:n,refreshTokenName:o?n+"_refresh":void 0,cookieDomain:i,cookieSecure:a,stateStorageName:n+"_state"}),f=u.useState(s.initialToken()),c=f[0],T=f[1];return u.useEffect((function(){s.syncTokens(c)}),[c]),u.createElement(h.Provider,{value:{authState:c,setAuthState:T}},t)},c=function(){return(c=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};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.authToken,authTokenType:this.context.authState.authTokenType,expireAt:this.context.authState.expireAt}},e.prototype.getCurrentUserState=function(){return this.context.authState.authState},e.prototype.updateRefreshToken=function(e,t){var r=new Date((new Date).getTime()+60*t*1e3);this.context.setAuthState((function(t){return c(c({},t),{refreshToken:e,refreshTokenExpireAt:r})}))},e.prototype.updateAuthState=function(e,t,r){var n={authToken:e};if(void 0!==t&&Object.assign(n,{authTokenType:t}),void 0!==r){var o=new Date((new Date).getTime()+60*r*1e3);Object.assign(n,{expireAt:o})}this.context.setAuthState((function(e){return c(c({},e),n)}))},e.prototype.updateUserState=function(e){this.context.setAuthState((function(t){return c(c({},t),{authState:e})}))},e}();f.defaultProps={cookieDomain:window.location.hostname,cookieSecure:"https:"===window.location.protocol},e.AuthProvider=f,e.PrivateRoute=function(e){var t=u.useContext(h);if(null===t)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");var r=e.component,o=e.loginPath,i=e.strict,a=e.sensitive,s=e.exact,l=e.path,f=e.location,T=e.render;return u.createElement(n.Route,{location:f,path:l,exact:s,sensitive:a,strict:i,render:function(e){return t.authState.authToken&&t.authState.expireAt&&(new Date(t.authState.expireAt)>new Date||(t.setAuthState((function(e){return c(c({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),0))?r?u.createElement(r,e):T?T(e):null:u.createElement(n.Redirect,{to:o})}})},e.useAuth=
/**

@@ -23,3 +9,3 @@ *@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

*/
function(){var e=u.useContext(s);return{authHeader:function(){return(null==e?void 0:e.authState)?e.authState.authTokenType+" "+e.authState.authToken:"Bearer "},isAuthenticated:function(){return!(!(null==e?void 0:e.authState.authToken)||!(null==e?void 0:e.authState.expireAt))&&(new Date(e.authState.expireAt)>new Date||(e.setAuthState((function(e){return f(f({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),!1))},authUser:function(){return e.authState.authState},signOut:function(){try{return!!(null==e?void 0:e.authState.authToken)&&(e.setAuthState((function(e){return f(f({},e),{authToken:null,authTokenType:null,refreshToken:null,refreshTokenExpireAt:null,expireAt:null,authState:null})})),console.log("RAJ :: Signing Out"),!0)}catch(e){return!1}},signIn:function(t){var n=t.token,r=t.tokenType,o=t.authState,a=t.expiresIn,u=t.refreshToken,i=t.refreshTokenExpireIn;if((u||i)&&!e.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.");var h=new Date((new Date).getTime()+60*a*1e3),s=i?new Date((new Date).getTime()+60*i*1e3):null;try{return!!e&&(e.setAuthState((function(e){return f(f({},e),{authToken:n,authTokenType:r,expireAt:h,authState:o,refreshToken:u||null,refreshTokenExpireAt:s})})),!0)}catch(e){return console.error(e),!1}}}}
function(){var e=u.useContext(h);if(null===e)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return{authHeader:function(){return(null==e?void 0:e.authState)?e.authState.authTokenType+" "+e.authState.authToken:"Bearer "},isAuthenticated:function(){return!(!(null==e?void 0:e.authState.authToken)||!(null==e?void 0:e.authState.expireAt))&&(new Date(e.authState.expireAt)>new Date||(e.setAuthState((function(e){return c(c({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),!1))},authUser:function(){return e.authState.authState},signOut:function(){try{return!!(null==e?void 0:e.authState.authToken)&&(e.setAuthState((function(e){return c(c({},e),{authToken:null,authTokenType:null,refreshToken:null,refreshTokenExpireAt:null,expireAt:null,authState:null})})),console.log("RAJ :: Signing Out"),!0)}catch(e){return!1}},signIn:function(t){var r=t.token,n=t.tokenType,o=t.authState,i=t.expiresIn,u=t.refreshToken,a=t.refreshTokenExpireIn;if((u||a)&&!e.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.");var h=new Date((new Date).getTime()+60*i*1e3),s=a?new Date((new Date).getTime()+60*a*1e3):null;try{return!!e&&(e.setAuthState((function(e){return c(c({},e),{authToken:r,authTokenType:n,expireAt:h,authState:o,refreshToken:u||null,refreshTokenExpireAt:s})})),!0)}catch(e){return console.error(e),!1}}}}
/**

@@ -30,3 +16,3 @@ *@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

*@license Apache-2.0
*/,e.useAuthHeader=function(){var e=u.useContext(s);return function(){return(null==e?void 0:e.authState)?e.authState.authTokenType+" "+e.authState.authToken:"Bearer "}},e.useAuthUser=function(){var e=u.useContext(s);return function(){return e.authState.authState}},e.useIsAuthenticated=
*/,e.useAuthHeader=function(){var e=u.useContext(h);if(null===e)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return function(){return(null==e?void 0:e.authState)?e.authState.authTokenType+" "+e.authState.authToken:"Bearer "}},e.useAuthUser=function(){var e=u.useContext(h);if(null===e)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return function(){return e.authState.authState}},e.useIsAuthenticated=
/**

@@ -38,3 +24,3 @@ *@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

*/
function(){var e=u.useContext(s);return function(){return!(!(null==e?void 0:e.authState.authToken)||!(null==e?void 0:e.authState.expireAt))&&(new Date(e.authState.expireAt)>new Date||(e.setAuthState((function(e){return f(f({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),!1))}},e.useRefreshToken=function(){var e=u.useContext(s);return new T(e)},e.useSignIn=function(){var e=u.useContext(s);return function(t){var n=t.token,r=t.tokenType,o=t.authState,a=t.expiresIn,u=t.refreshToken,i=t.refreshTokenExpireIn;if((u||i)&&!e.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.");var h=new Date((new Date).getTime()+60*a*1e3),s=i?new Date((new Date).getTime()+60*i*1e3):null;try{return!!e&&(e.setAuthState((function(e){return f(f({},e),{authToken:n,authTokenType:r,expireAt:h,authState:o,refreshToken:u||null,refreshTokenExpireAt:s})})),!0)}catch(e){return console.error(e),!1}}}
function(){var e=u.useContext(h);if(null===e)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return function(){return!(!(null==e?void 0:e.authState.authToken)||!(null==e?void 0:e.authState.expireAt))&&(new Date(e.authState.expireAt)>new Date||(e.setAuthState((function(e){return c(c({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),!1))}},e.useRefreshToken=function(){var e=u.useContext(h);if(null===e)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return new T(e)},e.useSignIn=function(){var e=u.useContext(h);if(null===e)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return function(t){var r=t.token,n=t.tokenType,o=t.authState,i=t.expiresIn,u=t.refreshToken,a=t.refreshTokenExpireIn;if((u||a)&&!e.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.");var h=new Date((new Date).getTime()+60*i*1e3),s=a?new Date((new Date).getTime()+60*a*1e3):null;try{return!!e&&(e.setAuthState((function(e){return c(c({},e),{authToken:r,authTokenType:n,expireAt:h,authState:o,refreshToken:u||null,refreshTokenExpireAt:s})})),!0)}catch(e){return console.error(e),!1}}}
/**

@@ -45,3 +31,3 @@ *@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

*@license Apache-2.0
*/,e.useSignOut=function(){var e=u.useContext(s);return function(){try{return!!(null==e?void 0:e.authState.authToken)&&(e.setAuthState((function(e){return f(f({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),console.log("RAJ :: Signing Out"),!0)}catch(e){return!1}}},e.withAuthHeader=
*/,e.useSignOut=function(){var e=u.useContext(h);if(null===e)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return function(){try{return!!(null==e?void 0:e.authState.authToken)&&(e.setAuthState((function(e){return c(c({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),console.log("RAJ :: Signing Out"),!0)}catch(e){return!1}}},e.withAuthHeader=
/**

@@ -53,3 +39,3 @@ *@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

*/
function(e){return function(t){return u.createElement(c,null,(function(n){return(null==n?void 0:n.authState)?u.createElement(e,f({},t,{authHeader:n.authState.authTokenType+" "+n.authState.authToken})):u.createElement(e,f({},t,{authHeader:null}))}))}}
function(e){return function(t){return u.createElement(s,null,(function(r){if(null===r)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return(null==r?void 0:r.authState)?u.createElement(e,c({},t,{authHeader:r.authState.authTokenType+" "+r.authState.authToken})):u.createElement(e,c({},t,{authHeader:null}))}))}}
/**

@@ -60,3 +46,3 @@ *@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

*@license Apache-2.0
*/,e.withAuthUser=function(e){return function(t){return u.createElement(c,null,(function(n){return u.createElement(e,f({},t,{authState:null==n?void 0:n.authState.authState}))}))}},e.withIsAuthenticated=
*/,e.withAuthUser=function(e){return function(t){return u.createElement(s,null,(function(r){if(null===r)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return u.createElement(e,c({},t,{authState:null==r?void 0:r.authState.authState}))}))}},e.withIsAuthenticated=
/**

@@ -68,3 +54,3 @@ *@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

*/
function(e){return function(t){return u.createElement(c,null,(function(n){return(null==n?void 0:n.authState.authToken)&&(null==n?void 0:n.authState.expireAt)?new Date(n.authState.expireAt)>new Date?u.createElement(e,f({},t,{isAuth:!0})):(n.setAuthState((function(e){return f(f({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),u.createElement(e,f({},t,{isAuth:!1}))):u.createElement(e,f({},t,{isAuth:!1}))}))}},e.withRefreshToken=function(e){return function(t){return u.createElement(c,null,(function(n){return u.createElement(e,f({},t,{refreshToken:new T(n)}))}))}},e.withSignIn=function(e){return function(t){return u.createElement(c,null,(function(n){return u.createElement(e,f({},t,{signIn:function(e){var t=e.token,r=e.tokenType,o=e.authState,a=e.expiresIn,u=e.refreshToken,i=e.refreshTokenExpireIn;if((u||i)&&!n.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.");var h=new Date((new Date).getTime()+60*a*1e3),s=i?new Date((new Date).getTime()+60*i*1e3):null;try{return!!n&&(n.setAuthState((function(e){return f(f({},e),{authToken:t,authTokenType:r,expireAt:h,authState:o,refreshToken:u||null,refreshTokenExpireAt:s})})),!0)}catch(e){return console.error(e),!1}}}))}))}},e.withSignOut=function(e){return function(t){return u.createElement(c,null,(function(n){return u.createElement(e,f({},t,{signOut:function(){try{return!!(null==n?void 0:n.authState.authToken)&&(n.setAuthState((function(e){return f(f({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),!0)}catch(e){return!1}}}))}))}},Object.defineProperty(e,"__esModule",{value:!0})}));
function(e){return function(t){return u.createElement(s,null,(function(r){if(null===r)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return(null==r?void 0:r.authState.authToken)&&(null==r?void 0:r.authState.expireAt)?new Date(r.authState.expireAt)>new Date?u.createElement(e,c({},t,{isAuth:!0})):(r.setAuthState((function(e){return c(c({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),u.createElement(e,c({},t,{isAuth:!1}))):u.createElement(e,c({},t,{isAuth:!1}))}))}},e.withRefreshToken=function(e){return function(t){return u.createElement(s,null,(function(r){if(null===r)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return u.createElement(e,c({},t,{refreshToken:new T(r)}))}))}},e.withSignIn=function(e){return function(t){return u.createElement(s,null,(function(r){if(null===r)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return u.createElement(e,c({},t,{signIn:function(e){var t=e.token,n=e.tokenType,o=e.authState,i=e.expiresIn,u=e.refreshToken,a=e.refreshTokenExpireIn;if((u||a)&&!r.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.");var h=new Date((new Date).getTime()+60*i*1e3),s=a?new Date((new Date).getTime()+60*a*1e3):null;try{return!!r&&(r.setAuthState((function(e){return c(c({},e),{authToken:t,authTokenType:n,expireAt:h,authState:o,refreshToken:u||null,refreshTokenExpireAt:s})})),!0)}catch(e){return console.error(e),!1}}}))}))}},e.withSignOut=function(e){return function(t){return u.createElement(s,null,(function(r){if(null===r)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return u.createElement(e,c({},t,{signOut:function(){try{return!!(null==r?void 0:r.authState.authToken)&&(r.setAuthState((function(e){return c(c({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),!0)}catch(e){return!1}}}))}))}},Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=index.umd.js.map
import * as React from 'react';
import { RouteProps } from 'react-router-dom';
interface PrivateRouteProps extends RouteProps {
import * as H from 'history';
import { RouteChildrenProps, RouteComponentProps } from 'react-router';
interface PrivateRouteProps {
loginPath: string;
location?: H.Location;
component?: React.ComponentType<RouteComponentProps<any>> | React.ComponentType<any>;
render?: (props: RouteComponentProps<any>) => React.ReactNode;
children?: ((props: RouteChildrenProps<any>) => React.ReactNode) | React.ReactNode;
path?: string | string[];
exact?: boolean;
sensitive?: boolean;
strict?: boolean;
}

@@ -6,0 +15,0 @@ /**

{
"name": "react-auth-kit",
"version": "1.4.11",
"version": "1.4.12",
"description": "Authentication Library for React, which makes Token based auth very easy",

@@ -18,11 +18,13 @@ "source": "src/index.tsx",

"start": "rollup -cw",
"build": "rollup -c",
"build": "run-s build:*",
"build:clean": "rimraf ./dist",
"build:dir": "mkdirp ./dist",
"build:build": "rollup -c",
"prepare": "run-s build",
"preversion": "run-s test",
"test": "run-s test:unit test:lint test:build",
"test": "run-s test:*",
"test:build": "run-s build",
"test:unit": "jest",
"test:lint": "eslint src/**/*.ts src/**/*.tsx",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage --colors",
"test:unit:watch": "jest --watch",
"fix": "eslint src/**/*.ts src/**/*.tsx --fix"

@@ -49,19 +51,23 @@ },

"devDependencies": {
"@rollup/plugin-node-resolve": "^13.0.0",
"@types/jest": "^26.0.23",
"@types/js-cookie": "^2.2.6",
"@types/node": "^15.12.2",
"@types/react": "^17.0.11",
"@types/react-dom": "^17.0.7",
"@types/react-router-dom": "^5.1.5",
"@typescript-eslint/eslint-plugin": "^4.27.0",
"@typescript-eslint/parser": "^4.27.0",
"eslint": "^7.28.0",
"@rollup/plugin-node-resolve": "^13.0.2",
"@testing-library/react": "^12.0.0",
"@types/jest": "^26.0.24",
"@types/js-cookie": "^2.2.7",
"@types/node": "^16.4.1",
"@types/react": "^17.0.14",
"@types/react-dom": "^17.0.9",
"@types/react-router-dom": "^5.1.8",
"@typescript-eslint/eslint-plugin": "^4.28.4",
"@typescript-eslint/parser": "^4.28.4",
"codecov": "^3.8.3",
"eslint": "^7.31.0",
"eslint-config-google": "^0.14.0",
"eslint-plugin-jest": "^24.0.0",
"eslint-plugin-jest": "^24.4.0",
"eslint-plugin-react": "^7.20.6",
"jest": "^27.0.4",
"jest": "^27.0.6",
"mkdirp": "^1.0.4",
"npm-run-all": "^4.1.5",
"react-dom": "^17.0.1",
"rollup": "^2.52.1",
"rimraf": "^3.0.2",
"rollup": "^2.53.3",
"rollup-plugin-filesize": "^9.0.2",

@@ -72,6 +78,6 @@ "rollup-plugin-license": "^2.2.0",

"rollup-plugin-typescript2": "^0.30.0",
"ts-jest": "^27.0.3",
"ts-jest": "^27.0.4",
"tslib": "^2.3.0",
"typedoc": "^0.21.0",
"typescript": "^4.3.4",
"typedoc": "^0.21.4",
"typescript": "^4.3.5",
"utility-types": "^3.10.0"

@@ -78,0 +84,0 @@ },

@@ -10,2 +10,7 @@ <p align="center">

<p align="center">
<a href="https://codecov.io/gh/react-auth-kit/react-auth-kit">
<img src="https://codecov.io/gh/react-auth-kit/react-auth-kit/branch/master/graph/badge.svg?token=H188T7PXLL"/>
</a>
<a href="https://github.com/react-auth-kit/react-auth-kit/workflows/NPM%20Deploy">

@@ -23,5 +28,2 @@ <img src="https://github.com/react-auth-kit/react-auth-kit/workflows/NPM%20Deploy/badge.svg" alt="NPM Deploy">

</a>
<a href="https://www.codacy.com/gh/react-auth-kit/react-auth-kit?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=react-auth-kit/react-auth-kit&amp;utm_campaign=Badge_Grade">
<img src="https://app.codacy.com/project/badge/Grade/a65202426152483d8e63d6623721080c" alt="Codacy Badge">
</a>
</p>

@@ -28,0 +30,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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