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

react-auth-kit

Package Overview
Dependencies
Maintainers
1
Versions
200
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-auth-kit - npm Package Compare versions

Comparing version 1.4.8 to 1.4.9

1004

dist/index.js

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

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var React = require('react');
var Cookies = require('js-cookie');
var reactRouterDom = require('react-router-dom');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () {
return e[k];
}
});
}
});
}
n['default'] = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/_interopNamespace(React);
var Cookies__default = /*#__PURE__*/_interopDefaultLegacy(Cookies);
/**
* @class TokenObject
*
* Stores and retrieve Token
*/
var TokenObject = /** @class */ (function () {
/**
* TokenObject - Stores, retrieve and process tokens
*
* @param authStorageName - Name of the Token,
* which will store the Authorization Token
*
* @param authStorageType - Type of the auth Storage, `
* cookie` or `localstorage`
*
* @param authTimeStorageName - Name of the Token,
* which will store the Expiring time of the Authorization Token
* @param stateStorageName - Name of the Token,
* which will store the User's state
*
* @param refreshTokenName - Name of the refresh Token,
* if `undefined`, then no refreshToken feature is using
*
* @param cookieDomain - domain name for the Cookies,
* only applicable when `authStorageType` is `cookie`
*
* @param cookieSecure - cookies are secure or not,
* only applicable when `authStorageType` is `cookie`
*
* @constructor
*/
function TokenObject(_a) {
var authStorageName = _a.authStorageName, authStorageType = _a.authStorageType, authTimeStorageName = _a.authTimeStorageName, stateStorageName = _a.stateStorageName, refreshTokenName = _a.refreshTokenName, cookieDomain = _a.cookieDomain, cookieSecure = _a.cookieSecure;
this.authStorageType = authStorageType;
this.authStorageName = authStorageName;
this.authTimeStorageName = authTimeStorageName;
this.stateStorageName = stateStorageName;
this.refreshTokenName = refreshTokenName;
this.cookieDomain = cookieDomain;
this.cookieSecure = cookieSecure;
this.authStorageTypeName = this.authStorageName + "_type";
this.isUsingRefreshToken = !!this.refreshTokenName;
this.refreshTokenTimeName = this.refreshTokenName ?
this.refreshTokenName + "_time" : null;
}
/**
* Get the Initial Tokens and states
* Called externally in `AuthProvider`
* when the Application is bootstrapping or refreshed
*
* If the `authStorageType` is `cookie`,
* get information from `initialCookieToken()` function
*
* If the `authTokenType` is `localStorage`
* get information from `initialLSToken()` function
*
* @returns TokenInterface
*/
TokenObject.prototype.initialToken = function () {
if (this.authStorageType === 'cookie') {
return this.initialCookieToken_();
}
else {
return this.initialLSToken_();
}
};
/**
* Get the Initial Token from Cookies
* Called internally by `initialToken` method
*
* If the `authStorageType` is `cookie`
* then this function is called
* And returns the Tokens and states Stored in all 4 cookies
*
* @returns TokenInterface
*/
TokenObject.prototype.initialCookieToken_ = function () {
var authToken = Cookies__default['default'].get(this.authStorageName);
var authTokenType = Cookies__default['default'].get(this.authStorageTypeName);
var authTokenTime = Cookies__default['default'].get(this.authTimeStorageName);
var stateCookie = Cookies__default['default'].get(this.stateStorageName);
var refreshToken = this.isUsingRefreshToken &&
this.refreshTokenName != null ? Cookies__default['default'].get(this.refreshTokenName) : null;
var refreshTokenTime = this.isUsingRefreshToken &&
this.refreshTokenTimeName != null ?
Cookies__default['default'].get(this.refreshTokenTimeName) : null;
return this.checkTokenExist(authToken, authTokenType, authTokenTime, stateCookie, refreshToken, refreshTokenTime);
};
/**
* Get the Initial Token from LocalStorage
* Called internally by `initialToken` method
*
* If the `authStorageType` is `localstorage`
* then this function is called
* And returns the Tokens and states Stored in all 4 cookies
*
* @returns TokenInterface
*/
TokenObject.prototype.initialLSToken_ = function () {
var authToken = localStorage.getItem(this.authStorageName);
var authTokenType = localStorage.getItem(this.authStorageTypeName);
var authTokenTime = localStorage.getItem(this.authTimeStorageName);
var stateCookie = localStorage.getItem(this.stateStorageName);
var refreshToken = this.isUsingRefreshToken &&
this.refreshTokenName != null ?
localStorage.getItem(this.refreshTokenName) : null;
var refreshTokenTime = this.isUsingRefreshToken &&
this.refreshTokenTimeName != null ?
localStorage.getItem(this.refreshTokenTimeName) : null;
return this.checkTokenExist(authToken, authTokenType, authTokenTime, stateCookie, refreshToken, refreshTokenTime);
};
/**
* Check if the Initial token is valid or not,
* Called Internally by `initialCookieToken_()` and `initialLSToken_()`
*
* If the tokens are valid,
* then it response TokenObject with auth Information
* Else it response TokenObject with all null
*
* @param authToken
* @param authTokenType
* @param authTokenTime
* @param stateCookie
* @param refreshToken
* @param refreshTokenTime
*
* @returns TokenInterface
*
*/
TokenObject.prototype.checkTokenExist = function (authToken, authTokenType, authTokenTime, stateCookie, refreshToken, refreshTokenTime) {
if (!!authToken && !!authTokenType && !!authTokenTime && !!stateCookie) {
var expiresAt = new Date(authTokenTime);
try {
var authState = JSON.parse(stateCookie);
return {
authToken: authToken,
authTokenType: authTokenType,
isUsingRefreshToken: this.isUsingRefreshToken,
refreshToken: this.isUsingRefreshToken && !!refreshToken ?
refreshToken : null,
refreshTokenExpireAt: this.isUsingRefreshToken &&
!!refreshTokenTime ? new Date(refreshTokenTime) : null,
expireAt: expiresAt,
authState: authState,
};
}
catch (e) {
return {
authToken: null,
authTokenType: null,
isUsingRefreshToken: this.isUsingRefreshToken,
refreshToken: null,
expireAt: null,
authState: null,
refreshTokenExpireAt: null,
};
}
}
else {
return {
authToken: null,
authTokenType: null,
isUsingRefreshToken: this.isUsingRefreshToken,
refreshToken: null,
expireAt: null,
authState: null,
refreshTokenExpireAt: null,
};
}
};
/**
* Sync Auth Tokens on time of login and logout
*
* Set the New Cookies or new Localstorage on login
* Or Remove the old Cookies or old Localstorage on logout
*
* @param authState
*/
TokenObject.prototype.syncTokens = function (authState) {
if (authState.authToken === undefined ||
authState.authTokenType === null ||
authState.authToken === null ||
authState.expireAt === null ||
authState.authState === null) {
this.removeToken();
}
else {
this.setToken(authState.authToken, authState.authTokenType, authState.refreshToken, authState.refreshTokenExpireAt, authState.expireAt, authState.authState);
}
};
/**
* Set Cookies or localstorage on login
*
* @param authToken
* @param authTokenType
* @param refreshToken
* @param refreshTokenExpiresAt
* @param expiresAt
* @param authState
*/
TokenObject.prototype.setToken = function (authToken, authTokenType, refreshToken, refreshTokenExpiresAt, expiresAt, authState) {
if (this.authStorageType === 'cookie') {
this.setCookieToken_(authToken, authTokenType, refreshToken, expiresAt, refreshTokenExpiresAt, authState);
}
else {
this.setLSToken_(authToken, authTokenType, refreshToken, expiresAt, refreshTokenExpiresAt, authState);
}
};
/**
*
* Set Cookie on time of Login
*
* @param authToken
* @param authTokenType
* @param refreshToken
* @param expiresAt
* @param refreshTokenExpiresAt
* @param authState
*/
TokenObject.prototype.setCookieToken_ = function (authToken, authTokenType, refreshToken, expiresAt, refreshTokenExpiresAt, authState) {
Cookies__default['default'].set(this.authStorageName, authToken, {
expires: expiresAt,
domain: this.cookieDomain,
secure: this.cookieSecure,
});
Cookies__default['default'].set(this.authStorageTypeName, authTokenType, {
expires: expiresAt,
domain: this.cookieDomain,
secure: this.cookieSecure,
});
Cookies__default['default'].set(this.authTimeStorageName, expiresAt.toISOString(), {
expires: expiresAt,
domain: this.cookieDomain,
secure: this.cookieSecure,
});
Cookies__default['default'].set(this.stateStorageName, authState, {
expires: expiresAt,
domain: this.cookieDomain,
secure: this.cookieSecure,
});
if (this.isUsingRefreshToken && !!this.refreshTokenName &&
!!refreshToken) {
Cookies__default['default'].set(this.refreshTokenName, refreshToken, {
expires: expiresAt,
domain: this.cookieDomain,
secure: this.cookieSecure,
});
}
if (this.isUsingRefreshToken && !!this.refreshTokenTimeName &&
!!refreshTokenExpiresAt) {
Cookies__default['default'].set(this.refreshTokenTimeName, refreshTokenExpiresAt.toISOString(), {
expires: expiresAt,
domain: this.cookieDomain,
secure: this.cookieSecure,
});
}
};
/**
* Set LocalStorage on time of Login
*
* @param authToken
* @param authTokenType
* @param refreshToken
* @param expiresAt
* @param refreshTokenExpiresAt
* @param authState
*/
TokenObject.prototype.setLSToken_ = function (authToken, authTokenType, refreshToken, expiresAt, refreshTokenExpiresAt, authState) {
localStorage.setItem(this.authStorageName, authToken);
localStorage.setItem(this.authStorageTypeName, authTokenType);
localStorage.setItem(this.authTimeStorageName, expiresAt.toISOString());
localStorage.setItem(this.stateStorageName, JSON.stringify(authState));
if (this.isUsingRefreshToken && !!this.refreshTokenName &&
!!refreshToken) {
localStorage.setItem(this.refreshTokenName, refreshToken);
}
if (this.isUsingRefreshToken && !!this.refreshTokenTimeName &&
!!refreshTokenExpiresAt) {
localStorage.setItem(this.refreshTokenTimeName, refreshTokenExpiresAt.toISOString());
}
};
/**
* Remove Tokens on time of Logout
*/
TokenObject.prototype.removeToken = function () {
if (this.authStorageType === 'cookie') {
this.removeCookieToken_();
}
else {
this.removeLSToken_();
}
};
/**
* Remove Token from Cookies
*/
TokenObject.prototype.removeCookieToken_ = function () {
Cookies__default['default'].remove(this.authStorageName, {
domain: this.cookieDomain,
secure: this.cookieSecure,
});
Cookies__default['default'].remove(this.authTimeStorageName, {
domain: this.cookieDomain,
secure: this.cookieSecure,
});
Cookies__default['default'].remove(this.stateStorageName, {
domain: this.cookieDomain,
secure: this.cookieSecure,
});
if (this.isUsingRefreshToken && !!this.refreshTokenName) {
Cookies__default['default'].remove(this.refreshTokenName, {
domain: this.cookieDomain,
secure: this.cookieSecure,
});
}
if (this.isUsingRefreshToken && !!this.refreshTokenTimeName) {
Cookies__default['default'].remove(this.refreshTokenTimeName, {
domain: this.cookieDomain,
secure: this.cookieSecure,
});
}
};
/**
* Remove Token from LocalStorage
*/
TokenObject.prototype.removeLSToken_ = function () {
localStorage.removeItem(this.authStorageName);
localStorage.removeItem(this.authTimeStorageName);
localStorage.removeItem(this.stateStorageName);
if (this.isUsingRefreshToken && !!this.refreshTokenName) {
localStorage.removeItem(this.refreshTokenName);
}
if (this.isUsingRefreshToken && !!this.refreshTokenTimeName) {
localStorage.removeItem(this.refreshTokenTimeName);
}
};
return TokenObject;
}());
var AuthContext = React__namespace.createContext({
authState: {
authTokenType: null,
authState: null,
authToken: null,
isUsingRefreshToken: false,
refreshToken: null,
refreshTokenExpireAt: null,
expireAt: null,
},
setAuthState: function () { },
});
/**
* AuthProvider - The Authentication Context Provider
*
* @param children
* @param authStorageName
* @param cookieDomain
* @param cookieSecure
*
* @return Functional Component
*/
var AuthProvider = function (_a) {
var children = _a.children, authType = _a.authType, authName = _a.authName, refreshToken = _a.refreshToken, cookieDomain = _a.cookieDomain, cookieSecure = _a.cookieSecure;
if (authType === 'cookie') {
if (!cookieDomain) {
throw new Error('authStorageType \'cookie\' ' +
'requires \'cookieDomain\' and \'cookieSecure\' in AuthProvider');
}
}
var refreshTokenName = refreshToken ? authName + "_refresh" : undefined;
var tokenObject = new TokenObject({
authTimeStorageName: authName + "_time",
authStorageType: authType,
authStorageName: authName,
refreshTokenName: refreshTokenName,
cookieDomain: cookieDomain,
cookieSecure: cookieSecure,
stateStorageName: authName + "_state",
});
var _b = React__namespace.useState(tokenObject.initialToken()), authState = _b[0], setAuthState = _b[1];
React__namespace.useEffect(function () {
tokenObject.syncTokens(authState);
}, [authState]);
return (React__namespace.createElement(AuthContext.Provider, { value: { authState: authState, setAuthState: setAuthState } }, children));
};
AuthProvider.defaultProps = {
authType: 'cookie',
authName: '_auth',
cookieDomain: window.location.hostname,
cookieSecure: window.location.protocol === 'https:',
};
var AuthContextConsumer = AuthContext.Consumer;
"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)};
/*! *****************************************************************************

@@ -439,53 +15,4 @@ Copyright (c) Microsoft Corporation.

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.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 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=
/**
* Private Route for Components
*
* @remarks
* This Component is based on {@link https://reactrouter.com/web/api/Route | reactrouter.Route}.
* So you need to install react-route-dom before use it
*
* @param props
*/
var PrivateRoute = function (props) {
var context = React__namespace.useContext(AuthContext);
var isAuth = function () {
if ((context === null || context === void 0 ? void 0 : context.authState.authToken) && (context === null || context === void 0 ? void 0 : context.authState.expireAt)) {
if (new Date(context.authState.expireAt) > new Date()) {
return true;
}
else {
context.setAuthState(function (prevState) { return (__assign(__assign({}, prevState), { authToken: null, authTokenType: null, expireAt: null, authState: null, refreshToken: null, refreshTokenExpireAt: null })); });
return false;
}
}
else {
return false;
}
};
var component = props.component, loginPath = props.loginPath, strict = props.strict, sensitive = props.sensitive, exact = props.exact, path = props.path, location = props.location, render = props.render;
return (React__namespace.createElement(reactRouterDom.Route, { location: location, path: path, exact: exact, sensitive: sensitive, strict: strict, render: function (renderProps) {
return isAuth() ?
component ?
React__namespace.createElement(component, renderProps) :
render ?
render(renderProps) :
null :
React__namespace.createElement(reactRouterDom.Redirect, { to: loginPath });
} }));
};
/**
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

@@ -496,109 +23,4 @@ *@fileoverview Authentication

*/
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}}}}
/**
*@public
*@function
*@name useAuth
*/
function useAuth() {
/**
*A constant c.
*@kind constant
*/
var c = React__namespace.useContext(AuthContext);
/** @function
* @name authHeader
* @description Get Auth header
* @returns authheader AuthHeader
*/
var authHeader = function () {
if (c === null || c === void 0 ? void 0 : c.authState) {
return c.authState.authTokenType + " " + c.authState.authToken;
}
else {
return "Bearer ";
}
};
/** @function
*@name authUser
*@description Get Auth user State
*@returns authuser state
*/
var authUser = function () {
return c.authState.authState;
};
/**
*@function
*@name isAuthenticated
*@description Get If the user is Authenticated
*@returns true | false
*/
var isAuthenticated = function () {
if ((c === null || c === void 0 ? void 0 : c.authState.authToken) && (c === null || c === void 0 ? void 0 : c.authState.expireAt)) {
if (new Date(c.authState.expireAt) > new Date()) {
return true;
}
else {
c.setAuthState(function (prevState) { return (__assign(__assign({}, prevState), { authToken: null, authTokenType: null, expireAt: null, authState: null, refreshToken: null, refreshTokenExpireAt: null })); });
return false;
}
}
else {
return false;
}
};
/**
*@function
*@name signIn
*@param signInConfig
*@returns true if sign-in else false
*/
var signIn = function (signInConfig) {
var token = signInConfig.token, tokenType = signInConfig.tokenType, authState = signInConfig.authState, expiresIn = signInConfig.expiresIn, refreshToken = signInConfig.refreshToken, refreshTokenExpireIn = signInConfig.refreshTokenExpireIn;
if ((refreshToken || refreshTokenExpireIn) &&
!c.authState.isUsingRefreshToken) {
throw new Error('The app doesn\'t implement \'refreshToken\' feature.\n' +
'So you have to implement refresh token feature from ' +
'\'AuthProvider\' before using it.');
}
var expTime = new Date(new Date().getTime() + expiresIn * 60 * 1000);
var refreshTokenExpireAt = !!refreshTokenExpireIn ?
new Date(new Date().getTime() + refreshTokenExpireIn * 60 * 1000) : null;
try {
if (c) {
c.setAuthState(function (prevState) { return (__assign(__assign({}, prevState), { authToken: token, authTokenType: tokenType, expireAt: expTime, authState: authState, refreshToken: !!refreshToken ? refreshToken : null, refreshTokenExpireAt: refreshTokenExpireAt })); });
return true;
}
else {
return false;
}
}
catch (e) {
console.error(e);
return false;
}
};
/**
*@function
*@name signOut
*@returns true | false
*/
var signOut = function () {
try {
if (c === null || c === void 0 ? void 0 : c.authState.authToken) {
c.setAuthState(function (prevState) { return (__assign(__assign({}, prevState), { authToken: null, authTokenType: null, refreshToken: null, refreshTokenExpireAt: null, expireAt: null, authState: null })); });
console.log('RAJ :: Signing Out');
return true;
}
else {
return false;
}
}
catch (e) {
return false;
}
};
return { authHeader: authHeader, isAuthenticated: isAuthenticated, authUser: authUser, signOut: signOut, signIn: signIn };
}
/**
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

@@ -608,347 +30,17 @@ *@fileoverview Sign In functionality

*@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=
/**
*@function
*@name useSignIn
*@description Authentication SignIn Hook
*@returns - Sign In function
*/
function useSignIn() {
var context = React__namespace.useContext(AuthContext);
return function (signInConfig) {
var token = signInConfig.token, tokenType = signInConfig.tokenType, authState = signInConfig.authState, expiresIn = signInConfig.expiresIn, refreshToken = signInConfig.refreshToken, refreshTokenExpireIn = signInConfig.refreshTokenExpireIn;
if ((refreshToken || refreshTokenExpireIn) &&
!context.authState.isUsingRefreshToken) {
throw new Error('The app doesn\'t implement \'refreshToken\' feature.\n' +
'So you have to implement refresh token feature from ' +
'\'AuthProvider\' before using it.');
}
var expTime = new Date(new Date().getTime() + expiresIn * 60 * 1000);
var refreshTokenExpireAt = !!refreshTokenExpireIn ?
new Date(new Date().getTime() + refreshTokenExpireIn * 60 * 1000) : null;
try {
if (context) {
context.setAuthState(function (prevState) { return (__assign(__assign({}, prevState), { authToken: token, authTokenType: tokenType, expireAt: expTime, authState: authState, refreshToken: !!refreshToken ? refreshToken : null, refreshTokenExpireAt: refreshTokenExpireAt })); });
return true;
}
else {
return false;
}
}
catch (e) {
console.error(e);
return false;
}
};
}
/**
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>
*@fileoverview Sign Out functionality
*@fileoverview Check User is authenticated or not
*@copyright Arkadip Bhattacharya 2020
*@license Apache-2.0
*/
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}}}
/**
*@public
*@function
*@name useSignOut
*@description Signout Hook
*/
function useSignOut() {
/**
*A constant c.
*@kind constant
*/
var c = React__namespace.useContext(AuthContext);
return function () {
try {
if (c === null || c === void 0 ? void 0 : c.authState.authToken) {
c.setAuthState(function (prevState) { return (__assign(__assign({}, prevState), { authToken: null, authTokenType: null, expireAt: null, authState: null, refreshToken: null, refreshTokenExpireAt: null })); });
console.log('RAJ :: Signing Out');
return true;
}
else {
return false;
}
}
catch (e) {
return false;
}
};
}
/**
* Auth State Hook
*
* @returns - Auth State Function
*/
function useAuthUser() {
var c = React__namespace.useContext(AuthContext);
return function () {
return c.authState.authState;
};
}
/**
*
*/
function useAuthHeader() {
var c = React__namespace.useContext(AuthContext);
return function () {
if (c === null || c === void 0 ? void 0 : c.authState) {
return c.authState.authTokenType + " " + c.authState.authToken;
}
else {
return "Bearer ";
}
};
}
/*
* Copyright 2020 Arkadip Bhattacharya
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @class RefreshToken
*
* Refreshes Token
*/
var RefreshToken = /** @class */ (function () {
/**
* @param context
* @constructor
*/
function RefreshToken(context) {
this.context = context;
if (!this.context.authState.isUsingRefreshToken) {
throw new Error('The app doesn\'t implement \'refreshToken\' feature.\n' +
'So you have to implement refresh token feature from ' +
'\'AuthProvider\' before using it.');
}
}
/**
* Get the current Refresh Token
* @returns refresh token
*/
RefreshToken.prototype.getCurrentRefreshToken = function () {
return {
refreshToken: this.context.authState.refreshToken,
refreshTokenExpireAt: this.context.authState.refreshTokenExpireAt,
};
};
/**
* Get the Current Auth State
* @returns a object with
* authState: The Auth Token,
* authTokenType: type of auth token,
* expireAt: expire time
*/
RefreshToken.prototype.getCurrentAuthState = function () {
return {
authToken: this.context.authState.authToken,
authTokenType: this.context.authState.authTokenType,
expireAt: this.context.authState.expireAt,
};
};
/**
* Get the Current User State
* @returns User State {object}
*/
RefreshToken.prototype.getCurrentUserState = function () {
return this.context.authState.authState;
};
/**
* Updates the Current Refresh Token
*
* @param refreshToken - new refresh Token
* @param expiresIn
*/
RefreshToken.prototype.updateRefreshToken = function (refreshToken, expiresIn) {
var expireAt = new Date(new Date().getTime() + expiresIn * 60 * 1000);
this.context.setAuthState(function (prevState) {
return (__assign(__assign({}, prevState), { refreshToken: refreshToken, refreshTokenExpireAt: expireAt }));
});
};
/**
* updates the AuthState
* @param authToken - The Updated authToken
* @param authTokenType - The updated authType (optional)
* @param expiresIn - The updated expiresIn in minutes. (optional)
*
* If the new authToken has different expire time,
* then you must have to update the expiresIn param
*/
RefreshToken.prototype.updateAuthState = function (authToken, authTokenType, expiresIn) {
var o = { authToken: authToken };
if (authTokenType !== undefined) {
Object.assign(o, { authTokenType: authTokenType });
}
if (expiresIn !== undefined) {
var expireAt = new Date(new Date().getTime() + expiresIn * 60 * 1000);
Object.assign(o, { expireAt: expireAt });
}
this.context.setAuthState(function (prevState) { return (__assign(__assign({}, prevState), o)); });
};
/**
* Updates the Auth User's state
* @param userState
*/
RefreshToken.prototype.updateUserState = function (userState) {
this.context.setAuthState(function (prevState) {
return (__assign(__assign({}, prevState), { authState: userState }));
});
};
return RefreshToken;
}());
/*
* Copyright 2020 Arkadip Bhattacharya
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
*@function
*@name useRefreshToken
*@description Refresh Token Hook
*@returns - RefreshToken object
*/
function useRefreshToken() {
var _context = React__namespace.useContext(AuthContext);
return new RefreshToken(_context);
}
/**
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>
*@fileoverview Check User is authenticated or not
*@fileoverview Sign Out functionality
*@copyright Arkadip Bhattacharya 2020
*@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=
/**
*@function
*@name useIsAuthenticated
*@description check weather user is authenticated or not
*/
function useIsAuthenticated() {
var context = React__namespace.useContext(AuthContext);
return function () {
if ((context === null || context === void 0 ? void 0 : context.authState.authToken) && (context === null || context === void 0 ? void 0 : context.authState.expireAt)) {
if (new Date(context.authState.expireAt) > new Date()) {
return true;
}
else {
context.setAuthState(function (prevState) { return (__assign(__assign({}, prevState), { authToken: null, authTokenType: null, expireAt: null, authState: null, refreshToken: null, refreshTokenExpireAt: null })); });
return false;
}
}
else {
return false;
}
};
}
/**
* @public
* @function
* @name withSignIn
* @description Inject sign in functionality inside the Component's Prop
* @param Component
*/
function withSignIn(Component) {
return function (props) {
return (React__namespace.createElement(AuthContextConsumer, null, function (c) {
var signIn = function (signInConfig) {
var token = signInConfig.token, tokenType = signInConfig.tokenType, authState = signInConfig.authState, expiresIn = signInConfig.expiresIn, refreshToken = signInConfig.refreshToken, refreshTokenExpireIn = signInConfig.refreshTokenExpireIn;
if ((refreshToken || refreshTokenExpireIn) &&
!c.authState.isUsingRefreshToken) {
throw new Error('The app doesn\'t implement ' +
'\'refreshToken\' feature.\n' +
'So you have to implement refresh token feature from ' +
'\'AuthProvider\' before using it.');
}
var expTime = new Date(new Date().getTime() + expiresIn * 60 * 1000);
var refreshTokenExpireAt = !!refreshTokenExpireIn ?
new Date(new Date().getTime() + refreshTokenExpireIn * 60 * 1000) :
null;
try {
if (c) {
c.setAuthState(function (prevState) { return (__assign(__assign({}, prevState), { authToken: token, authTokenType: tokenType, expireAt: expTime, authState: authState, refreshToken: !!refreshToken ? refreshToken : null, refreshTokenExpireAt: refreshTokenExpireAt })); });
return true;
}
else {
return false;
}
}
catch (e) {
console.error(e);
return false;
}
};
return React__namespace.createElement(Component, __assign({}, props, { signIn: signIn }));
}));
};
}
/**
* @public
* @function
* @name withSignOut
* @description Inject sign Out functionality inside the Component's Prop
* @param Component
*/
function withSignOut(Component) {
return function (props) {
return (React__namespace.createElement(AuthContextConsumer, null, function (c) {
var signOut = function () {
try {
if (c === null || c === void 0 ? void 0 : c.authState.authToken) {
c.setAuthState(function (prevState) { return (__assign(__assign({}, prevState), { authToken: null, authTokenType: null, expireAt: null, authState: null, refreshToken: null, refreshTokenExpireAt: null })); });
return true;
}
else {
return false;
}
}
catch (e) {
return false;
}
};
return React__namespace.createElement(Component, __assign({}, props, { signOut: signOut }));
}));
};
}
/**
* @function
* @name withAuthUser
* @description Inject Authenticated User's state inside the Component's Prop
* @param Component
*/
function withAuthUser(Component) {
return function (props) {
return (React__namespace.createElement(AuthContextConsumer, null, function (value) { return (React__namespace.createElement(Component, __assign({}, props, { authState: value === null || value === void 0 ? void 0 : value.authState.authState }))); }));
};
}
/**
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

@@ -959,23 +51,4 @@ *@fileoverview Authentication header

*/
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}))}))}}
/**
* @public
* @function
* @name withAuthHeader
* @description Inject Authentication Header inside the Component's Prop
* @param Component - React Component
*/
function withAuthHeader(Component) {
return function (props) {
return (React__namespace.createElement(AuthContextConsumer, null, function (c) {
if (c === null || c === void 0 ? void 0 : c.authState) {
return (React__namespace.createElement(Component, __assign({}, props, { authHeader: c.authState.authTokenType + " " + c.authState.authToken })));
}
else {
return React__namespace.createElement(Component, __assign({}, props, { authHeader: null }));
}
}));
};
}
/**
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

@@ -985,19 +58,4 @@ *@fileoverview Authentication header

*@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=
/**
* @public
* @function
* @name withAuthHeader
* @description Inject Authentication Header inside the Component's Prop
* @param Component - React Component
*/
function withRefreshToken(Component) {
return function (props) {
return (React__namespace.createElement(AuthContextConsumer, null, function (c) {
return (React__namespace.createElement(Component, __assign({}, props, { refreshToken: new RefreshToken(c) })));
}));
};
}
/**
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

@@ -1008,42 +66,2 @@ *@fileoverview Authentication status

*/
/**
* @public
* @function
* @name withIsAuthenticated
* @description Inject Authentication status inside the Component's Prop
* @param Component
*/
function withIsAuthenticated(Component) {
return function (props) {
return (React__namespace.createElement(AuthContextConsumer, null, function (c) {
if ((c === null || c === void 0 ? void 0 : c.authState.authToken) && (c === null || c === void 0 ? void 0 : c.authState.expireAt)) {
if (new Date(c.authState.expireAt) > new Date()) {
return React__namespace.createElement(Component, __assign({}, props, { isAuth: true }));
}
else {
c.setAuthState(function (prevState) { return (__assign(__assign({}, prevState), { authToken: null, authTokenType: null, expireAt: null, authState: null, refreshToken: null, refreshTokenExpireAt: null })); });
return React__namespace.createElement(Component, __assign({}, props, { isAuth: false }));
}
}
else {
return React__namespace.createElement(Component, __assign({}, props, { isAuth: false }));
}
}));
};
}
exports.AuthProvider = AuthProvider;
exports.PrivateRoute = PrivateRoute;
exports.useAuth = useAuth;
exports.useAuthHeader = useAuthHeader;
exports.useAuthUser = useAuthUser;
exports.useIsAuthenticated = useIsAuthenticated;
exports.useRefreshToken = useRefreshToken;
exports.useSignIn = useSignIn;
exports.useSignOut = useSignOut;
exports.withAuthHeader = withAuthHeader;
exports.withAuthUser = withAuthUser;
exports.withIsAuthenticated = withIsAuthenticated;
exports.withRefreshToken = withRefreshToken;
exports.withSignIn = withSignIn;
exports.withSignOut = withSignOut;
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}}}))}))}};

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

import * as React from 'react';
import Cookies from 'js-cookie';
import { Route, Redirect } from 'react-router-dom';
/**
* @class TokenObject
*
* Stores and retrieve Token
*/
var TokenObject = /** @class */ (function () {
/**
* TokenObject - Stores, retrieve and process tokens
*
* @param authStorageName - Name of the Token,
* which will store the Authorization Token
*
* @param authStorageType - Type of the auth Storage, `
* cookie` or `localstorage`
*
* @param authTimeStorageName - Name of the Token,
* which will store the Expiring time of the Authorization Token
* @param stateStorageName - Name of the Token,
* which will store the User's state
*
* @param refreshTokenName - Name of the refresh Token,
* if `undefined`, then no refreshToken feature is using
*
* @param cookieDomain - domain name for the Cookies,
* only applicable when `authStorageType` is `cookie`
*
* @param cookieSecure - cookies are secure or not,
* only applicable when `authStorageType` is `cookie`
*
* @constructor
*/
function TokenObject(_a) {
var authStorageName = _a.authStorageName, authStorageType = _a.authStorageType, authTimeStorageName = _a.authTimeStorageName, stateStorageName = _a.stateStorageName, refreshTokenName = _a.refreshTokenName, cookieDomain = _a.cookieDomain, cookieSecure = _a.cookieSecure;
this.authStorageType = authStorageType;
this.authStorageName = authStorageName;
this.authTimeStorageName = authTimeStorageName;
this.stateStorageName = stateStorageName;
this.refreshTokenName = refreshTokenName;
this.cookieDomain = cookieDomain;
this.cookieSecure = cookieSecure;
this.authStorageTypeName = this.authStorageName + "_type";
this.isUsingRefreshToken = !!this.refreshTokenName;
this.refreshTokenTimeName = this.refreshTokenName ?
this.refreshTokenName + "_time" : null;
}
/**
* Get the Initial Tokens and states
* Called externally in `AuthProvider`
* when the Application is bootstrapping or refreshed
*
* If the `authStorageType` is `cookie`,
* get information from `initialCookieToken()` function
*
* If the `authTokenType` is `localStorage`
* get information from `initialLSToken()` function
*
* @returns TokenInterface
*/
TokenObject.prototype.initialToken = function () {
if (this.authStorageType === 'cookie') {
return this.initialCookieToken_();
}
else {
return this.initialLSToken_();
}
};
/**
* Get the Initial Token from Cookies
* Called internally by `initialToken` method
*
* If the `authStorageType` is `cookie`
* then this function is called
* And returns the Tokens and states Stored in all 4 cookies
*
* @returns TokenInterface
*/
TokenObject.prototype.initialCookieToken_ = function () {
var authToken = Cookies.get(this.authStorageName);
var authTokenType = Cookies.get(this.authStorageTypeName);
var authTokenTime = Cookies.get(this.authTimeStorageName);
var stateCookie = Cookies.get(this.stateStorageName);
var refreshToken = this.isUsingRefreshToken &&
this.refreshTokenName != null ? Cookies.get(this.refreshTokenName) : null;
var refreshTokenTime = this.isUsingRefreshToken &&
this.refreshTokenTimeName != null ?
Cookies.get(this.refreshTokenTimeName) : null;
return this.checkTokenExist(authToken, authTokenType, authTokenTime, stateCookie, refreshToken, refreshTokenTime);
};
/**
* Get the Initial Token from LocalStorage
* Called internally by `initialToken` method
*
* If the `authStorageType` is `localstorage`
* then this function is called
* And returns the Tokens and states Stored in all 4 cookies
*
* @returns TokenInterface
*/
TokenObject.prototype.initialLSToken_ = function () {
var authToken = localStorage.getItem(this.authStorageName);
var authTokenType = localStorage.getItem(this.authStorageTypeName);
var authTokenTime = localStorage.getItem(this.authTimeStorageName);
var stateCookie = localStorage.getItem(this.stateStorageName);
var refreshToken = this.isUsingRefreshToken &&
this.refreshTokenName != null ?
localStorage.getItem(this.refreshTokenName) : null;
var refreshTokenTime = this.isUsingRefreshToken &&
this.refreshTokenTimeName != null ?
localStorage.getItem(this.refreshTokenTimeName) : null;
return this.checkTokenExist(authToken, authTokenType, authTokenTime, stateCookie, refreshToken, refreshTokenTime);
};
/**
* Check if the Initial token is valid or not,
* Called Internally by `initialCookieToken_()` and `initialLSToken_()`
*
* If the tokens are valid,
* then it response TokenObject with auth Information
* Else it response TokenObject with all null
*
* @param authToken
* @param authTokenType
* @param authTokenTime
* @param stateCookie
* @param refreshToken
* @param refreshTokenTime
*
* @returns TokenInterface
*
*/
TokenObject.prototype.checkTokenExist = function (authToken, authTokenType, authTokenTime, stateCookie, refreshToken, refreshTokenTime) {
if (!!authToken && !!authTokenType && !!authTokenTime && !!stateCookie) {
var expiresAt = new Date(authTokenTime);
try {
var authState = JSON.parse(stateCookie);
return {
authToken: authToken,
authTokenType: authTokenType,
isUsingRefreshToken: this.isUsingRefreshToken,
refreshToken: this.isUsingRefreshToken && !!refreshToken ?
refreshToken : null,
refreshTokenExpireAt: this.isUsingRefreshToken &&
!!refreshTokenTime ? new Date(refreshTokenTime) : null,
expireAt: expiresAt,
authState: authState,
};
}
catch (e) {
return {
authToken: null,
authTokenType: null,
isUsingRefreshToken: this.isUsingRefreshToken,
refreshToken: null,
expireAt: null,
authState: null,
refreshTokenExpireAt: null,
};
}
}
else {
return {
authToken: null,
authTokenType: null,
isUsingRefreshToken: this.isUsingRefreshToken,
refreshToken: null,
expireAt: null,
authState: null,
refreshTokenExpireAt: null,
};
}
};
/**
* Sync Auth Tokens on time of login and logout
*
* Set the New Cookies or new Localstorage on login
* Or Remove the old Cookies or old Localstorage on logout
*
* @param authState
*/
TokenObject.prototype.syncTokens = function (authState) {
if (authState.authToken === undefined ||
authState.authTokenType === null ||
authState.authToken === null ||
authState.expireAt === null ||
authState.authState === null) {
this.removeToken();
}
else {
this.setToken(authState.authToken, authState.authTokenType, authState.refreshToken, authState.refreshTokenExpireAt, authState.expireAt, authState.authState);
}
};
/**
* Set Cookies or localstorage on login
*
* @param authToken
* @param authTokenType
* @param refreshToken
* @param refreshTokenExpiresAt
* @param expiresAt
* @param authState
*/
TokenObject.prototype.setToken = function (authToken, authTokenType, refreshToken, refreshTokenExpiresAt, expiresAt, authState) {
if (this.authStorageType === 'cookie') {
this.setCookieToken_(authToken, authTokenType, refreshToken, expiresAt, refreshTokenExpiresAt, authState);
}
else {
this.setLSToken_(authToken, authTokenType, refreshToken, expiresAt, refreshTokenExpiresAt, authState);
}
};
/**
*
* Set Cookie on time of Login
*
* @param authToken
* @param authTokenType
* @param refreshToken
* @param expiresAt
* @param refreshTokenExpiresAt
* @param authState
*/
TokenObject.prototype.setCookieToken_ = function (authToken, authTokenType, refreshToken, expiresAt, refreshTokenExpiresAt, authState) {
Cookies.set(this.authStorageName, authToken, {
expires: expiresAt,
domain: this.cookieDomain,
secure: this.cookieSecure,
});
Cookies.set(this.authStorageTypeName, authTokenType, {
expires: expiresAt,
domain: this.cookieDomain,
secure: this.cookieSecure,
});
Cookies.set(this.authTimeStorageName, expiresAt.toISOString(), {
expires: expiresAt,
domain: this.cookieDomain,
secure: this.cookieSecure,
});
Cookies.set(this.stateStorageName, authState, {
expires: expiresAt,
domain: this.cookieDomain,
secure: this.cookieSecure,
});
if (this.isUsingRefreshToken && !!this.refreshTokenName &&
!!refreshToken) {
Cookies.set(this.refreshTokenName, refreshToken, {
expires: expiresAt,
domain: this.cookieDomain,
secure: this.cookieSecure,
});
}
if (this.isUsingRefreshToken && !!this.refreshTokenTimeName &&
!!refreshTokenExpiresAt) {
Cookies.set(this.refreshTokenTimeName, refreshTokenExpiresAt.toISOString(), {
expires: expiresAt,
domain: this.cookieDomain,
secure: this.cookieSecure,
});
}
};
/**
* Set LocalStorage on time of Login
*
* @param authToken
* @param authTokenType
* @param refreshToken
* @param expiresAt
* @param refreshTokenExpiresAt
* @param authState
*/
TokenObject.prototype.setLSToken_ = function (authToken, authTokenType, refreshToken, expiresAt, refreshTokenExpiresAt, authState) {
localStorage.setItem(this.authStorageName, authToken);
localStorage.setItem(this.authStorageTypeName, authTokenType);
localStorage.setItem(this.authTimeStorageName, expiresAt.toISOString());
localStorage.setItem(this.stateStorageName, JSON.stringify(authState));
if (this.isUsingRefreshToken && !!this.refreshTokenName &&
!!refreshToken) {
localStorage.setItem(this.refreshTokenName, refreshToken);
}
if (this.isUsingRefreshToken && !!this.refreshTokenTimeName &&
!!refreshTokenExpiresAt) {
localStorage.setItem(this.refreshTokenTimeName, refreshTokenExpiresAt.toISOString());
}
};
/**
* Remove Tokens on time of Logout
*/
TokenObject.prototype.removeToken = function () {
if (this.authStorageType === 'cookie') {
this.removeCookieToken_();
}
else {
this.removeLSToken_();
}
};
/**
* Remove Token from Cookies
*/
TokenObject.prototype.removeCookieToken_ = function () {
Cookies.remove(this.authStorageName, {
domain: this.cookieDomain,
secure: this.cookieSecure,
});
Cookies.remove(this.authTimeStorageName, {
domain: this.cookieDomain,
secure: this.cookieSecure,
});
Cookies.remove(this.stateStorageName, {
domain: this.cookieDomain,
secure: this.cookieSecure,
});
if (this.isUsingRefreshToken && !!this.refreshTokenName) {
Cookies.remove(this.refreshTokenName, {
domain: this.cookieDomain,
secure: this.cookieSecure,
});
}
if (this.isUsingRefreshToken && !!this.refreshTokenTimeName) {
Cookies.remove(this.refreshTokenTimeName, {
domain: this.cookieDomain,
secure: this.cookieSecure,
});
}
};
/**
* Remove Token from LocalStorage
*/
TokenObject.prototype.removeLSToken_ = function () {
localStorage.removeItem(this.authStorageName);
localStorage.removeItem(this.authTimeStorageName);
localStorage.removeItem(this.stateStorageName);
if (this.isUsingRefreshToken && !!this.refreshTokenName) {
localStorage.removeItem(this.refreshTokenName);
}
if (this.isUsingRefreshToken && !!this.refreshTokenTimeName) {
localStorage.removeItem(this.refreshTokenTimeName);
}
};
return TokenObject;
}());
var AuthContext = React.createContext({
authState: {
authTokenType: null,
authState: null,
authToken: null,
isUsingRefreshToken: false,
refreshToken: null,
refreshTokenExpireAt: null,
expireAt: null,
},
setAuthState: function () { },
});
/**
* AuthProvider - The Authentication Context Provider
*
* @param children
* @param authStorageName
* @param cookieDomain
* @param cookieSecure
*
* @return Functional Component
*/
var AuthProvider = function (_a) {
var children = _a.children, authType = _a.authType, authName = _a.authName, refreshToken = _a.refreshToken, cookieDomain = _a.cookieDomain, cookieSecure = _a.cookieSecure;
if (authType === 'cookie') {
if (!cookieDomain) {
throw new Error('authStorageType \'cookie\' ' +
'requires \'cookieDomain\' and \'cookieSecure\' in AuthProvider');
}
}
var refreshTokenName = refreshToken ? authName + "_refresh" : undefined;
var tokenObject = new TokenObject({
authTimeStorageName: authName + "_time",
authStorageType: authType,
authStorageName: authName,
refreshTokenName: refreshTokenName,
cookieDomain: cookieDomain,
cookieSecure: cookieSecure,
stateStorageName: authName + "_state",
});
var _b = React.useState(tokenObject.initialToken()), authState = _b[0], setAuthState = _b[1];
React.useEffect(function () {
tokenObject.syncTokens(authState);
}, [authState]);
return (React.createElement(AuthContext.Provider, { value: { authState: authState, setAuthState: setAuthState } }, children));
};
AuthProvider.defaultProps = {
authType: 'cookie',
authName: '_auth',
cookieDomain: window.location.hostname,
cookieSecure: window.location.protocol === 'https:',
};
var AuthContextConsumer = AuthContext.Consumer;
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})}})};
/*! *****************************************************************************

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

***************************************************************************** */
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
/**
* Private Route for Components
*
* @remarks
* This Component is based on {@link https://reactrouter.com/web/api/Route | reactrouter.Route}.
* So you need to install react-route-dom before use it
*
* @param props
*/
var PrivateRoute = function (props) {
var context = React.useContext(AuthContext);
var isAuth = function () {
if ((context === null || context === void 0 ? void 0 : context.authState.authToken) && (context === null || context === void 0 ? void 0 : context.authState.expireAt)) {
if (new Date(context.authState.expireAt) > new Date()) {
return true;
}
else {
context.setAuthState(function (prevState) { return (__assign(__assign({}, prevState), { authToken: null, authTokenType: null, expireAt: null, authState: null, refreshToken: null, refreshTokenExpireAt: null })); });
return false;
}
}
else {
return false;
}
};
var component = props.component, loginPath = props.loginPath, strict = props.strict, sensitive = props.sensitive, exact = props.exact, path = props.path, location = props.location, render = props.render;
return (React.createElement(Route, { location: location, path: path, exact: exact, sensitive: sensitive, strict: strict, render: function (renderProps) {
return isAuth() ?
component ?
React.createElement(component, renderProps) :
render ?
render(renderProps) :
null :
React.createElement(Redirect, { to: loginPath });
} }));
};
/**
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

@@ -467,109 +23,4 @@ *@fileoverview Authentication

*/
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}}}}
/**
*@public
*@function
*@name useAuth
*/
function useAuth() {
/**
*A constant c.
*@kind constant
*/
var c = React.useContext(AuthContext);
/** @function
* @name authHeader
* @description Get Auth header
* @returns authheader AuthHeader
*/
var authHeader = function () {
if (c === null || c === void 0 ? void 0 : c.authState) {
return c.authState.authTokenType + " " + c.authState.authToken;
}
else {
return "Bearer ";
}
};
/** @function
*@name authUser
*@description Get Auth user State
*@returns authuser state
*/
var authUser = function () {
return c.authState.authState;
};
/**
*@function
*@name isAuthenticated
*@description Get If the user is Authenticated
*@returns true | false
*/
var isAuthenticated = function () {
if ((c === null || c === void 0 ? void 0 : c.authState.authToken) && (c === null || c === void 0 ? void 0 : c.authState.expireAt)) {
if (new Date(c.authState.expireAt) > new Date()) {
return true;
}
else {
c.setAuthState(function (prevState) { return (__assign(__assign({}, prevState), { authToken: null, authTokenType: null, expireAt: null, authState: null, refreshToken: null, refreshTokenExpireAt: null })); });
return false;
}
}
else {
return false;
}
};
/**
*@function
*@name signIn
*@param signInConfig
*@returns true if sign-in else false
*/
var signIn = function (signInConfig) {
var token = signInConfig.token, tokenType = signInConfig.tokenType, authState = signInConfig.authState, expiresIn = signInConfig.expiresIn, refreshToken = signInConfig.refreshToken, refreshTokenExpireIn = signInConfig.refreshTokenExpireIn;
if ((refreshToken || refreshTokenExpireIn) &&
!c.authState.isUsingRefreshToken) {
throw new Error('The app doesn\'t implement \'refreshToken\' feature.\n' +
'So you have to implement refresh token feature from ' +
'\'AuthProvider\' before using it.');
}
var expTime = new Date(new Date().getTime() + expiresIn * 60 * 1000);
var refreshTokenExpireAt = !!refreshTokenExpireIn ?
new Date(new Date().getTime() + refreshTokenExpireIn * 60 * 1000) : null;
try {
if (c) {
c.setAuthState(function (prevState) { return (__assign(__assign({}, prevState), { authToken: token, authTokenType: tokenType, expireAt: expTime, authState: authState, refreshToken: !!refreshToken ? refreshToken : null, refreshTokenExpireAt: refreshTokenExpireAt })); });
return true;
}
else {
return false;
}
}
catch (e) {
console.error(e);
return false;
}
};
/**
*@function
*@name signOut
*@returns true | false
*/
var signOut = function () {
try {
if (c === null || c === void 0 ? void 0 : c.authState.authToken) {
c.setAuthState(function (prevState) { return (__assign(__assign({}, prevState), { authToken: null, authTokenType: null, refreshToken: null, refreshTokenExpireAt: null, expireAt: null, authState: null })); });
console.log('RAJ :: Signing Out');
return true;
}
else {
return false;
}
}
catch (e) {
return false;
}
};
return { authHeader: authHeader, isAuthenticated: isAuthenticated, authUser: authUser, signOut: signOut, signIn: signIn };
}
/**
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

@@ -579,39 +30,4 @@ *@fileoverview Sign In functionality

*@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
*@name useSignIn
*@description Authentication SignIn Hook
*@returns - Sign In function
*/
function useSignIn() {
var context = React.useContext(AuthContext);
return function (signInConfig) {
var token = signInConfig.token, tokenType = signInConfig.tokenType, authState = signInConfig.authState, expiresIn = signInConfig.expiresIn, refreshToken = signInConfig.refreshToken, refreshTokenExpireIn = signInConfig.refreshTokenExpireIn;
if ((refreshToken || refreshTokenExpireIn) &&
!context.authState.isUsingRefreshToken) {
throw new Error('The app doesn\'t implement \'refreshToken\' feature.\n' +
'So you have to implement refresh token feature from ' +
'\'AuthProvider\' before using it.');
}
var expTime = new Date(new Date().getTime() + expiresIn * 60 * 1000);
var refreshTokenExpireAt = !!refreshTokenExpireIn ?
new Date(new Date().getTime() + refreshTokenExpireIn * 60 * 1000) : null;
try {
if (context) {
context.setAuthState(function (prevState) { return (__assign(__assign({}, prevState), { authToken: token, authTokenType: tokenType, expireAt: expTime, authState: authState, refreshToken: !!refreshToken ? refreshToken : null, refreshTokenExpireAt: refreshTokenExpireAt })); });
return true;
}
else {
return false;
}
}
catch (e) {
console.error(e);
return false;
}
};
}
/**
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

@@ -621,194 +37,4 @@ *@fileoverview Sign Out functionality

*@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)}
/**
*@public
*@function
*@name useSignOut
*@description Signout Hook
*/
function useSignOut() {
/**
*A constant c.
*@kind constant
*/
var c = React.useContext(AuthContext);
return function () {
try {
if (c === null || c === void 0 ? void 0 : c.authState.authToken) {
c.setAuthState(function (prevState) { return (__assign(__assign({}, prevState), { authToken: null, authTokenType: null, expireAt: null, authState: null, refreshToken: null, refreshTokenExpireAt: null })); });
console.log('RAJ :: Signing Out');
return true;
}
else {
return false;
}
}
catch (e) {
return false;
}
};
}
/**
* Auth State Hook
*
* @returns - Auth State Function
*/
function useAuthUser() {
var c = React.useContext(AuthContext);
return function () {
return c.authState.authState;
};
}
/**
*
*/
function useAuthHeader() {
var c = React.useContext(AuthContext);
return function () {
if (c === null || c === void 0 ? void 0 : c.authState) {
return c.authState.authTokenType + " " + c.authState.authToken;
}
else {
return "Bearer ";
}
};
}
/*
* Copyright 2020 Arkadip Bhattacharya
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @class RefreshToken
*
* Refreshes Token
*/
var RefreshToken = /** @class */ (function () {
/**
* @param context
* @constructor
*/
function RefreshToken(context) {
this.context = context;
if (!this.context.authState.isUsingRefreshToken) {
throw new Error('The app doesn\'t implement \'refreshToken\' feature.\n' +
'So you have to implement refresh token feature from ' +
'\'AuthProvider\' before using it.');
}
}
/**
* Get the current Refresh Token
* @returns refresh token
*/
RefreshToken.prototype.getCurrentRefreshToken = function () {
return {
refreshToken: this.context.authState.refreshToken,
refreshTokenExpireAt: this.context.authState.refreshTokenExpireAt,
};
};
/**
* Get the Current Auth State
* @returns a object with
* authState: The Auth Token,
* authTokenType: type of auth token,
* expireAt: expire time
*/
RefreshToken.prototype.getCurrentAuthState = function () {
return {
authToken: this.context.authState.authToken,
authTokenType: this.context.authState.authTokenType,
expireAt: this.context.authState.expireAt,
};
};
/**
* Get the Current User State
* @returns User State {object}
*/
RefreshToken.prototype.getCurrentUserState = function () {
return this.context.authState.authState;
};
/**
* Updates the Current Refresh Token
*
* @param refreshToken - new refresh Token
* @param expiresIn
*/
RefreshToken.prototype.updateRefreshToken = function (refreshToken, expiresIn) {
var expireAt = new Date(new Date().getTime() + expiresIn * 60 * 1000);
this.context.setAuthState(function (prevState) {
return (__assign(__assign({}, prevState), { refreshToken: refreshToken, refreshTokenExpireAt: expireAt }));
});
};
/**
* updates the AuthState
* @param authToken - The Updated authToken
* @param authTokenType - The updated authType (optional)
* @param expiresIn - The updated expiresIn in minutes. (optional)
*
* If the new authToken has different expire time,
* then you must have to update the expiresIn param
*/
RefreshToken.prototype.updateAuthState = function (authToken, authTokenType, expiresIn) {
var o = { authToken: authToken };
if (authTokenType !== undefined) {
Object.assign(o, { authTokenType: authTokenType });
}
if (expiresIn !== undefined) {
var expireAt = new Date(new Date().getTime() + expiresIn * 60 * 1000);
Object.assign(o, { expireAt: expireAt });
}
this.context.setAuthState(function (prevState) { return (__assign(__assign({}, prevState), o)); });
};
/**
* Updates the Auth User's state
* @param userState
*/
RefreshToken.prototype.updateUserState = function (userState) {
this.context.setAuthState(function (prevState) {
return (__assign(__assign({}, prevState), { authState: userState }));
});
};
return RefreshToken;
}());
/*
* Copyright 2020 Arkadip Bhattacharya
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
*@function
*@name useRefreshToken
*@description Refresh Token Hook
*@returns - RefreshToken object
*/
function useRefreshToken() {
var _context = React.useContext(AuthContext);
return new RefreshToken(_context);
}
/**
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

@@ -818,110 +44,4 @@ *@fileoverview Check User is authenticated or not

*@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
*@name useIsAuthenticated
*@description check weather user is authenticated or not
*/
function useIsAuthenticated() {
var context = React.useContext(AuthContext);
return function () {
if ((context === null || context === void 0 ? void 0 : context.authState.authToken) && (context === null || context === void 0 ? void 0 : context.authState.expireAt)) {
if (new Date(context.authState.expireAt) > new Date()) {
return true;
}
else {
context.setAuthState(function (prevState) { return (__assign(__assign({}, prevState), { authToken: null, authTokenType: null, expireAt: null, authState: null, refreshToken: null, refreshTokenExpireAt: null })); });
return false;
}
}
else {
return false;
}
};
}
/**
* @public
* @function
* @name withSignIn
* @description Inject sign in functionality inside the Component's Prop
* @param Component
*/
function withSignIn(Component) {
return function (props) {
return (React.createElement(AuthContextConsumer, null, function (c) {
var signIn = function (signInConfig) {
var token = signInConfig.token, tokenType = signInConfig.tokenType, authState = signInConfig.authState, expiresIn = signInConfig.expiresIn, refreshToken = signInConfig.refreshToken, refreshTokenExpireIn = signInConfig.refreshTokenExpireIn;
if ((refreshToken || refreshTokenExpireIn) &&
!c.authState.isUsingRefreshToken) {
throw new Error('The app doesn\'t implement ' +
'\'refreshToken\' feature.\n' +
'So you have to implement refresh token feature from ' +
'\'AuthProvider\' before using it.');
}
var expTime = new Date(new Date().getTime() + expiresIn * 60 * 1000);
var refreshTokenExpireAt = !!refreshTokenExpireIn ?
new Date(new Date().getTime() + refreshTokenExpireIn * 60 * 1000) :
null;
try {
if (c) {
c.setAuthState(function (prevState) { return (__assign(__assign({}, prevState), { authToken: token, authTokenType: tokenType, expireAt: expTime, authState: authState, refreshToken: !!refreshToken ? refreshToken : null, refreshTokenExpireAt: refreshTokenExpireAt })); });
return true;
}
else {
return false;
}
}
catch (e) {
console.error(e);
return false;
}
};
return React.createElement(Component, __assign({}, props, { signIn: signIn }));
}));
};
}
/**
* @public
* @function
* @name withSignOut
* @description Inject sign Out functionality inside the Component's Prop
* @param Component
*/
function withSignOut(Component) {
return function (props) {
return (React.createElement(AuthContextConsumer, null, function (c) {
var signOut = function () {
try {
if (c === null || c === void 0 ? void 0 : c.authState.authToken) {
c.setAuthState(function (prevState) { return (__assign(__assign({}, prevState), { authToken: null, authTokenType: null, expireAt: null, authState: null, refreshToken: null, refreshTokenExpireAt: null })); });
return true;
}
else {
return false;
}
}
catch (e) {
return false;
}
};
return React.createElement(Component, __assign({}, props, { signOut: signOut }));
}));
};
}
/**
* @function
* @name withAuthUser
* @description Inject Authenticated User's state inside the Component's Prop
* @param Component
*/
function withAuthUser(Component) {
return function (props) {
return (React.createElement(AuthContextConsumer, null, function (value) { return (React.createElement(Component, __assign({}, props, { authState: value === null || value === void 0 ? void 0 : value.authState.authState }))); }));
};
}
/**
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

@@ -931,24 +51,4 @@ *@fileoverview Authentication header

*@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}))}))}}
/**
* @public
* @function
* @name withAuthHeader
* @description Inject Authentication Header inside the Component's Prop
* @param Component - React Component
*/
function withAuthHeader(Component) {
return function (props) {
return (React.createElement(AuthContextConsumer, null, function (c) {
if (c === null || c === void 0 ? void 0 : c.authState) {
return (React.createElement(Component, __assign({}, props, { authHeader: c.authState.authTokenType + " " + c.authState.authToken })));
}
else {
return React.createElement(Component, __assign({}, props, { authHeader: null }));
}
}));
};
}
/**
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

@@ -958,19 +58,4 @@ *@fileoverview Authentication header

*@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)}))}))}}
/**
* @public
* @function
* @name withAuthHeader
* @description Inject Authentication Header inside the Component's Prop
* @param Component - React Component
*/
function withRefreshToken(Component) {
return function (props) {
return (React.createElement(AuthContextConsumer, null, function (c) {
return (React.createElement(Component, __assign({}, props, { refreshToken: new RefreshToken(c) })));
}));
};
}
/**
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

@@ -980,29 +65,2 @@ *@fileoverview Authentication status

*@license Apache-2.0
*/
/**
* @public
* @function
* @name withIsAuthenticated
* @description Inject Authentication status inside the Component's Prop
* @param Component
*/
function withIsAuthenticated(Component) {
return function (props) {
return (React.createElement(AuthContextConsumer, null, function (c) {
if ((c === null || c === void 0 ? void 0 : c.authState.authToken) && (c === null || c === void 0 ? void 0 : c.authState.expireAt)) {
if (new Date(c.authState.expireAt) > new Date()) {
return React.createElement(Component, __assign({}, props, { isAuth: true }));
}
else {
c.setAuthState(function (prevState) { return (__assign(__assign({}, prevState), { authToken: null, authTokenType: null, expireAt: null, authState: null, refreshToken: null, refreshTokenExpireAt: null })); });
return React.createElement(Component, __assign({}, props, { isAuth: false }));
}
}
else {
return React.createElement(Component, __assign({}, props, { isAuth: false }));
}
}));
};
}
export { AuthProvider, PrivateRoute, useAuth, useAuthHeader, useAuthUser, useIsAuthenticated, useRefreshToken, useSignIn, useSignOut, withAuthHeader, withAuthUser, withIsAuthenticated, withRefreshToken, withSignIn, withSignOut };
*/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};

96

dist/index.umd.js

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

/*! react-auth-kit v1.4.8 | 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)};
/*! react-auth-kit v1.4.9 | 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.
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
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=
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=
/**
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>
*@fileoverview Authentication
*@copyright Arkadip Bhattacharya 2020
*@license Apache-2.0
*/
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>
*@fileoverview Authentication
*@copyright Arkadip Bhattacharya 2020
*@license Apache-2.0
*/
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}}}}
/**
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>
*@fileoverview Sign In functionality
*@copyright Arkadip Bhattacharya 2020
*@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=
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>
*@fileoverview Sign In functionality
*@copyright Arkadip Bhattacharya 2020
*@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=
/**
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>
*@fileoverview Check User is authenticated or not
*@copyright Arkadip Bhattacharya 2020
*@license Apache-2.0
*/
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>
*@fileoverview Check User is authenticated or not
*@copyright Arkadip Bhattacharya 2020
*@license Apache-2.0
*/
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}}}
/**
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>
*@fileoverview Sign Out functionality
*@copyright Arkadip Bhattacharya 2020
*@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=
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>
*@fileoverview Sign Out functionality
*@copyright Arkadip Bhattacharya 2020
*@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=
/**
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>
*@fileoverview Authentication header
*@copyright Arkadip Bhattacharya 2020
*@license Apache-2.0
*/
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>
*@fileoverview Authentication header
*@copyright Arkadip Bhattacharya 2020
*@license Apache-2.0
*/
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}))}))}}
/**
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>
*@fileoverview Authentication header
*@copyright Arkadip Bhattacharya 2020
*@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=
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>
*@fileoverview Authentication header
*@copyright Arkadip Bhattacharya 2020
*@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=
/**
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>
*@fileoverview Authentication status
*@copyright Arkadip Bhattacharya 2020
*@license Apache-2.0
*/
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>
*@fileoverview Authentication status
*@copyright Arkadip Bhattacharya 2020
*@license Apache-2.0
*/
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})}));
{
"name": "react-auth-kit",
"version": "1.4.8",
"version": "1.4.9",
"description": "Authentication Library for React, which makes Token based auth very easy",

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

"devDependencies": {
"@rollup/plugin-commonjs": "^18.0.0",
"@rollup/plugin-commonjs": "^19.0.0",
"@rollup/plugin-node-resolve": "^13.0.0",
"@rollup/plugin-typescript": "^8.2.1",
"@types/jest": "^26.0.10",

@@ -68,3 +69,2 @@ "@types/js-cookie": "^2.2.6",

"rollup-plugin-terser": "^7.0.0",
"rollup-plugin-typescript2": "^0.30.0",
"ts-jest": "^26.3.0",

@@ -71,0 +71,0 @@ "typedoc": "^0.20.16",

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