New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-auth-kit

Package Overview
Dependencies
Maintainers
1
Versions
200
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-auth-kit - npm Package Compare versions

Comparing version 1.4.17-0 to 1.4.18-0

dist/__tests__/TokenObject.test.d.ts

3

CHANGELOG.md

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

## [1.4.17-0] - 2021-08-25
Refresh Token reformat
## [1.4.16] - 2021-08-03

@@ -12,0 +9,0 @@ ### Fix:

@@ -34,3 +34,3 @@ /**

*/
declare function withAuthHeader<P extends withAuthHeaderProps>(Component: React.ComponentType<P>): React.FC<P>;
declare function withAuthHeader<P extends withAuthHeaderProps>(Component: React.ComponentType<P>): React.FunctionComponent<P>;
/**

@@ -37,0 +37,0 @@ *@exports withAuthHeader

@@ -34,3 +34,3 @@ /**

*/
declare function withAuthUser<P extends withAuthProps>(Component: React.ComponentType<P>): React.FC<P>;
declare function withAuthUser<P extends withAuthProps>(Component: React.ComponentType<P>): React.FunctionComponent<P>;
/**

@@ -37,0 +37,0 @@ * @exports withAuthUser

@@ -34,3 +34,3 @@ /**

*/
declare function withIsAuthenticated<P extends withAuthHeaderProps>(Component: React.ComponentType<P>): React.FC<P>;
declare function withIsAuthenticated<P extends withAuthHeaderProps>(Component: React.ComponentType<P>): React.FunctionComponent<P>;
export default withIsAuthenticated;

@@ -35,3 +35,3 @@ /**

*/
declare function withRefreshToken<P extends withRefreshTokenProps>(Component: React.ComponentType<P>): React.FC<P>;
declare function withRefreshToken<P extends withRefreshTokenProps>(Component: React.ComponentType<P>): React.FunctionComponent<P>;
export default withRefreshToken;

@@ -35,3 +35,3 @@ /**

*/
declare function withSignIn<P extends withSignInProps>(Component: React.ComponentType<P>): React.FC<P>;
declare function withSignIn<P extends withSignInProps>(Component: React.ComponentType<P>): React.FunctionComponent<P>;
export default withSignIn;

@@ -34,3 +34,3 @@ /**

*/
declare function withSignOut<P extends withSignOutProps>(Component: React.ComponentType<P>): React.FC<P>;
declare function withSignOut<P extends withSignOutProps>(Component: React.ComponentType<P>): React.FunctionComponent<P>;
export default withSignOut;

@@ -12,19 +12,19 @@ '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];
}
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);
}
n['default'] = e;
return Object.freeze(n);
}

@@ -57,2 +57,28 @@

/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
var __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);
};
/**

@@ -186,24 +212,30 @@ * @class TokenObject

var authState = JSON.parse(stateCookie);
return {
authToken: authToken,
authTokenType: authTokenType,
var obj = {
auth: {
token: authToken,
type: authTokenType,
expiresAt: expiresAt,
},
userState: authState,
isSignIn: true,
isUsingRefreshToken: this.isUsingRefreshToken,
refreshToken: this.isUsingRefreshToken && !!refreshToken ?
refreshToken : null,
refreshTokenExpireAt: this.isUsingRefreshToken &&
!!refreshTokenTime ? new Date(refreshTokenTime) : null,
expireAt: expiresAt,
authState: authState,
isSignIn: true,
refresh: undefined,
};
if (this.isUsingRefreshToken && !!refreshToken && !!refreshTokenTime) {
var refreshTokenExpiresAt = new Date(refreshTokenTime);
return __assign(__assign({}, obj), { refresh: {
token: refreshToken,
expiresAt: refreshTokenExpiresAt,
} });
}
else {
return __assign(__assign({}, obj), { refresh: null });
}
}
catch (e) {
return {
authToken: null,
authTokenType: null,
auth: null,
refresh: null,
userState: null,
isUsingRefreshToken: this.isUsingRefreshToken,
refreshToken: null,
expireAt: null,
authState: null,
refreshTokenExpireAt: null,
isSignIn: false,

@@ -215,9 +247,6 @@ };

return {
authToken: null,
authTokenType: null,
auth: null,
refresh: null,
userState: null,
isUsingRefreshToken: this.isUsingRefreshToken,
refreshToken: null,
expireAt: null,
authState: null,
refreshTokenExpireAt: null,
isSignIn: false,

@@ -236,11 +265,12 @@ };

TokenObject.prototype.syncTokens = function (authState) {
if (authState.authToken === undefined ||
authState.authTokenType === null ||
authState.authToken === null ||
authState.expireAt === null ||
authState.authState === null) {
this.removeToken();
if (authState.auth) {
if (this.isUsingRefreshToken && authState.refresh) {
this.setToken(authState.auth.token, authState.auth.type, authState.refresh.token, authState.refresh.expiresAt, authState.auth.expiresAt, authState.userState);
}
else {
this.setToken(authState.auth.token, authState.auth.type, null, null, authState.auth.expiresAt, authState.userState);
}
}
else {
this.setToken(authState.authToken, authState.authTokenType, authState.refreshToken, authState.refreshTokenExpireAt, authState.expireAt, authState.authState);
this.removeToken();
}

@@ -293,7 +323,9 @@ };

});
Cookies__default['default'].set(this.stateStorageName, JSON.stringify(authState), {
expires: expiresAt,
domain: this.cookieDomain,
secure: this.cookieSecure,
});
if (authState) {
Cookies__default['default'].set(this.stateStorageName, JSON.stringify(authState), {
expires: expiresAt,
domain: this.cookieDomain,
secure: this.cookieSecure,
});
}
if (this.isUsingRefreshToken && !!this.refreshTokenName &&

@@ -330,3 +362,5 @@ !!refreshToken) {

localStorage.setItem(this.authTimeStorageName, expiresAt.toISOString());
localStorage.setItem(this.stateStorageName, JSON.stringify(authState));
if (authState) {
localStorage.setItem(this.stateStorageName, JSON.stringify(authState));
}
if (this.isUsingRefreshToken && !!this.refreshTokenName &&

@@ -403,28 +437,2 @@ !!refreshToken) {

/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
var __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);
};
/**

@@ -464,12 +472,5 @@ * @author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

case ActionType.SignIn:
if (action.payload.refresh) {
// return with refresh token
return __assign(__assign({}, state), { authToken: action.payload.auth.token, authTokenType: action.payload.auth.type, expireAt: action.payload.auth.expiresAt, authState: action.payload.userState, refreshToken: action.payload.refresh.token, refreshTokenExpireAt: action.payload.refresh.expiresAt, isSignIn: true });
}
else {
// return without refresh token
return __assign(__assign({}, state), { authToken: action.payload.auth.token, authTokenType: action.payload.auth.type, expireAt: action.payload.auth.expiresAt, authState: action.payload.userState, refreshToken: null, refreshTokenExpireAt: null, isSignIn: true });
}
return __assign(__assign({}, state), { auth: action.payload.auth, refresh: action.payload.refresh, userState: action.payload.userState, isSignIn: true });
case ActionType.SignOut:
return __assign(__assign({}, state), { authToken: null, authTokenType: null, expireAt: null, authState: null, refreshToken: null, refreshTokenExpireAt: null, isSignIn: false });
return __assign(__assign({}, state), { auth: null, refresh: null, userState: null, isSignIn: false });
default:

@@ -562,4 +563,4 @@ return state;

var isAuth = function () {
if (context.authState.authToken && context.authState.expireAt) {
if (new Date(context.authState.expireAt) > new Date()) {
if (context.authState.auth) {
if (new Date(context.authState.auth.expiresAt) > new Date()) {
return true;

@@ -758,3 +759,4 @@ }

return function () {
return context.authState.authState;
return context.authState.auth ?
context.authState.userState : null;
};

@@ -792,4 +794,4 @@ }

return function () {
if (c === null || c === void 0 ? void 0 : c.authState) {
return c.authState.authTokenType + " " + c.authState.authToken;
if (c.authState.auth) {
return c.authState.auth.type + " " + c.authState.auth.token;
}

@@ -903,4 +905,4 @@ else {

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()) {
if (context.authState.auth) {
if (new Date(context.authState.auth.expiresAt) > new Date()) {
return true;

@@ -1039,3 +1041,8 @@ }

}
return (React__namespace.createElement(Component, __assign({}, props, { authState: context === null || context === void 0 ? void 0 : context.authState.authState })));
if (context.authState.auth) {
return (React__namespace.createElement(Component, __assign({}, props, { authState: context.authState.userState })));
}
else {
return (React__namespace.createElement(Component, __assign({}, props, { authState: null })));
}
}));

@@ -1078,7 +1085,7 @@ };

}
if (c === null || c === void 0 ? void 0 : c.authState) {
return (React__namespace.createElement(Component, __assign({}, props, { authHeader: c.authState.authTokenType + " " + c.authState.authToken })));
if (c.authState.auth) {
return (React__namespace.createElement(Component, __assign({}, props, { authHeader: c.authState.auth.type + " " + c.authState.auth.token })));
}
else {
return React__namespace.createElement(Component, __assign({}, props, { authHeader: null }));
return React__namespace.createElement(Component, __assign({}, props, { authHeader: "" }));
}

@@ -1160,4 +1167,4 @@ }));

}
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()) {
if (c.authState.auth) {
if (new Date(c.authState.auth.expiresAt) > new Date()) {
return React__namespace.createElement(Component, __assign({}, props, { isAuth: true }));

@@ -1191,2 +1198,3 @@ }

* limitations under the License.
* last updated 25th August 2021
*/

@@ -1193,0 +1201,0 @@ // Default prop for AuthProvider

@@ -27,2 +27,28 @@ import * as React from 'react';

/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
var __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);
};
/**

@@ -156,24 +182,30 @@ * @class TokenObject

var authState = JSON.parse(stateCookie);
return {
authToken: authToken,
authTokenType: authTokenType,
var obj = {
auth: {
token: authToken,
type: authTokenType,
expiresAt: expiresAt,
},
userState: authState,
isSignIn: true,
isUsingRefreshToken: this.isUsingRefreshToken,
refreshToken: this.isUsingRefreshToken && !!refreshToken ?
refreshToken : null,
refreshTokenExpireAt: this.isUsingRefreshToken &&
!!refreshTokenTime ? new Date(refreshTokenTime) : null,
expireAt: expiresAt,
authState: authState,
isSignIn: true,
refresh: undefined,
};
if (this.isUsingRefreshToken && !!refreshToken && !!refreshTokenTime) {
var refreshTokenExpiresAt = new Date(refreshTokenTime);
return __assign(__assign({}, obj), { refresh: {
token: refreshToken,
expiresAt: refreshTokenExpiresAt,
} });
}
else {
return __assign(__assign({}, obj), { refresh: null });
}
}
catch (e) {
return {
authToken: null,
authTokenType: null,
auth: null,
refresh: null,
userState: null,
isUsingRefreshToken: this.isUsingRefreshToken,
refreshToken: null,
expireAt: null,
authState: null,
refreshTokenExpireAt: null,
isSignIn: false,

@@ -185,9 +217,6 @@ };

return {
authToken: null,
authTokenType: null,
auth: null,
refresh: null,
userState: null,
isUsingRefreshToken: this.isUsingRefreshToken,
refreshToken: null,
expireAt: null,
authState: null,
refreshTokenExpireAt: null,
isSignIn: false,

@@ -206,11 +235,12 @@ };

TokenObject.prototype.syncTokens = function (authState) {
if (authState.authToken === undefined ||
authState.authTokenType === null ||
authState.authToken === null ||
authState.expireAt === null ||
authState.authState === null) {
this.removeToken();
if (authState.auth) {
if (this.isUsingRefreshToken && authState.refresh) {
this.setToken(authState.auth.token, authState.auth.type, authState.refresh.token, authState.refresh.expiresAt, authState.auth.expiresAt, authState.userState);
}
else {
this.setToken(authState.auth.token, authState.auth.type, null, null, authState.auth.expiresAt, authState.userState);
}
}
else {
this.setToken(authState.authToken, authState.authTokenType, authState.refreshToken, authState.refreshTokenExpireAt, authState.expireAt, authState.authState);
this.removeToken();
}

@@ -263,7 +293,9 @@ };

});
Cookies.set(this.stateStorageName, JSON.stringify(authState), {
expires: expiresAt,
domain: this.cookieDomain,
secure: this.cookieSecure,
});
if (authState) {
Cookies.set(this.stateStorageName, JSON.stringify(authState), {
expires: expiresAt,
domain: this.cookieDomain,
secure: this.cookieSecure,
});
}
if (this.isUsingRefreshToken && !!this.refreshTokenName &&

@@ -300,3 +332,5 @@ !!refreshToken) {

localStorage.setItem(this.authTimeStorageName, expiresAt.toISOString());
localStorage.setItem(this.stateStorageName, JSON.stringify(authState));
if (authState) {
localStorage.setItem(this.stateStorageName, JSON.stringify(authState));
}
if (this.isUsingRefreshToken && !!this.refreshTokenName &&

@@ -373,28 +407,2 @@ !!refreshToken) {

/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
var __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);
};
/**

@@ -434,12 +442,5 @@ * @author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

case ActionType.SignIn:
if (action.payload.refresh) {
// return with refresh token
return __assign(__assign({}, state), { authToken: action.payload.auth.token, authTokenType: action.payload.auth.type, expireAt: action.payload.auth.expiresAt, authState: action.payload.userState, refreshToken: action.payload.refresh.token, refreshTokenExpireAt: action.payload.refresh.expiresAt, isSignIn: true });
}
else {
// return without refresh token
return __assign(__assign({}, state), { authToken: action.payload.auth.token, authTokenType: action.payload.auth.type, expireAt: action.payload.auth.expiresAt, authState: action.payload.userState, refreshToken: null, refreshTokenExpireAt: null, isSignIn: true });
}
return __assign(__assign({}, state), { auth: action.payload.auth, refresh: action.payload.refresh, userState: action.payload.userState, isSignIn: true });
case ActionType.SignOut:
return __assign(__assign({}, state), { authToken: null, authTokenType: null, expireAt: null, authState: null, refreshToken: null, refreshTokenExpireAt: null, isSignIn: false });
return __assign(__assign({}, state), { auth: null, refresh: null, userState: null, isSignIn: false });
default:

@@ -532,4 +533,4 @@ return state;

var isAuth = function () {
if (context.authState.authToken && context.authState.expireAt) {
if (new Date(context.authState.expireAt) > new Date()) {
if (context.authState.auth) {
if (new Date(context.authState.auth.expiresAt) > new Date()) {
return true;

@@ -728,3 +729,4 @@ }

return function () {
return context.authState.authState;
return context.authState.auth ?
context.authState.userState : null;
};

@@ -762,4 +764,4 @@ }

return function () {
if (c === null || c === void 0 ? void 0 : c.authState) {
return c.authState.authTokenType + " " + c.authState.authToken;
if (c.authState.auth) {
return c.authState.auth.type + " " + c.authState.auth.token;
}

@@ -873,4 +875,4 @@ else {

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()) {
if (context.authState.auth) {
if (new Date(context.authState.auth.expiresAt) > new Date()) {
return true;

@@ -1009,3 +1011,8 @@ }

}
return (React.createElement(Component, __assign({}, props, { authState: context === null || context === void 0 ? void 0 : context.authState.authState })));
if (context.authState.auth) {
return (React.createElement(Component, __assign({}, props, { authState: context.authState.userState })));
}
else {
return (React.createElement(Component, __assign({}, props, { authState: null })));
}
}));

@@ -1048,7 +1055,7 @@ };

}
if (c === null || c === void 0 ? void 0 : c.authState) {
return (React.createElement(Component, __assign({}, props, { authHeader: c.authState.authTokenType + " " + c.authState.authToken })));
if (c.authState.auth) {
return (React.createElement(Component, __assign({}, props, { authHeader: c.authState.auth.type + " " + c.authState.auth.token })));
}
else {
return React.createElement(Component, __assign({}, props, { authHeader: null }));
return React.createElement(Component, __assign({}, props, { authHeader: "" }));
}

@@ -1130,4 +1137,4 @@ }));

}
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()) {
if (c.authState.auth) {
if (new Date(c.authState.auth.expiresAt) > new Date()) {
return React.createElement(Component, __assign({}, props, { isAuth: true }));

@@ -1161,2 +1168,3 @@ }

* limitations under the License.
* last updated 25th August 2021
*/

@@ -1163,0 +1171,0 @@ // Default prop for AuthProvider

@@ -1,24 +0,24 @@

/*! react-auth-kit v1.4.17-0 | Apache-2.0 */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("js-cookie"),require("react-router-dom")):"function"==typeof define&&define.amd?define(["exports","react","js-cookie","react-router-dom"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactAuthKit={},e.React,e.Cookies,e.ReactRouterDOM)}(this,(function(e,t,r,o){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function i(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var a,s=i(t),u=n(r),h=s.createContext(null),l=h.Consumer,f=function(){function e(e,t,r,o,n){this.authStorageType=t,this.authStorageName=e,this.authTimeStorageName=e+"_storage",this.stateStorageName=e+"_state",this.refreshTokenName=r,this.cookieDomain=o,this.cookieSecure=n,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),r=u.default.get(this.authTimeStorageName),o=u.default.get(this.stateStorageName),n=this.isUsingRefreshToken&&null!=this.refreshTokenName?u.default.get(this.refreshTokenName):null,i=this.isUsingRefreshToken&&null!=this.refreshTokenTimeName?u.default.get(this.refreshTokenTimeName):null;return this.checkTokenExist(e,t,r,o,n,i)},e.prototype.initialLSToken_=function(){var e=localStorage.getItem(this.authStorageName),t=localStorage.getItem(this.authStorageTypeName),r=localStorage.getItem(this.authTimeStorageName),o=localStorage.getItem(this.stateStorageName),n=this.isUsingRefreshToken&&null!=this.refreshTokenName?localStorage.getItem(this.refreshTokenName):null,i=this.isUsingRefreshToken&&null!=this.refreshTokenTimeName?localStorage.getItem(this.refreshTokenTimeName):null;return this.checkTokenExist(e,t,r,o,n,i)},e.prototype.checkTokenExist=function(e,t,r,o,n,i){if(!(e&&t&&r&&o))return{authToken:null,authTokenType:null,isUsingRefreshToken:this.isUsingRefreshToken,refreshToken:null,expireAt:null,authState:null,refreshTokenExpireAt:null,isSignIn:!1};var a=new Date(r);try{var s=JSON.parse(o);return{authToken:e,authTokenType:t,isUsingRefreshToken:this.isUsingRefreshToken,refreshToken:this.isUsingRefreshToken&&n?n:null,refreshTokenExpireAt:this.isUsingRefreshToken&&i?new Date(i):null,expireAt:a,authState:s,isSignIn:!0}}catch(e){return{authToken:null,authTokenType:null,isUsingRefreshToken:this.isUsingRefreshToken,refreshToken:null,expireAt:null,authState:null,refreshTokenExpireAt:null,isSignIn:!1}}},e.prototype.syncTokens=function(e){void 0===e.authToken||null===e.authTokenType||null===e.authToken||null===e.expireAt||null===e.authState?this.removeToken():this.setToken(e.authToken,e.authTokenType,e.refreshToken,e.refreshTokenExpireAt,e.expireAt,e.authState)},e.prototype.setToken=function(e,t,r,o,n,i){"cookie"===this.authStorageType?this.setCookieToken_(e,t,r,n,o,i):this.setLSToken_(e,t,r,n,o,i)},e.prototype.setCookieToken_=function(e,t,r,o,n,i){u.default.set(this.authStorageName,e,{expires:o,domain:this.cookieDomain,secure:this.cookieSecure}),u.default.set(this.authStorageTypeName,t,{expires:o,domain:this.cookieDomain,secure:this.cookieSecure}),u.default.set(this.authTimeStorageName,o.toISOString(),{expires:o,domain:this.cookieDomain,secure:this.cookieSecure}),u.default.set(this.stateStorageName,JSON.stringify(i),{expires:o,domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenName&&r&&u.default.set(this.refreshTokenName,r,{expires:o,domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenTimeName&&n&&u.default.set(this.refreshTokenTimeName,n.toISOString(),{expires:o,domain:this.cookieDomain,secure:this.cookieSecure})},e.prototype.setLSToken_=function(e,t,r,o,n,i){localStorage.setItem(this.authStorageName,e),localStorage.setItem(this.authStorageTypeName,t),localStorage.setItem(this.authTimeStorageName,o.toISOString()),localStorage.setItem(this.stateStorageName,JSON.stringify(i)),this.isUsingRefreshToken&&this.refreshTokenName&&r&&localStorage.setItem(this.refreshTokenName,r),this.isUsingRefreshToken&&this.refreshTokenTimeName&&n&&localStorage.setItem(this.refreshTokenTimeName,n.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.authStorageTypeName,{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.authStorageTypeName),localStorage.removeItem(this.stateStorageName),this.isUsingRefreshToken&&this.refreshTokenName&&localStorage.removeItem(this.refreshTokenName),this.isUsingRefreshToken&&this.refreshTokenTimeName&&localStorage.removeItem(this.refreshTokenTimeName)},e}(),c=function(){return(c=Object.assign||function(e){for(var t,r=1,o=arguments.length;r<o;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e}).apply(this,arguments)};function m(e,t){switch(t.type){case a.SignIn:return t.payload.refresh?c(c({},e),{authToken:t.payload.auth.token,authTokenType:t.payload.auth.type,expireAt:t.payload.auth.expiresAt,authState:t.payload.userState,refreshToken:t.payload.refresh.token,refreshTokenExpireAt:t.payload.refresh.expiresAt,isSignIn:!0}):c(c({},e),{authToken:t.payload.auth.token,authTokenType:t.payload.auth.type,expireAt:t.payload.auth.expiresAt,authState:t.payload.userState,refreshToken:null,refreshTokenExpireAt:null,isSignIn:!0});case a.SignOut:return c(c({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null,isSignIn:!1});default:return e}}function k(e){return{type:a.SignIn,payload:e}}function T(){return{type:a.SignOut}}!function(e){e[e.SignIn=0]="SignIn",e[e.SignOut=1]="SignOut"}(a||(a={}));var p=function(e){var t=e.children,r=e.authType,o=e.authName,n=e.refreshToken,i=e.cookieDomain,a=e.cookieSecure;if("cookie"===r&&!i)throw new Error("authType 'cookie' requires 'cookieDomain' and 'cookieSecure' props in AuthProvider");var u=new f(o,r,n?o+"_refresh":null,i,a),l=s.useReducer(m,u.initialToken()),c=l[0],k=l[1];return s.useEffect((function(){u.syncTokens(c)}),[c]),s.createElement(h.Provider,{value:{authState:c,dispatch:k}},t)};var d=function(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.")};p.defaultProps={cookieDomain:window.location.hostname,cookieSecure:"https:"===window.location.protocol},e.AuthProvider=p,e.PrivateRoute=function(e){var t=s.useContext(h);if(null===t)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");var r=e.component,n=e.loginPath,i=e.strict,a=e.sensitive,u=e.exact,l=e.path,f=e.location,c=e.render;return s.createElement(o.Route,{location:f,path:l,exact:u,sensitive:a,strict:i,render:function(e){return t.authState.authToken&&t.authState.expireAt&&(new Date(t.authState.expireAt)>new Date||(t.dispatch(T()),0))?r?s.createElement(r,e):c?c(e):null:s.createElement(o.Redirect,{to:n})}})},e.useAuthHeader=function(){var e=s.useContext(h);if(null===e)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return function(){return(null==e?void 0:e.authState)?e.authState.authTokenType+" "+e.authState.authToken:""}},e.useAuthUser=function(){var e=s.useContext(h);if(null===e)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return function(){return e.authState.authState}},e.useIsAuthenticated=function(){var e=s.useContext(h);if(null===e)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return function(){return!(!(null==e?void 0:e.authState.authToken)||!(null==e?void 0:e.authState.expireAt))&&(new Date(e.authState.expireAt)>new Date||(e.dispatch(T()),!1))}},e.useRefreshToken=function(){var e=s.useContext(h);if(null===e)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return new d(e)},e.useSignIn=
/*! react-auth-kit v1.4.18-0 | Apache-2.0 */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("js-cookie"),require("react-router-dom")):"function"==typeof define&&define.amd?define(["exports","react","js-cookie","react-router-dom"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactAuthKit={},e.React,e.Cookies,e.ReactRouterDOM)}(this,(function(e,t,r,o){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function i(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var a,s=i(t),u=n(r),h=s.createContext(null),f=h.Consumer,c=function(){return(c=Object.assign||function(e){for(var t,r=1,o=arguments.length;r<o;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e}).apply(this,arguments)},l=function(){function e(e,t,r,o,n){this.authStorageType=t,this.authStorageName=e,this.authTimeStorageName=e+"_storage",this.stateStorageName=e+"_state",this.refreshTokenName=r,this.cookieDomain=o,this.cookieSecure=n,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),r=u.default.get(this.authTimeStorageName),o=u.default.get(this.stateStorageName),n=this.isUsingRefreshToken&&null!=this.refreshTokenName?u.default.get(this.refreshTokenName):null,i=this.isUsingRefreshToken&&null!=this.refreshTokenTimeName?u.default.get(this.refreshTokenTimeName):null;return this.checkTokenExist(e,t,r,o,n,i)},e.prototype.initialLSToken_=function(){var e=localStorage.getItem(this.authStorageName),t=localStorage.getItem(this.authStorageTypeName),r=localStorage.getItem(this.authTimeStorageName),o=localStorage.getItem(this.stateStorageName),n=this.isUsingRefreshToken&&null!=this.refreshTokenName?localStorage.getItem(this.refreshTokenName):null,i=this.isUsingRefreshToken&&null!=this.refreshTokenTimeName?localStorage.getItem(this.refreshTokenTimeName):null;return this.checkTokenExist(e,t,r,o,n,i)},e.prototype.checkTokenExist=function(e,t,r,o,n,i){if(!(e&&t&&r&&o))return{auth:null,refresh:null,userState:null,isUsingRefreshToken:this.isUsingRefreshToken,isSignIn:!1};var a=new Date(r);try{var s={auth:{token:e,type:t,expiresAt:a},userState:JSON.parse(o),isSignIn:!0,isUsingRefreshToken:this.isUsingRefreshToken,refresh:void 0};if(this.isUsingRefreshToken&&n&&i){var u=new Date(i);return c(c({},s),{refresh:{token:n,expiresAt:u}})}return c(c({},s),{refresh:null})}catch(e){return{auth:null,refresh:null,userState:null,isUsingRefreshToken:this.isUsingRefreshToken,isSignIn:!1}}},e.prototype.syncTokens=function(e){e.auth?this.isUsingRefreshToken&&e.refresh?this.setToken(e.auth.token,e.auth.type,e.refresh.token,e.refresh.expiresAt,e.auth.expiresAt,e.userState):this.setToken(e.auth.token,e.auth.type,null,null,e.auth.expiresAt,e.userState):this.removeToken()},e.prototype.setToken=function(e,t,r,o,n,i){"cookie"===this.authStorageType?this.setCookieToken_(e,t,r,n,o,i):this.setLSToken_(e,t,r,n,o,i)},e.prototype.setCookieToken_=function(e,t,r,o,n,i){u.default.set(this.authStorageName,e,{expires:o,domain:this.cookieDomain,secure:this.cookieSecure}),u.default.set(this.authStorageTypeName,t,{expires:o,domain:this.cookieDomain,secure:this.cookieSecure}),u.default.set(this.authTimeStorageName,o.toISOString(),{expires:o,domain:this.cookieDomain,secure:this.cookieSecure}),i&&u.default.set(this.stateStorageName,JSON.stringify(i),{expires:o,domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenName&&r&&u.default.set(this.refreshTokenName,r,{expires:o,domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenTimeName&&n&&u.default.set(this.refreshTokenTimeName,n.toISOString(),{expires:o,domain:this.cookieDomain,secure:this.cookieSecure})},e.prototype.setLSToken_=function(e,t,r,o,n,i){localStorage.setItem(this.authStorageName,e),localStorage.setItem(this.authStorageTypeName,t),localStorage.setItem(this.authTimeStorageName,o.toISOString()),i&&localStorage.setItem(this.stateStorageName,JSON.stringify(i)),this.isUsingRefreshToken&&this.refreshTokenName&&r&&localStorage.setItem(this.refreshTokenName,r),this.isUsingRefreshToken&&this.refreshTokenTimeName&&n&&localStorage.setItem(this.refreshTokenTimeName,n.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.authStorageTypeName,{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.authStorageTypeName),localStorage.removeItem(this.stateStorageName),this.isUsingRefreshToken&&this.refreshTokenName&&localStorage.removeItem(this.refreshTokenName),this.isUsingRefreshToken&&this.refreshTokenTimeName&&localStorage.removeItem(this.refreshTokenTimeName)},e}();function m(e,t){switch(t.type){case a.SignIn:return c(c({},e),{auth:t.payload.auth,refresh:t.payload.refresh,userState:t.payload.userState,isSignIn:!0});case a.SignOut:return c(c({},e),{auth:null,refresh:null,userState:null,isSignIn:!1});default:return e}}function k(e){return{type:a.SignIn,payload:e}}function d(){return{type:a.SignOut}}!function(e){e[e.SignIn=0]="SignIn",e[e.SignOut=1]="SignOut"}(a||(a={}));var g=function(e){var t=e.children,r=e.authType,o=e.authName,n=e.refreshToken,i=e.cookieDomain,a=e.cookieSecure;if("cookie"===r&&!i)throw new Error("authType 'cookie' requires 'cookieDomain' and 'cookieSecure' props in AuthProvider");var u=new l(o,r,n?o+"_refresh":null,i,a),f=s.useReducer(m,u.initialToken()),c=f[0],k=f[1];return s.useEffect((function(){u.syncTokens(c)}),[c]),s.createElement(h.Provider,{value:{authState:c,dispatch:k}},t)};var S=function(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.")};g.defaultProps={cookieDomain:window.location.hostname,cookieSecure:"https:"===window.location.protocol},e.AuthProvider=g,e.PrivateRoute=function(e){var t=s.useContext(h);if(null===t)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");var r=e.component,n=e.loginPath,i=e.strict,a=e.sensitive,u=e.exact,f=e.path,c=e.location,l=e.render;return s.createElement(o.Route,{location:c,path:f,exact:u,sensitive:a,strict:i,render:function(e){return t.authState.auth&&(new Date(t.authState.auth.expiresAt)>new Date||(t.dispatch(d()),0))?r?s.createElement(r,e):l?l(e):null:s.createElement(o.Redirect,{to:n})}})},e.useAuthHeader=function(){var e=s.useContext(h);if(null===e)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return function(){return e.authState.auth?e.authState.auth.type+" "+e.authState.auth.token:""}},e.useAuthUser=function(){var e=s.useContext(h);if(null===e)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return function(){return e.authState.auth?e.authState.userState:null}},e.useIsAuthenticated=function(){var e=s.useContext(h);if(null===e)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return function(){return!!e.authState.auth&&(new Date(e.authState.auth.expiresAt)>new Date||(e.dispatch(d()),!1))}},e.useRefreshToken=function(){var e=s.useContext(h);if(null===e)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return new S(e)},e.useSignIn=
/**
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>
*@fileoverview Sign In functionality <hook>
*@copyright Arkadip Bhattacharya 2020
*@license Apache-2.0
*
* 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(){var e=s.useContext(h);if(null===e)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return function(t){var r=t.token,o=t.tokenType,n=t.authState,i=t.expiresIn,a=t.refreshToken,s=t.refreshTokenExpireIn,u=new Date((new Date).getTime()+60*i*1e3);if(e.authState.isUsingRefreshToken){if(a&&s){var h=new Date((new Date).getTime()+60*s*1e3);return e.dispatch(k({auth:{token:r,type:o,expiresAt:u},userState:n,refresh:{token:a,expiresAt:h}})),!0}throw new Error('Make sure you given "refreshToken" and "refreshTokenExpireIn" parameter')}if(a&&s)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.dispatch(k({auth:{token:r,type:o,expiresAt:u},userState:n,refresh:null})),!0}},e.useSignOut=function(){var e=s.useContext(h);if(null===e)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return function(){try{return!!e&&(e.dispatch(T()),!0)}catch(e){return!1}}},e.withAuthHeader=function(e){return function(t){return s.createElement(l,null,(function(r){if(null===r)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return(null==r?void 0:r.authState)?s.createElement(e,c({},t,{authHeader:r.authState.authTokenType+" "+r.authState.authToken})):s.createElement(e,c({},t,{authHeader:null}))}))}},e.withAuthUser=function(e){return function(t){return s.createElement(l,null,(function(r){if(null===r)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return s.createElement(e,c({},t,{authState:null==r?void 0:r.authState.authState}))}))}},e.withIsAuthenticated=function(e){return function(t){return s.createElement(l,null,(function(r){if(null===r)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return(null==r?void 0:r.authState.authToken)&&(null==r?void 0:r.authState.expireAt)?new Date(r.authState.expireAt)>new Date?s.createElement(e,c({},t,{isAuth:!0})):(r.dispatch(T()),s.createElement(e,c({},t,{isAuth:!1}))):s.createElement(e,c({},t,{isAuth:!1}))}))}},e.withRefreshToken=function(e){return function(t){return s.createElement(l,null,(function(r){if(null===r)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return s.createElement(e,c({},t,{refreshToken:new d(r)}))}))}},e.withSignIn=function(e){return function(t){return s.createElement(l,null,(function(r){if(null===r)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return s.createElement(e,c({},t,{signIn:function(e){var t=e.token,o=e.tokenType,n=e.authState,i=e.expiresIn,a=e.refreshToken,s=e.refreshTokenExpireIn,u=new Date((new Date).getTime()+60*i*1e3);if(r.authState.isUsingRefreshToken){if(a&&s){var h=new Date((new Date).getTime()+60*s*1e3);return r.dispatch(k({auth:{token:t,type:o,expiresAt:u},userState:n,refresh:{token:a,expiresAt:h}})),!0}throw new Error('Make sure you given "refreshToken" and "refreshTokenExpireIn" parameter')}if(a&&s)throw new Error("The app doesn't implement 'refreshToken' feature.\n So you have to implement refresh token feature from 'AuthProvider' before using it.");return r.dispatch(k({auth:{token:t,type:o,expiresAt:u},userState:n,refresh:null})),!0}}))}))}},e.withSignOut=function(e){return function(t){return s.createElement(l,null,(function(r){if(null===r)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return s.createElement(e,c({},t,{signOut:function(){try{return!!r&&(r.dispatch(T()),!0)}catch(e){return!1}}}))}))}},Object.defineProperty(e,"__esModule",{value:!0})}));
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>
*@fileoverview Sign In functionality <hook>
*@copyright Arkadip Bhattacharya 2020
*@license Apache-2.0
*
* 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(){var e=s.useContext(h);if(null===e)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return function(t){var r=t.token,o=t.tokenType,n=t.authState,i=t.expiresIn,a=t.refreshToken,s=t.refreshTokenExpireIn,u=new Date((new Date).getTime()+60*i*1e3);if(e.authState.isUsingRefreshToken){if(a&&s){var h=new Date((new Date).getTime()+60*s*1e3);return e.dispatch(k({auth:{token:r,type:o,expiresAt:u},userState:n,refresh:{token:a,expiresAt:h}})),!0}throw new Error('Make sure you given "refreshToken" and "refreshTokenExpireIn" parameter')}if(a&&s)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.dispatch(k({auth:{token:r,type:o,expiresAt:u},userState:n,refresh:null})),!0}},e.useSignOut=function(){var e=s.useContext(h);if(null===e)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return function(){try{return!!e&&(e.dispatch(d()),!0)}catch(e){return!1}}},e.withAuthHeader=function(e){return function(t){return s.createElement(f,null,(function(r){if(null===r)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return r.authState.auth?s.createElement(e,c({},t,{authHeader:r.authState.auth.type+" "+r.authState.auth.token})):s.createElement(e,c({},t,{authHeader:""}))}))}},e.withAuthUser=function(e){return function(t){return s.createElement(f,null,(function(r){if(null===r)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return r.authState.auth?s.createElement(e,c({},t,{authState:r.authState.userState})):s.createElement(e,c({},t,{authState:null}))}))}},e.withIsAuthenticated=function(e){return function(t){return s.createElement(f,null,(function(r){if(null===r)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return r.authState.auth?new Date(r.authState.auth.expiresAt)>new Date?s.createElement(e,c({},t,{isAuth:!0})):(r.dispatch(d()),s.createElement(e,c({},t,{isAuth:!1}))):s.createElement(e,c({},t,{isAuth:!1}))}))}},e.withRefreshToken=function(e){return function(t){return s.createElement(f,null,(function(r){if(null===r)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return s.createElement(e,c({},t,{refreshToken:new S(r)}))}))}},e.withSignIn=function(e){return function(t){return s.createElement(f,null,(function(r){if(null===r)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return s.createElement(e,c({},t,{signIn:function(e){var t=e.token,o=e.tokenType,n=e.authState,i=e.expiresIn,a=e.refreshToken,s=e.refreshTokenExpireIn,u=new Date((new Date).getTime()+60*i*1e3);if(r.authState.isUsingRefreshToken){if(a&&s){var h=new Date((new Date).getTime()+60*s*1e3);return r.dispatch(k({auth:{token:t,type:o,expiresAt:u},userState:n,refresh:{token:a,expiresAt:h}})),!0}throw new Error('Make sure you given "refreshToken" and "refreshTokenExpireIn" parameter')}if(a&&s)throw new Error("The app doesn't implement 'refreshToken' feature.\n So you have to implement refresh token feature from 'AuthProvider' before using it.");return r.dispatch(k({auth:{token:t,type:o,expiresAt:u},userState:n,refresh:null})),!0}}))}))}},e.withSignOut=function(e){return function(t){return s.createElement(f,null,(function(r){if(null===r)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return s.createElement(e,c({},t,{signOut:function(){try{return!!r&&(r.dispatch(d()),!0)}catch(e){return!1}}}))}))}},Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=index.umd.js.map

@@ -113,3 +113,3 @@ import { AuthKitStateInterface, AuthStateUserObject } from './types';

*/
setToken(authToken: string, authTokenType: string, refreshToken: string | null, refreshTokenExpiresAt: Date | null, expiresAt: Date, authState: AuthStateUserObject): void;
setToken(authToken: string, authTokenType: string, refreshToken: string | null, refreshTokenExpiresAt: Date | null, expiresAt: Date, authState: AuthStateUserObject | null): void;
/**

@@ -126,3 +126,3 @@ *

*/
setCookieToken_(authToken: string, authTokenType: string, refreshToken: string | null, expiresAt: Date, refreshTokenExpiresAt: Date | null, authState: AuthStateUserObject): void;
setCookieToken_(authToken: string, authTokenType: string, refreshToken: string | null, expiresAt: Date, refreshTokenExpiresAt: Date | null, authState: AuthStateUserObject | null): void;
/**

@@ -138,3 +138,3 @@ * Set LocalStorage at the time of Login

*/
setLSToken_(authToken: string, authTokenType: string, refreshToken: string | null, expiresAt: Date, refreshTokenExpiresAt: Date | null, authState: AuthStateUserObject): void;
setLSToken_(authToken: string, authTokenType: string, refreshToken: string | null, expiresAt: Date, refreshTokenExpiresAt: Date | null, authState: AuthStateUserObject | null): void;
/**

@@ -141,0 +141,0 @@ * Remove Tokens on time of Logout

@@ -23,10 +23,14 @@ /**

export interface AuthKitStateInterface {
authToken: string | null;
authTokenType: string | null;
expireAt: Date | null;
auth: {
token: string;
type: string;
expiresAt: Date;
} | null;
refresh: {
token: string;
expiresAt: Date;
} | null;
userState: AuthStateUserObject | null;
isSignIn: boolean;
isUsingRefreshToken: boolean;
refreshToken: string | null;
refreshTokenExpireAt: Date | null;
authState: AuthStateUserObject | null;
isSignIn: boolean;
}

@@ -33,0 +37,0 @@ export interface signInFunctionParams {

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

@@ -22,3 +22,3 @@ "source": "src/index.tsx",

"build:build": "rollup -c",
"prepare": "run-s build",
"prepare": "run-s build && husky install",
"preversion": "run-s test",

@@ -30,4 +30,3 @@ "test": "run-s test:*",

"test:unit:watch": "jest --watch",
"fix": "eslint src/**/*.ts src/**/*.tsx --fix",
"release": "release-it"
"fix": "eslint src/**/*.ts src/**/*.tsx --fix"
},

@@ -53,3 +52,4 @@ "keywords": [

"devDependencies": {
"@release-it/keep-a-changelog": "^2.3.0",
"@commitlint/cli": "^13.1.0",
"@commitlint/config-conventional": "^13.1.0",
"@rollup/plugin-node-resolve": "^13.0.4",

@@ -59,3 +59,3 @@ "@testing-library/react": "^12.0.0",

"@types/js-cookie": "^2.2.7",
"@types/node": "^16.7.1",
"@types/node": "^16.7.3",
"@types/react": "^17.0.19",

@@ -70,8 +70,9 @@ "@types/react-dom": "^17.0.9",

"eslint-plugin-jest": "^24.4.0",
"eslint-plugin-react": "^7.20.6",
"jest": "^27.0.6",
"eslint-plugin-react": "^7.25.1",
"husky": "^7.0.0",
"jest": "^27.1.0",
"lint-staged": "^11.1.2",
"mkdirp": "^1.0.4",
"npm-run-all": "^4.1.5",
"react-dom": "^17.0.1",
"release-it": "^14.11.5",
"rimraf": "^3.0.2",

@@ -86,3 +87,3 @@ "rollup": "^2.56.3",

"tslib": "^2.3.1",
"typedoc": "^0.21.6",
"typedoc": "^0.21.7",
"typescript": "^4.3.5",

@@ -101,3 +102,6 @@ "utility-types": "^3.10.0"

"react-router-dom": "^5.2.0"
},
"lint-staged": {
"src/**/*.{ts,tsx,json,js}": "eslint --cache --fix"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc