react-auth-kit
Advanced tools
Comparing version 1.4.5 to 1.4.6
@@ -7,2 +7,6 @@ # Changelog | ||
# [1.4.6] - 2021-04-09 | ||
### Changed: | ||
- Added GA in the docs | ||
## [1.4.5] - 2021-02-10 | ||
@@ -9,0 +13,0 @@ ### Fixed: |
@@ -11,2 +11,23 @@ 'use strict'; | ||
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); | ||
@@ -352,3 +373,3 @@ | ||
var AuthContext = React.createContext({ | ||
var AuthContext = React__namespace.createContext({ | ||
authState: { | ||
@@ -396,7 +417,7 @@ authTokenType: null, | ||
}); | ||
var _b = React.useState(tokenObject.initialToken()), authState = _b[0], setAuthState = _b[1]; | ||
React.useEffect(function () { | ||
var _b = React__namespace.useState(tokenObject.initialToken()), authState = _b[0], setAuthState = _b[1]; | ||
React__namespace.useEffect(function () { | ||
tokenObject.syncTokens(authState); | ||
}, [authState]); | ||
return (React.createElement(AuthContext.Provider, { value: { authState: authState, setAuthState: setAuthState } }, children)); | ||
return (React__namespace.createElement(AuthContext.Provider, { value: { authState: authState, setAuthState: setAuthState } }, children)); | ||
}; | ||
@@ -448,3 +469,3 @@ AuthProvider.defaultProps = { | ||
var PrivateRoute = function (props) { | ||
var context = React.useContext(AuthContext); | ||
var context = React__namespace.useContext(AuthContext); | ||
var isAuth = function () { | ||
@@ -465,10 +486,10 @@ if ((context === null || context === void 0 ? void 0 : context.authState.authToken) && (context === null || context === void 0 ? void 0 : context.authState.expireAt)) { | ||
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(reactRouterDom.Route, { location: location, path: path, exact: exact, sensitive: sensitive, strict: strict, render: function (renderProps) { | ||
return (React__namespace.createElement(reactRouterDom.Route, { location: location, path: path, exact: exact, sensitive: sensitive, strict: strict, render: function (renderProps) { | ||
return isAuth() ? | ||
component ? | ||
React.createElement(component, renderProps) : | ||
React__namespace.createElement(component, renderProps) : | ||
render ? | ||
render(renderProps) : | ||
null : | ||
React.createElement(reactRouterDom.Redirect, { to: loginPath }); | ||
React__namespace.createElement(reactRouterDom.Redirect, { to: loginPath }); | ||
} })); | ||
@@ -493,3 +514,3 @@ }; | ||
*/ | ||
var c = React.useContext(AuthContext); | ||
var c = React__namespace.useContext(AuthContext); | ||
/** @function | ||
@@ -603,3 +624,3 @@ * @name authHeader | ||
function useSignIn() { | ||
var context = React.useContext(AuthContext); | ||
var context = React__namespace.useContext(AuthContext); | ||
return function (signInConfig) { | ||
@@ -649,3 +670,3 @@ var token = signInConfig.token, tokenType = signInConfig.tokenType, authState = signInConfig.authState, expiresIn = signInConfig.expiresIn, refreshToken = signInConfig.refreshToken, refreshTokenExpireIn = signInConfig.refreshTokenExpireIn; | ||
*/ | ||
var c = React.useContext(AuthContext); | ||
var c = React__namespace.useContext(AuthContext); | ||
return function () { | ||
@@ -674,3 +695,3 @@ try { | ||
function useAuthUser() { | ||
var c = React.useContext(AuthContext); | ||
var c = React__namespace.useContext(AuthContext); | ||
return function () { | ||
@@ -685,3 +706,3 @@ return c.authState.authState; | ||
function useAuthHeader() { | ||
var c = React.useContext(AuthContext); | ||
var c = React__namespace.useContext(AuthContext); | ||
return function () { | ||
@@ -827,3 +848,3 @@ if (c === null || c === void 0 ? void 0 : c.authState) { | ||
function useRefreshToken() { | ||
var _context = React.useContext(AuthContext); | ||
var _context = React__namespace.useContext(AuthContext); | ||
return new RefreshToken(_context); | ||
@@ -844,3 +865,3 @@ } | ||
function useIsAuthenticated() { | ||
var context = React.useContext(AuthContext); | ||
var context = React__namespace.useContext(AuthContext); | ||
return function () { | ||
@@ -871,3 +892,3 @@ if ((context === null || context === void 0 ? void 0 : context.authState.authToken) && (context === null || context === void 0 ? void 0 : context.authState.expireAt)) { | ||
return function (props) { | ||
return (React.createElement(AuthContextConsumer, null, function (c) { | ||
return (React__namespace.createElement(AuthContextConsumer, null, function (c) { | ||
var signIn = function (signInConfig) { | ||
@@ -900,3 +921,3 @@ var token = signInConfig.token, tokenType = signInConfig.tokenType, authState = signInConfig.authState, expiresIn = signInConfig.expiresIn, refreshToken = signInConfig.refreshToken, refreshTokenExpireIn = signInConfig.refreshTokenExpireIn; | ||
}; | ||
return React.createElement(Component, __assign({}, props, { signIn: signIn })); | ||
return React__namespace.createElement(Component, __assign({}, props, { signIn: signIn })); | ||
})); | ||
@@ -915,3 +936,3 @@ }; | ||
return function (props) { | ||
return (React.createElement(AuthContextConsumer, null, function (c) { | ||
return (React__namespace.createElement(AuthContextConsumer, null, function (c) { | ||
var signOut = function () { | ||
@@ -931,3 +952,3 @@ try { | ||
}; | ||
return React.createElement(Component, __assign({}, props, { signOut: signOut })); | ||
return React__namespace.createElement(Component, __assign({}, props, { signOut: signOut })); | ||
})); | ||
@@ -945,3 +966,3 @@ }; | ||
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 }))); })); | ||
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 }))); })); | ||
}; | ||
@@ -965,8 +986,8 @@ } | ||
return function (props) { | ||
return (React.createElement(AuthContextConsumer, null, function (c) { | ||
return (React__namespace.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 }))); | ||
return (React__namespace.createElement(Component, __assign({}, props, { authHeader: c.authState.authTokenType + " " + c.authState.authToken }))); | ||
} | ||
else { | ||
return React.createElement(Component, __assign({}, props, { authHeader: null })); | ||
return React__namespace.createElement(Component, __assign({}, props, { authHeader: null })); | ||
} | ||
@@ -992,4 +1013,4 @@ })); | ||
return function (props) { | ||
return (React.createElement(AuthContextConsumer, null, function (c) { | ||
return (React.createElement(Component, __assign({}, props, { refreshToken: new RefreshToken(c) }))); | ||
return (React__namespace.createElement(AuthContextConsumer, null, function (c) { | ||
return (React__namespace.createElement(Component, __assign({}, props, { refreshToken: new RefreshToken(c) }))); | ||
})); | ||
@@ -1014,14 +1035,14 @@ }; | ||
return function (props) { | ||
return (React.createElement(AuthContextConsumer, null, function (c) { | ||
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.createElement(Component, __assign({}, props, { isAuth: true })); | ||
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.createElement(Component, __assign({}, props, { isAuth: false })); | ||
return React__namespace.createElement(Component, __assign({}, props, { isAuth: false })); | ||
} | ||
} | ||
else { | ||
return React.createElement(Component, __assign({}, props, { isAuth: false })); | ||
return React__namespace.createElement(Component, __assign({}, props, { isAuth: false })); | ||
} | ||
@@ -1028,0 +1049,0 @@ })); |
@@ -1,2 +0,2 @@ | ||
import { createContext, useState, useEffect, createElement, useContext } from 'react'; | ||
import * as React from 'react'; | ||
import Cookies from 'js-cookie'; | ||
@@ -343,3 +343,3 @@ import { Route, Redirect } from 'react-router-dom'; | ||
var AuthContext = createContext({ | ||
var AuthContext = React.createContext({ | ||
authState: { | ||
@@ -387,7 +387,7 @@ authTokenType: null, | ||
}); | ||
var _b = useState(tokenObject.initialToken()), authState = _b[0], setAuthState = _b[1]; | ||
useEffect(function () { | ||
var _b = React.useState(tokenObject.initialToken()), authState = _b[0], setAuthState = _b[1]; | ||
React.useEffect(function () { | ||
tokenObject.syncTokens(authState); | ||
}, [authState]); | ||
return (createElement(AuthContext.Provider, { value: { authState: authState, setAuthState: setAuthState } }, children)); | ||
return (React.createElement(AuthContext.Provider, { value: { authState: authState, setAuthState: setAuthState } }, children)); | ||
}; | ||
@@ -439,3 +439,3 @@ AuthProvider.defaultProps = { | ||
var PrivateRoute = function (props) { | ||
var context = useContext(AuthContext); | ||
var context = React.useContext(AuthContext); | ||
var isAuth = function () { | ||
@@ -456,10 +456,10 @@ if ((context === null || context === void 0 ? void 0 : context.authState.authToken) && (context === null || context === void 0 ? void 0 : context.authState.expireAt)) { | ||
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 (createElement(Route, { location: location, path: path, exact: exact, sensitive: sensitive, strict: strict, render: function (renderProps) { | ||
return (React.createElement(Route, { location: location, path: path, exact: exact, sensitive: sensitive, strict: strict, render: function (renderProps) { | ||
return isAuth() ? | ||
component ? | ||
createElement(component, renderProps) : | ||
React.createElement(component, renderProps) : | ||
render ? | ||
render(renderProps) : | ||
null : | ||
createElement(Redirect, { to: loginPath }); | ||
React.createElement(Redirect, { to: loginPath }); | ||
} })); | ||
@@ -484,3 +484,3 @@ }; | ||
*/ | ||
var c = useContext(AuthContext); | ||
var c = React.useContext(AuthContext); | ||
/** @function | ||
@@ -594,3 +594,3 @@ * @name authHeader | ||
function useSignIn() { | ||
var context = useContext(AuthContext); | ||
var context = React.useContext(AuthContext); | ||
return function (signInConfig) { | ||
@@ -640,3 +640,3 @@ var token = signInConfig.token, tokenType = signInConfig.tokenType, authState = signInConfig.authState, expiresIn = signInConfig.expiresIn, refreshToken = signInConfig.refreshToken, refreshTokenExpireIn = signInConfig.refreshTokenExpireIn; | ||
*/ | ||
var c = useContext(AuthContext); | ||
var c = React.useContext(AuthContext); | ||
return function () { | ||
@@ -665,3 +665,3 @@ try { | ||
function useAuthUser() { | ||
var c = useContext(AuthContext); | ||
var c = React.useContext(AuthContext); | ||
return function () { | ||
@@ -676,3 +676,3 @@ return c.authState.authState; | ||
function useAuthHeader() { | ||
var c = useContext(AuthContext); | ||
var c = React.useContext(AuthContext); | ||
return function () { | ||
@@ -818,3 +818,3 @@ if (c === null || c === void 0 ? void 0 : c.authState) { | ||
function useRefreshToken() { | ||
var _context = useContext(AuthContext); | ||
var _context = React.useContext(AuthContext); | ||
return new RefreshToken(_context); | ||
@@ -835,3 +835,3 @@ } | ||
function useIsAuthenticated() { | ||
var context = useContext(AuthContext); | ||
var context = React.useContext(AuthContext); | ||
return function () { | ||
@@ -862,3 +862,3 @@ if ((context === null || context === void 0 ? void 0 : context.authState.authToken) && (context === null || context === void 0 ? void 0 : context.authState.expireAt)) { | ||
return function (props) { | ||
return (createElement(AuthContextConsumer, null, function (c) { | ||
return (React.createElement(AuthContextConsumer, null, function (c) { | ||
var signIn = function (signInConfig) { | ||
@@ -891,3 +891,3 @@ var token = signInConfig.token, tokenType = signInConfig.tokenType, authState = signInConfig.authState, expiresIn = signInConfig.expiresIn, refreshToken = signInConfig.refreshToken, refreshTokenExpireIn = signInConfig.refreshTokenExpireIn; | ||
}; | ||
return createElement(Component, __assign({}, props, { signIn: signIn })); | ||
return React.createElement(Component, __assign({}, props, { signIn: signIn })); | ||
})); | ||
@@ -906,3 +906,3 @@ }; | ||
return function (props) { | ||
return (createElement(AuthContextConsumer, null, function (c) { | ||
return (React.createElement(AuthContextConsumer, null, function (c) { | ||
var signOut = function () { | ||
@@ -922,3 +922,3 @@ try { | ||
}; | ||
return createElement(Component, __assign({}, props, { signOut: signOut })); | ||
return React.createElement(Component, __assign({}, props, { signOut: signOut })); | ||
})); | ||
@@ -936,3 +936,3 @@ }; | ||
return function (props) { | ||
return (createElement(AuthContextConsumer, null, function (value) { return (createElement(Component, __assign({}, props, { authState: value === null || value === void 0 ? void 0 : value.authState.authState }))); })); | ||
return (React.createElement(AuthContextConsumer, null, function (value) { return (React.createElement(Component, __assign({}, props, { authState: value === null || value === void 0 ? void 0 : value.authState.authState }))); })); | ||
}; | ||
@@ -956,8 +956,8 @@ } | ||
return function (props) { | ||
return (createElement(AuthContextConsumer, null, function (c) { | ||
return (React.createElement(AuthContextConsumer, null, function (c) { | ||
if (c === null || c === void 0 ? void 0 : c.authState) { | ||
return (createElement(Component, __assign({}, props, { authHeader: c.authState.authTokenType + " " + c.authState.authToken }))); | ||
return (React.createElement(Component, __assign({}, props, { authHeader: c.authState.authTokenType + " " + c.authState.authToken }))); | ||
} | ||
else { | ||
return createElement(Component, __assign({}, props, { authHeader: null })); | ||
return React.createElement(Component, __assign({}, props, { authHeader: null })); | ||
} | ||
@@ -983,4 +983,4 @@ })); | ||
return function (props) { | ||
return (createElement(AuthContextConsumer, null, function (c) { | ||
return (createElement(Component, __assign({}, props, { refreshToken: new RefreshToken(c) }))); | ||
return (React.createElement(AuthContextConsumer, null, function (c) { | ||
return (React.createElement(Component, __assign({}, props, { refreshToken: new RefreshToken(c) }))); | ||
})); | ||
@@ -1005,14 +1005,14 @@ }; | ||
return function (props) { | ||
return (createElement(AuthContextConsumer, null, function (c) { | ||
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 createElement(Component, __assign({}, props, { isAuth: true })); | ||
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 createElement(Component, __assign({}, props, { isAuth: false })); | ||
return React.createElement(Component, __assign({}, props, { isAuth: false })); | ||
} | ||
} | ||
else { | ||
return createElement(Component, __assign({}, props, { isAuth: false })); | ||
return React.createElement(Component, __assign({}, props, { isAuth: false })); | ||
} | ||
@@ -1019,0 +1019,0 @@ })); |
@@ -1,3 +0,3 @@ | ||
/*! react-auth-kit v1.4.5 | Apache-2.0 */ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("js-cookie"),require("react-router-dom")):"function"==typeof define&&define.amd?define(["exports","react","js-cookie","react-router-dom"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactAuthKit={},e.React,e.Cookies,e.reactRouterDom)}(this,(function(e,t,n,r){"use strict";function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=o(n),u=function(){function e(e){var t=e.authStorageName,n=e.authStorageType,r=e.authTimeStorageName,o=e.stateStorageName,a=e.refreshTokenName,u=e.cookieDomain,i=e.cookieSecure;this.authStorageType=n,this.authStorageName=t,this.authTimeStorageName=r,this.stateStorageName=o,this.refreshTokenName=a,this.cookieDomain=u,this.cookieSecure=i,this.authStorageTypeName=this.authStorageName+"_type",this.isUsingRefreshToken=!!this.refreshTokenName,this.refreshTokenTimeName=this.refreshTokenName?this.refreshTokenName+"_time":null}return e.prototype.initialToken=function(){return"cookie"===this.authStorageType?this.initialCookieToken_():this.initialLSToken_()},e.prototype.initialCookieToken_=function(){var e=a.default.get(this.authStorageName),t=a.default.get(this.authStorageTypeName),n=a.default.get(this.authTimeStorageName),r=a.default.get(this.stateStorageName),o=this.isUsingRefreshToken&&null!=this.refreshTokenName?a.default.get(this.refreshTokenName):null,u=this.isUsingRefreshToken&&null!=this.refreshTokenTimeName?a.default.get(this.refreshTokenTimeName):null;return this.checkTokenExist(e,t,n,r,o,u)},e.prototype.initialLSToken_=function(){var e=localStorage.getItem(this.authStorageName),t=localStorage.getItem(this.authStorageTypeName),n=localStorage.getItem(this.authTimeStorageName),r=localStorage.getItem(this.stateStorageName),o=this.isUsingRefreshToken&&null!=this.refreshTokenName?localStorage.getItem(this.refreshTokenName):null,a=this.isUsingRefreshToken&&null!=this.refreshTokenTimeName?localStorage.getItem(this.refreshTokenTimeName):null;return this.checkTokenExist(e,t,n,r,o,a)},e.prototype.checkTokenExist=function(e,t,n,r,o,a){if(!(e&&t&&n&&r))return{authToken:null,authTokenType:null,isUsingRefreshToken:this.isUsingRefreshToken,refreshToken:null,expireAt:null,authState:null,refreshTokenExpireAt:null};var u=new Date(n);try{var i=JSON.parse(r);return{authToken:e,authTokenType:t,isUsingRefreshToken:this.isUsingRefreshToken,refreshToken:this.isUsingRefreshToken&&o?o:null,refreshTokenExpireAt:this.isUsingRefreshToken&&a?new Date(a):null,expireAt:u,authState:i}}catch(e){return{authToken:null,authTokenType:null,isUsingRefreshToken:this.isUsingRefreshToken,refreshToken:null,expireAt:null,authState:null,refreshTokenExpireAt:null}}},e.prototype.syncTokens=function(e){void 0===e.authToken||null===e.authTokenType||null===e.authToken||null===e.expireAt||null===e.authState?this.removeToken():this.setToken(e.authToken,e.authTokenType,e.refreshToken,e.refreshTokenExpireAt,e.expireAt,e.authState)},e.prototype.setToken=function(e,t,n,r,o,a){"cookie"===this.authStorageType?this.setCookieToken_(e,t,n,o,r,a):this.setLSToken_(e,t,n,o,r,a)},e.prototype.setCookieToken_=function(e,t,n,r,o,u){a.default.set(this.authStorageName,e,{expires:r,domain:this.cookieDomain,secure:this.cookieSecure}),a.default.set(this.authStorageTypeName,t,{expires:r,domain:this.cookieDomain,secure:this.cookieSecure}),a.default.set(this.authTimeStorageName,r.toISOString(),{expires:r,domain:this.cookieDomain,secure:this.cookieSecure}),a.default.set(this.stateStorageName,u,{expires:r,domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenName&&n&&a.default.set(this.refreshTokenName,n,{expires:r,domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenTimeName&&o&&a.default.set(this.refreshTokenTimeName,o.toISOString(),{expires:r,domain:this.cookieDomain,secure:this.cookieSecure})},e.prototype.setLSToken_=function(e,t,n,r,o,a){localStorage.setItem(this.authStorageName,e),localStorage.setItem(this.authStorageTypeName,t),localStorage.setItem(this.authTimeStorageName,r.toISOString()),localStorage.setItem(this.stateStorageName,JSON.stringify(a)),this.isUsingRefreshToken&&this.refreshTokenName&&n&&localStorage.setItem(this.refreshTokenName,n),this.isUsingRefreshToken&&this.refreshTokenTimeName&&o&&localStorage.setItem(this.refreshTokenTimeName,o.toISOString())},e.prototype.removeToken=function(){"cookie"===this.authStorageType?this.removeCookieToken_():this.removeLSToken_()},e.prototype.removeCookieToken_=function(){a.default.remove(this.authStorageName,{domain:this.cookieDomain,secure:this.cookieSecure}),a.default.remove(this.authTimeStorageName,{domain:this.cookieDomain,secure:this.cookieSecure}),a.default.remove(this.stateStorageName,{domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenName&&a.default.remove(this.refreshTokenName,{domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenTimeName&&a.default.remove(this.refreshTokenTimeName,{domain:this.cookieDomain,secure:this.cookieSecure})},e.prototype.removeLSToken_=function(){localStorage.removeItem(this.authStorageName),localStorage.removeItem(this.authTimeStorageName),localStorage.removeItem(this.stateStorageName),this.isUsingRefreshToken&&this.refreshTokenName&&localStorage.removeItem(this.refreshTokenName),this.isUsingRefreshToken&&this.refreshTokenTimeName&&localStorage.removeItem(this.refreshTokenTimeName)},e}(),i=t.createContext({authState:{authTokenType:null,authState:null,authToken:null,isUsingRefreshToken:!1,refreshToken:null,refreshTokenExpireAt:null,expireAt:null},setAuthState:function(){}}),h=function(e){var n=e.children,r=e.authStorageType,o=e.authStorageName,a=e.authTimeStorageName,h=e.stateStorageName,s=e.refreshTokenName,l=e.cookieDomain,T=e.cookieSecure;if("cookie"===r&&!l)throw new Error("authStorageType 'cookie' requires 'cookieDomain' and 'cookieSecure' in AuthProvider");var c=new u({authTimeStorageName:a,authStorageType:r,authStorageName:o,refreshTokenName:s,cookieDomain:l,cookieSecure:T,stateStorageName:h}),f=t.useState(c.initialToken()),k=f[0],m=f[1];return t.useEffect((function(){c.syncTokens(k)}),[k]),t.createElement(i.Provider,{value:{authState:k,setAuthState:m}},n)};h.defaultProps={authStorageType:"cookie",authStorageName:"_auth_token",authTimeStorageName:"_auth_time",stateStorageName:"_auth_state",cookieSecure:!0};var s=i.Consumer,l=function(){return(l=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)}; | ||
/*! react-auth-kit v1.4.6 | 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.authStorageType,r=e.authStorageName,o=e.authTimeStorageName,a=e.stateStorageName,i=e.refreshTokenName,l=e.cookieDomain,c=e.cookieSecure;if("cookie"===n&&!l)throw new Error("authStorageType 'cookie' requires 'cookieDomain' and 'cookieSecure' in AuthProvider");var f=new h({authTimeStorageName:o,authStorageType:n,authStorageName:r,refreshTokenName:i,cookieDomain:l,cookieSecure:c,stateStorageName:a}),T=u.useState(f.initialToken()),k=T[0],m=T[1];return u.useEffect((function(){f.syncTokens(k)}),[k]),u.createElement(s.Provider,{value:{authState:k,setAuthState:m}},t)};l.defaultProps={authStorageType:"cookie",authStorageName:"_auth_token",authTimeStorageName:"_auth_time",stateStorageName:"_auth_state",cookieSecure:!0};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)}; | ||
/*! ***************************************************************************** | ||
@@ -16,3 +16,3 @@ Copyright (c) Microsoft Corporation. | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */var T=function(){function e(e){if(this.context=e,!this.context.authState.isUsingRefreshToken)throw new Error("The app doesn't implement 'refreshToken' feature.\nSo you have to implement refresh token feature from 'AuthProvider' before using it.")}return e.prototype.getCurrentRefreshToken=function(){return{refreshToken:this.context.authState.refreshToken,refreshTokenExpireAt:this.context.authState.refreshTokenExpireAt}},e.prototype.getCurrentAuthState=function(){return{authToken:this.context.authState.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 l(l({},t),{refreshToken:e,refreshTokenExpireAt:n})}))},e.prototype.updateAuthState=function(e,t,n){var r={authToken:e};if(void 0!==t&&Object.assign(r,{authTokenType:t}),void 0!==n){var o=new Date((new Date).getTime()+60*n*1e3);Object.assign(r,{expireAt:o})}this.context.setAuthState((function(e){return l(l({},e),r)}))},e.prototype.updateUserState=function(e){this.context.setAuthState((function(t){return l(l({},t),{authState:e})}))},e}();e.AuthProvider=h,e.PrivateRoute=function(e){var n=t.useContext(i),o=e.component,a=e.loginPath,u=e.strict,h=e.sensitive,s=e.exact,T=e.path,c=e.location,f=e.render;return t.createElement(r.Route,{location:c,path:T,exact:s,sensitive:h,strict:u,render:function(e){return(null==n?void 0:n.authState.authToken)&&(null==n?void 0:n.authState.expireAt)&&(new Date(n.authState.expireAt)>new Date||(n.setAuthState((function(e){return l(l({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),0))?o?t.createElement(o,e):f?f(e):null:t.createElement(r.Redirect,{to:a})}})},e.useAuth= | ||
***************************************************************************** */var T=function(){function e(e){if(this.context=e,!this.context.authState.isUsingRefreshToken)throw new Error("The app doesn't implement 'refreshToken' feature.\nSo you have to implement refresh token feature from 'AuthProvider' before using it.")}return e.prototype.getCurrentRefreshToken=function(){return{refreshToken:this.context.authState.refreshToken,refreshTokenExpireAt:this.context.authState.refreshTokenExpireAt}},e.prototype.getCurrentAuthState=function(){return{authToken:this.context.authState.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= | ||
/** | ||
@@ -24,3 +24,3 @@ *@author Arkadip Bhattacharya <in2arkadipb13@gmail.com> | ||
*/ | ||
function(){var e=t.useContext(i);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 l(l({},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 l(l({},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 l(l({},e),{authToken:n,authTokenType:r,expireAt:h,authState:o,refreshToken:u||null,refreshTokenExpireAt:s})})),!0)}catch(e){return console.error(e),!1}}}} | ||
function(){var e=u.useContext(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}}}} | ||
/** | ||
@@ -31,3 +31,3 @@ *@author Arkadip Bhattacharya <in2arkadipb13@gmail.com> | ||
*@license Apache-2.0 | ||
*/,e.useAuthHeader=function(){var e=t.useContext(i);return function(){return(null==e?void 0:e.authState)?e.authState.authTokenType+" "+e.authState.authToken:"Bearer "}},e.useAuthUser=function(){var e=t.useContext(i);return function(){return e.authState.authState}},e.useIsAuthenticated= | ||
*/,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= | ||
/** | ||
@@ -39,3 +39,3 @@ *@author Arkadip Bhattacharya <in2arkadipb13@gmail.com> | ||
*/ | ||
function(){var e=t.useContext(i);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 l(l({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),!1))}},e.useRefreshToken=function(){var e=t.useContext(i);return new T(e)},e.useSignIn=function(){var e=t.useContext(i);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 l(l({},e),{authToken:n,authTokenType:r,expireAt:h,authState:o,refreshToken:u||null,refreshTokenExpireAt:s})})),!0)}catch(e){return console.error(e),!1}}} | ||
function(){var e=u.useContext(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}}} | ||
/** | ||
@@ -46,3 +46,3 @@ *@author Arkadip Bhattacharya <in2arkadipb13@gmail.com> | ||
*@license Apache-2.0 | ||
*/,e.useSignOut=function(){var e=t.useContext(i);return function(){try{return!!(null==e?void 0:e.authState.authToken)&&(e.setAuthState((function(e){return l(l({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),console.log("RAJ :: Signing Out"),!0)}catch(e){return!1}}},e.withAuthHeader= | ||
*/,e.useSignOut=function(){var e=u.useContext(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= | ||
/** | ||
@@ -54,3 +54,3 @@ *@author Arkadip Bhattacharya <in2arkadipb13@gmail.com> | ||
*/ | ||
function(e){return function(n){return t.createElement(s,null,(function(r){return(null==r?void 0:r.authState)?t.createElement(e,l({},n,{authHeader:r.authState.authTokenType+" "+r.authState.authToken})):t.createElement(e,l({},n,{authHeader:null}))}))}} | ||
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}))}))}} | ||
/** | ||
@@ -61,3 +61,3 @@ *@author Arkadip Bhattacharya <in2arkadipb13@gmail.com> | ||
*@license Apache-2.0 | ||
*/,e.withAuthUser=function(e){return function(n){return t.createElement(s,null,(function(r){return t.createElement(e,l({},n,{authState:null==r?void 0:r.authState.authState}))}))}},e.withIsAuthenticated= | ||
*/,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= | ||
/** | ||
@@ -69,2 +69,2 @@ *@author Arkadip Bhattacharya <in2arkadipb13@gmail.com> | ||
*/ | ||
function(e){return function(n){return t.createElement(s,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?t.createElement(e,l({},n,{isAuth:!0})):(r.setAuthState((function(e){return l(l({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),t.createElement(e,l({},n,{isAuth:!1}))):t.createElement(e,l({},n,{isAuth:!1}))}))}},e.withRefreshToken=function(e){return function(n){return t.createElement(s,null,(function(r){return t.createElement(e,l({},n,{refreshToken:new T(r)}))}))}},e.withSignIn=function(e){return function(n){return t.createElement(s,null,(function(r){return t.createElement(e,l({},n,{signIn:function(e){var t=e.token,n=e.tokenType,o=e.authState,a=e.expiresIn,u=e.refreshToken,i=e.refreshTokenExpireIn;if((u||i)&&!r.authState.isUsingRefreshToken)throw new Error("The app doesn't implement 'refreshToken' feature.\nSo you have to implement refresh token feature from 'AuthProvider' before using it.");var h=new Date((new Date).getTime()+60*a*1e3),s=i?new Date((new Date).getTime()+60*i*1e3):null;try{return!!r&&(r.setAuthState((function(e){return l(l({},e),{authToken:t,authTokenType:n,expireAt:h,authState:o,refreshToken:u||null,refreshTokenExpireAt:s})})),!0)}catch(e){return console.error(e),!1}}}))}))}},e.withSignOut=function(e){return function(n){return t.createElement(s,null,(function(r){return t.createElement(e,l({},n,{signOut:function(){try{return!!(null==r?void 0:r.authState.authToken)&&(r.setAuthState((function(e){return l(l({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null})})),!0)}catch(e){return!1}}}))}))}},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
function(e){return function(t){return u.createElement(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.5", | ||
"version": "1.4.6", | ||
"description": "Authentication Library for React, which makes Token based auth very easy", | ||
@@ -45,3 +45,3 @@ "source": "src/index.tsx", | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^17.0.0", | ||
"@rollup/plugin-commonjs": "^18.0.0", | ||
"@rollup/plugin-node-resolve": "^11.1.0", | ||
@@ -68,3 +68,3 @@ "@types/jest": "^26.0.10", | ||
"rollup-plugin-terser": "^7.0.0", | ||
"rollup-plugin-typescript2": "^0.29.0", | ||
"rollup-plugin-typescript2": "^0.30.0", | ||
"ts-jest": "^26.3.0", | ||
@@ -71,0 +71,0 @@ "typedoc": "^0.20.16", |
@@ -0,0 +0,0 @@ <p align="center"> |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
130680
2666