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.6.2 to 1.6.3-beta.1

29

dist/index.js

@@ -109,11 +109,11 @@ 'use strict';

this.authStorageName = authStorageName;
this.authTimeStorageName = authStorageName + "_storage";
this.stateStorageName = authStorageName + "_state";
this.authTimeStorageName = "".concat(authStorageName, "_storage");
this.stateStorageName = "".concat(authStorageName, "_state");
this.refreshTokenName = refreshTokenName;
this.cookieDomain = cookieDomain;
this.cookieSecure = cookieSecure;
this.authStorageTypeName = this.authStorageName + "_type";
this.authStorageTypeName = "".concat(this.authStorageName, "_type");
this.isUsingRefreshToken = !!this.refreshTokenName;
this.refreshTokenTimeName = this.refreshTokenName ?
this.refreshTokenName + "_time" : null;
"".concat(this.refreshTokenName, "_time") : null;
}

@@ -587,3 +587,3 @@ /**

}
var refreshTokenName = refresh ? authName + "_refresh" : null;
var refreshTokenName = refresh ? "".concat(authName, "_refresh") : null;
var tokenObject = new TokenObject(authName, authType, refreshTokenName, cookieDomain, cookieSecure);

@@ -594,3 +594,4 @@ var _b = React__namespace.useReducer(authReducer, tokenObject.initialToken()), authState = _b[0], dispatch = _b[1];

var _a, _b, _c, _d;
var r = refresh.refreshApiCallback({
refresh
.refreshApiCallback({
authToken: (_a = authState.auth) === null || _a === void 0 ? void 0 : _a.token,

@@ -601,8 +602,10 @@ authTokenExpireAt: (_b = authState.auth) === null || _b === void 0 ? void 0 : _b.expiresAt,

refreshTokenExpiresAt: (_d = authState.refresh) === null || _d === void 0 ? void 0 : _d.expiresAt,
})
.then(function (result) {
// IF the API call is successful then refresh the AUTH state
if (result.isSuccess) {
// store the new value using the state update
dispatch(doRefresh(result));
}
});
// store the new value using the state update
if (r.isSuccess) {
// IF the API call is successful then refresh the AUTH state
dispatch(doRefresh(r));
}
}, authState.isSignIn ? refresh.interval : null);

@@ -905,3 +908,3 @@ }

if (c.authState.auth) {
return c.authState.auth.type + " " + c.authState.auth.token;
return "".concat(c.authState.auth.type, " ").concat(c.authState.auth.token);
}

@@ -1124,3 +1127,3 @@ else {

if (c.authState.auth) {
return (React__namespace.createElement(Component, __assign({}, props, { authHeader: c.authState.auth.type + " " + c.authState.auth.token })));
return (React__namespace.createElement(Component, __assign({}, props, { authHeader: "".concat(c.authState.auth.type, " ").concat(c.authState.auth.token) })));
}

@@ -1127,0 +1130,0 @@ else {

@@ -82,11 +82,11 @@ import * as React from 'react';

this.authStorageName = authStorageName;
this.authTimeStorageName = authStorageName + "_storage";
this.stateStorageName = authStorageName + "_state";
this.authTimeStorageName = "".concat(authStorageName, "_storage");
this.stateStorageName = "".concat(authStorageName, "_state");
this.refreshTokenName = refreshTokenName;
this.cookieDomain = cookieDomain;
this.cookieSecure = cookieSecure;
this.authStorageTypeName = this.authStorageName + "_type";
this.authStorageTypeName = "".concat(this.authStorageName, "_type");
this.isUsingRefreshToken = !!this.refreshTokenName;
this.refreshTokenTimeName = this.refreshTokenName ?
this.refreshTokenName + "_time" : null;
"".concat(this.refreshTokenName, "_time") : null;
}

@@ -560,3 +560,3 @@ /**

}
var refreshTokenName = refresh ? authName + "_refresh" : null;
var refreshTokenName = refresh ? "".concat(authName, "_refresh") : null;
var tokenObject = new TokenObject(authName, authType, refreshTokenName, cookieDomain, cookieSecure);

@@ -567,3 +567,4 @@ var _b = React.useReducer(authReducer, tokenObject.initialToken()), authState = _b[0], dispatch = _b[1];

var _a, _b, _c, _d;
var r = refresh.refreshApiCallback({
refresh
.refreshApiCallback({
authToken: (_a = authState.auth) === null || _a === void 0 ? void 0 : _a.token,

@@ -574,8 +575,10 @@ authTokenExpireAt: (_b = authState.auth) === null || _b === void 0 ? void 0 : _b.expiresAt,

refreshTokenExpiresAt: (_d = authState.refresh) === null || _d === void 0 ? void 0 : _d.expiresAt,
})
.then(function (result) {
// IF the API call is successful then refresh the AUTH state
if (result.isSuccess) {
// store the new value using the state update
dispatch(doRefresh(result));
}
});
// store the new value using the state update
if (r.isSuccess) {
// IF the API call is successful then refresh the AUTH state
dispatch(doRefresh(r));
}
}, authState.isSignIn ? refresh.interval : null);

@@ -878,3 +881,3 @@ }

if (c.authState.auth) {
return c.authState.auth.type + " " + c.authState.auth.token;
return "".concat(c.authState.auth.type, " ").concat(c.authState.auth.token);
}

@@ -1097,3 +1100,3 @@ else {

if (c.authState.auth) {
return (React.createElement(Component, __assign({}, props, { authHeader: c.authState.auth.type + " " + c.authState.auth.token })));
return (React.createElement(Component, __assign({}, props, { authHeader: "".concat(c.authState.auth.type, " ").concat(c.authState.auth.token) })));
}

@@ -1100,0 +1103,0 @@ else {

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

/*! react-auth-kit v1.6.2 | Apache-2.0 */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("js-cookie"),require("react-router-dom")):"function"==typeof define&&define.amd?define(["exports","react","js-cookie","react-router-dom"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactAuthKit={},e.React,e.Cookies,e.ReactRouterDOM)}(this,(function(e,t,r,n){"use strict";function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function i(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var a,s=i(t),u=o(r),h=s.createContext(null),f=h.Consumer,c=function(){return(c=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},l=function(){function e(e,t,r,n,o){this.authStorageType=t,this.authStorageName=e,this.authTimeStorageName=e+"_storage",this.stateStorageName=e+"_state",this.refreshTokenName=r,this.cookieDomain=n,this.cookieSecure=o,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),n=u.default.get(this.stateStorageName),o=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,n,o,i)},e.prototype.initialLSToken_=function(){var e=localStorage.getItem(this.authStorageName),t=localStorage.getItem(this.authStorageTypeName),r=localStorage.getItem(this.authTimeStorageName),n=localStorage.getItem(this.stateStorageName),o=this.isUsingRefreshToken&&null!=this.refreshTokenName?localStorage.getItem(this.refreshTokenName):null,i=this.isUsingRefreshToken&&null!=this.refreshTokenTimeName?localStorage.getItem(this.refreshTokenTimeName):null;return this.checkTokenExist(e,t,r,n,o,i)},e.prototype.checkTokenExist=function(e,t,r,n,o,i){if(!(e&&t&&r&&n))return{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(n),isSignIn:!0,isUsingRefreshToken:this.isUsingRefreshToken,refresh:void 0};if(this.isUsingRefreshToken&&o&&i){var u=new Date(i);return c(c({},s),{refresh:{token:o,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,n,o,i){"cookie"===this.authStorageType?this.setCookieToken_(e,t,r,o,n,i):this.setLSToken_(e,t,r,o,n,i)},e.prototype.setCookieToken_=function(e,t,r,n,o,i){u.default.set(this.authStorageName,e,{expires:n,domain:this.cookieDomain,secure:this.cookieSecure}),u.default.set(this.authStorageTypeName,t,{expires:n,domain:this.cookieDomain,secure:this.cookieSecure}),u.default.set(this.authTimeStorageName,n.toISOString(),{expires:n,domain:this.cookieDomain,secure:this.cookieSecure}),i&&u.default.set(this.stateStorageName,JSON.stringify(i),{expires:n,domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenName&&r&&u.default.set(this.refreshTokenName,r,{expires:n,domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenTimeName&&o&&u.default.set(this.refreshTokenTimeName,o.toISOString(),{expires:n,domain:this.cookieDomain,secure:this.cookieSecure})},e.prototype.setLSToken_=function(e,t,r,n,o,i){localStorage.setItem(this.authStorageName,e),localStorage.setItem(this.authStorageTypeName,t),localStorage.setItem(this.authTimeStorageName,n.toISOString()),i&&localStorage.setItem(this.stateStorageName,JSON.stringify(i)),this.isUsingRefreshToken&&this.refreshTokenName&&r&&localStorage.setItem(this.refreshTokenName,r),this.isUsingRefreshToken&&this.refreshTokenTimeName&&o&&localStorage.setItem(this.refreshTokenTimeName,o.toISOString())},e.prototype.removeToken=function(){"cookie"===this.authStorageType?this.removeCookieToken_():this.removeLSToken_()},e.prototype.removeCookieToken_=function(){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});case a.RefreshToken:return e.isSignIn&&e.auth&&e.refresh?c(c({},e),{auth:{token:t.payload.newAuthToken?t.payload.newAuthToken:e.auth.token,type:e.auth.type,expiresAt:t.payload.newAuthTokenExpireIn?new Date((new Date).getTime()+60*t.payload.newAuthTokenExpireIn*1e3):e.auth.expiresAt},refresh:{token:t.payload.newRefreshToken?t.payload.newRefreshToken:e.refresh.token,expiresAt:t.payload.newRefreshTokenExpiresIn?new Date((new Date).getTime()+60*t.payload.newRefreshTokenExpiresIn*1e3):e.refresh.expiresAt},userState:t.payload.newAuthUserState?t.payload.newAuthUserState:e.userState}):e}}function k(e){return{type:a.SignIn,payload:e}}function p(){return{type:a.SignOut}}!function(e){e[e.SignIn=0]="SignIn",e[e.SignOut=1]="SignOut",e[e.RefreshToken=2]="RefreshToken"}(a||(a={}));var d=function(e){var t=e.children,r=e.authType,n=e.authName,o=e.cookieDomain,i=e.cookieSecure,u=e.refresh;if("cookie"===r&&!o)throw new Error("authType 'cookie' requires 'cookieDomain' and 'cookieSecure' props in AuthProvider");var f,c,k,p,d=new l(n,r,u?n+"_refresh":null,o,i),S=s.useReducer(m,d.initialToken()),T=S[0],g=S[1];return u&&(f=function(){var e,t,r,n,o,i=u.refreshApiCallback({authToken:null===(e=T.auth)||void 0===e?void 0:e.token,authTokenExpireAt:null===(t=T.auth)||void 0===t?void 0:t.expiresAt,authUserState:T.userState,refreshToken:null===(r=T.refresh)||void 0===r?void 0:r.token,refreshTokenExpiresAt:null===(n=T.refresh)||void 0===n?void 0:n.expiresAt});i.isSuccess&&g((o=i,{type:a.RefreshToken,payload:o}))},c=T.isSignIn?u.interval:null,k=s.useRef(f),p=s.useRef(null),s.useEffect((function(){k.current=f}),[f]),s.useEffect((function(){return"number"==typeof c&&(p.current=window.setInterval((function(){return k.current()}),60*c*1e3)),function(){p.current&&window.clearTimeout(p.current)}}),[c])),s.useEffect((function(){d.syncTokens(T)}),[T]),s.createElement(h.Provider,{value:{authState:T,dispatch:g}},t)};d.defaultProps={cookieDomain:window.location.hostname,cookieSecure:"https:"===window.location.protocol},e.AuthProvider=d,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,o=e.loginPath,i=e.strict,a=e.sensitive,u=e.exact,f=e.path,c=e.location,l=e.render;return s.createElement(n.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(p()),0))?r?s.createElement(r,e):l?l(e):null:s.createElement(n.Redirect,{to:o})}})},e.createRefresh=function(e){return e},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(p()),!1))}},e.useSignIn=
/*! react-auth-kit v1.6.3-beta.1 | Apache-2.0 */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("js-cookie"),require("react-router-dom")):"function"==typeof define&&define.amd?define(["exports","react","js-cookie","react-router-dom"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactAuthKit={},e.React,e.Cookies,e.ReactRouterDOM)}(this,(function(e,t,r,n){"use strict";function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function i(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var a,s=i(t),u=o(r),h=s.createContext(null),c=h.Consumer,f=function(){return(f=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},l=function(){function e(e,t,r,n,o){this.authStorageType=t,this.authStorageName=e,this.authTimeStorageName="".concat(e,"_storage"),this.stateStorageName="".concat(e,"_state"),this.refreshTokenName=r,this.cookieDomain=n,this.cookieSecure=o,this.authStorageTypeName="".concat(this.authStorageName,"_type"),this.isUsingRefreshToken=!!this.refreshTokenName,this.refreshTokenTimeName=this.refreshTokenName?"".concat(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),n=u.default.get(this.stateStorageName),o=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,n,o,i)},e.prototype.initialLSToken_=function(){var e=localStorage.getItem(this.authStorageName),t=localStorage.getItem(this.authStorageTypeName),r=localStorage.getItem(this.authTimeStorageName),n=localStorage.getItem(this.stateStorageName),o=this.isUsingRefreshToken&&null!=this.refreshTokenName?localStorage.getItem(this.refreshTokenName):null,i=this.isUsingRefreshToken&&null!=this.refreshTokenTimeName?localStorage.getItem(this.refreshTokenTimeName):null;return this.checkTokenExist(e,t,r,n,o,i)},e.prototype.checkTokenExist=function(e,t,r,n,o,i){if(!(e&&t&&r&&n))return{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(n),isSignIn:!0,isUsingRefreshToken:this.isUsingRefreshToken,refresh:void 0};if(this.isUsingRefreshToken&&o&&i){var u=new Date(i);return f(f({},s),{refresh:{token:o,expiresAt:u}})}return f(f({},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,n,o,i){"cookie"===this.authStorageType?this.setCookieToken_(e,t,r,o,n,i):this.setLSToken_(e,t,r,o,n,i)},e.prototype.setCookieToken_=function(e,t,r,n,o,i){u.default.set(this.authStorageName,e,{expires:n,domain:this.cookieDomain,secure:this.cookieSecure}),u.default.set(this.authStorageTypeName,t,{expires:n,domain:this.cookieDomain,secure:this.cookieSecure}),u.default.set(this.authTimeStorageName,n.toISOString(),{expires:n,domain:this.cookieDomain,secure:this.cookieSecure}),i&&u.default.set(this.stateStorageName,JSON.stringify(i),{expires:n,domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenName&&r&&u.default.set(this.refreshTokenName,r,{expires:n,domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenTimeName&&o&&u.default.set(this.refreshTokenTimeName,o.toISOString(),{expires:n,domain:this.cookieDomain,secure:this.cookieSecure})},e.prototype.setLSToken_=function(e,t,r,n,o,i){localStorage.setItem(this.authStorageName,e),localStorage.setItem(this.authStorageTypeName,t),localStorage.setItem(this.authTimeStorageName,n.toISOString()),i&&localStorage.setItem(this.stateStorageName,JSON.stringify(i)),this.isUsingRefreshToken&&this.refreshTokenName&&r&&localStorage.setItem(this.refreshTokenName,r),this.isUsingRefreshToken&&this.refreshTokenTimeName&&o&&localStorage.setItem(this.refreshTokenTimeName,o.toISOString())},e.prototype.removeToken=function(){"cookie"===this.authStorageType?this.removeCookieToken_():this.removeLSToken_()},e.prototype.removeCookieToken_=function(){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 f(f({},e),{auth:t.payload.auth,refresh:t.payload.refresh,userState:t.payload.userState,isSignIn:!0});case a.SignOut:return f(f({},e),{auth:null,refresh:null,userState:null,isSignIn:!1});case a.RefreshToken:return e.isSignIn&&e.auth&&e.refresh?f(f({},e),{auth:{token:t.payload.newAuthToken?t.payload.newAuthToken:e.auth.token,type:e.auth.type,expiresAt:t.payload.newAuthTokenExpireIn?new Date((new Date).getTime()+60*t.payload.newAuthTokenExpireIn*1e3):e.auth.expiresAt},refresh:{token:t.payload.newRefreshToken?t.payload.newRefreshToken:e.refresh.token,expiresAt:t.payload.newRefreshTokenExpiresIn?new Date((new Date).getTime()+60*t.payload.newRefreshTokenExpiresIn*1e3):e.refresh.expiresAt},userState:t.payload.newAuthUserState?t.payload.newAuthUserState:e.userState}):e}}function k(e){return{type:a.SignIn,payload:e}}function p(){return{type:a.SignOut}}!function(e){e[e.SignIn=0]="SignIn",e[e.SignOut=1]="SignOut",e[e.RefreshToken=2]="RefreshToken"}(a||(a={}));var d=function(e){var t=e.children,r=e.authType,n=e.authName,o=e.cookieDomain,i=e.cookieSecure,u=e.refresh;if("cookie"===r&&!o)throw new Error("authType 'cookie' requires 'cookieDomain' and 'cookieSecure' props in AuthProvider");var c,f,k,p,d=u?"".concat(n,"_refresh"):null,S=new l(n,r,d,o,i),T=s.useReducer(m,S.initialToken()),g=T[0],v=T[1];return u&&(c=function(){var e,t,r,n;u.refreshApiCallback({authToken:null===(e=g.auth)||void 0===e?void 0:e.token,authTokenExpireAt:null===(t=g.auth)||void 0===t?void 0:t.expiresAt,authUserState:g.userState,refreshToken:null===(r=g.refresh)||void 0===r?void 0:r.token,refreshTokenExpiresAt:null===(n=g.refresh)||void 0===n?void 0:n.expiresAt}).then((function(e){var t;e.isSuccess&&v((t=e,{type:a.RefreshToken,payload:t}))}))},f=g.isSignIn?u.interval:null,k=s.useRef(c),p=s.useRef(null),s.useEffect((function(){k.current=c}),[c]),s.useEffect((function(){return"number"==typeof f&&(p.current=window.setInterval((function(){return k.current()}),60*f*1e3)),function(){p.current&&window.clearTimeout(p.current)}}),[f])),s.useEffect((function(){S.syncTokens(g)}),[g]),s.createElement(h.Provider,{value:{authState:g,dispatch:v}},t)};d.defaultProps={cookieDomain:window.location.hostname,cookieSecure:"https:"===window.location.protocol},e.AuthProvider=d,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,o=e.loginPath,i=e.strict,a=e.sensitive,u=e.exact,c=e.path,f=e.location,l=e.render;return s.createElement(n.Route,{location:f,path:c,exact:u,sensitive:a,strict:i,render:function(e){return t.authState.auth&&(new Date(t.authState.auth.expiresAt)>new Date||(t.dispatch(p()),0))?r?s.createElement(r,e):l?l(e):null:s.createElement(n.Redirect,{to:o})}})},e.createRefresh=function(e){return e},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?"".concat(e.authState.auth.type," ").concat(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(p()),!1))}},e.useSignIn=
/**

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

*/
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,n=t.tokenType,o=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:n,expiresAt:u},userState:o,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:n,expiresAt:u},userState:o,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(p()),!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(p()),s.createElement(e,c({},t,{isAuth:!1}))):s.createElement(e,c({},t,{isAuth:!1}))}))}},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,n=e.tokenType,o=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:n,expiresAt:u},userState:o,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:n,expiresAt:u},userState:o,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(p()),!0)}catch(e){return!1}}}))}))}},Object.defineProperty(e,"__esModule",{value:!0})}));
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,n=t.tokenType,o=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:n,expiresAt:u},userState:o,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:n,expiresAt:u},userState:o,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(p()),!0)}catch(e){return!1}}},e.withAuthHeader=function(e){return function(t){return s.createElement(c,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,f({},t,{authHeader:"".concat(r.authState.auth.type," ").concat(r.authState.auth.token)})):s.createElement(e,f({},t,{authHeader:""}))}))}},e.withAuthUser=function(e){return function(t){return s.createElement(c,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,f({},t,{authState:r.authState.userState})):s.createElement(e,f({},t,{authState:null}))}))}},e.withIsAuthenticated=function(e){return function(t){return s.createElement(c,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,f({},t,{isAuth:!0})):(r.dispatch(p()),s.createElement(e,f({},t,{isAuth:!1}))):s.createElement(e,f({},t,{isAuth:!1}))}))}},e.withSignIn=function(e){return function(t){return s.createElement(c,null,(function(r){if(null===r)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return s.createElement(e,f({},t,{signIn:function(e){var t=e.token,n=e.tokenType,o=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:n,expiresAt:u},userState:o,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:n,expiresAt:u},userState:o,refresh:null})),!0}}))}))}},e.withSignOut=function(e){return function(t){return s.createElement(c,null,(function(r){if(null===r)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return s.createElement(e,f({},t,{signOut:function(){try{return!!r&&(r.dispatch(p()),!0)}catch(e){return!1}}}))}))}},Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=index.umd.js.map

@@ -73,2 +73,13 @@ /**

/**
* Refresh Token Callback Response
*/
export declare type RefreshTokenCallbackResponse = {
isSuccess: boolean;
newAuthToken: string;
newAuthTokenExpireIn?: number | null;
newRefreshToken?: string | null;
newRefreshTokenExpiresIn?: number | null;
newAuthUserState?: AuthStateUserObject | null;
};
/**
* Refresh Token types

@@ -82,10 +93,3 @@ */

authUserState: AuthStateUserObject | null;
}) => {
isSuccess: boolean;
newAuthToken: string;
newAuthTokenExpireIn?: number | null;
newRefreshToken?: string | null;
newRefreshTokenExpiresIn?: number | null;
newAuthUserState?: AuthStateUserObject | null;
};
}) => Promise<RefreshTokenCallbackResponse>;
export interface createRefreshParamInterface {

@@ -92,0 +96,0 @@ interval: number;

{
"name": "react-auth-kit",
"version": "1.6.2",
"version": "1.6.3-beta.1",
"description": "Authentication Library for React, which makes Token based auth very easy",

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

"devDependencies": {
"@commitlint/cli": "^14.1.0",
"@commitlint/config-conventional": "^14.1.0",
"@commitlint/cli": "^15.0.0",
"@commitlint/config-conventional": "^15.0.0",
"@rollup/plugin-node-resolve": "^13.0.6",

@@ -57,18 +57,18 @@ "@semantic-release/changelog": "^6.0.1",

"@testing-library/react-hooks": "^7.0.2",
"@types/jest": "^27.0.2",
"@types/js-cookie": "^3.0.0",
"@types/node": "^16.11.7",
"@types/react": "^17.0.34",
"@types/jest": "^27.0.3",
"@types/js-cookie": "^3.0.1",
"@types/node": "^16.11.10",
"@types/react": "^17.0.37",
"@types/react-dom": "^17.0.11",
"@types/react-router-dom": "^5.3.2",
"@typescript-eslint/eslint-plugin": "^5.3.1",
"@typescript-eslint/parser": "^5.3.1",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
"codecov": "^3.8.3",
"eslint": "^8.2.0",
"eslint": "^8.3.0",
"eslint-config-google": "^0.14.0",
"eslint-plugin-jest": "^25.2.4",
"eslint-plugin-react": "^7.27.0",
"eslint-plugin-jest": "^25.3.0",
"eslint-plugin-react": "^7.27.1",
"husky": "^7.0.4",
"jest": "^27.3.1",
"lint-staged": "^11.2.6",
"jest": "^27.4.0",
"lint-staged": "^12.1.2",
"mkdirp": "^1.0.4",

@@ -78,3 +78,3 @@ "npm-run-all": "^4.1.5",

"rimraf": "^3.0.2",
"rollup": "^2.59.0",
"rollup": "^2.60.1",
"rollup-plugin-filesize": "^9.0.2",

@@ -84,7 +84,7 @@ "rollup-plugin-license": "^2.6.0",

"rollup-plugin-terser": "^7.0.0",
"rollup-plugin-typescript2": "^0.30.0",
"rollup-plugin-typescript2": "^0.31.1",
"ts-jest": "^27.0.7",
"tslib": "^2.3.1",
"typedoc": "^0.22.8",
"typescript": "^4.4.4",
"typedoc": "^0.22.10",
"typescript": "^4.5.2",
"utility-types": "^3.10.0"

@@ -91,0 +91,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc