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.3.4 to 1.4.0

dist/higherOrderComponents/withRefreshToken.d.ts

4

CHANGELOG.md

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

## [1.4.0] - 2020-12-20
### Added:
- Added Refresh Token feature
## [1.3.4] - 2020-12-18

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

4

dist/index.d.ts

@@ -8,2 +8,3 @@ import AuthProvider from './AuthProvider';

import useAuthHeader from './hooks/useAuthHeader';
import useRefreshToken from './hooks/useRefreshToken';
import useIsAuthenticated from './hooks/useIsAuthenticated';

@@ -14,3 +15,4 @@ import withSignIn from './higherOrderComponents/withSignIn';

import withAuthHeader from './higherOrderComponents/withAuthHeader';
import withRefreshToken from './higherOrderComponents/withRefreshToken';
import withIsAuthenticated from './higherOrderComponents/withIsAuthenticated';
export { AuthProvider, PrivateRoute, useAuth, useSignIn, useSignOut, useAuthUser, useAuthHeader, useIsAuthenticated, withSignIn, withSignOut, withAuthUser, withAuthHeader, withIsAuthenticated, };
export { AuthProvider, PrivateRoute, useAuth, useSignIn, useSignOut, useAuthUser, useAuthHeader, useRefreshToken, useIsAuthenticated, withSignIn, withSignOut, withAuthUser, withAuthHeader, withRefreshToken, withIsAuthenticated, };

@@ -565,3 +565,110 @@ 'use strict';

/*
* Copyright 2020 Arkadip Bhattacharya
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @class RefreshToken
*
* Refreshes Token
*/
var RefreshToken = /** @class */ (function () {
/**
* @param context
* @constructor
*/
function RefreshToken(context) {
this.context = context;
}
/**
* Get the Current Auth State
* @returns a object with
* authState: The Auth Token,
* authTokenType: type of auth token,
* expireAt: expire time
*/
RefreshToken.prototype.getCurrentAuthState = function () {
return {
authToken: this.context.authState.authTokenType,
authTokenType: this.context.authState.authToken,
expireAt: this.context.authState.expireAt,
};
};
/**
* Get the Current User State
* @returns User State {object}
*/
RefreshToken.prototype.getCurrentUserState = function () {
return this.context.authState.authState;
};
/**
* updates the AuthState
* @param authToken - The Updated authToken
* @param authTokenType - The updated authType (optional)
* @param expiresIn - The updated expiresIn in minutes. (optional)
*
* If the new authToken has different expire time,
* then you must have to update the expiresIn param
*/
RefreshToken.prototype.updateAuthState = function (authToken, authTokenType, expiresIn) {
var o = { authToken: authToken };
if (authTokenType !== undefined) {
Object.assign(o, { authTokenType: authTokenType });
}
if (expiresIn !== undefined) {
var expireAt = new Date(new Date().getTime() + expiresIn * 60 * 1000);
Object.assign(o, { expireAt: expireAt });
}
this.context.setAuthState(function (prevState) { return (__assign(__assign({}, prevState), o)); });
};
/**
* Updates the Auth User's state
* @param userState
*/
RefreshToken.prototype.updateUserState = function (userState) {
this.context.setAuthState(function (prevState) {
return (__assign(__assign({}, prevState), { authState: userState }));
});
};
return RefreshToken;
}());
/*
* Copyright 2020 Arkadip Bhattacharya
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
*@function
*@name useRefreshToken
*@description Refresh Token Hook
*@returns - RefreshToken object
*/
function useRefreshToken() {
var _context = React.useContext(AuthContext);
return new RefreshToken(_context);
}
/**
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

@@ -700,2 +807,23 @@ *@fileoverview Check User is authenticated or not

/**
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>
*@fileoverview Authentication header
*@copyright Arkadip Bhattacharya 2020
*@license Apache-2.0
*/
/**
* @public
* @function
* @name withAuthHeader
* @description Inject Authentication Header inside the Component's Prop
* @param Component - React Component
*/
function withRefreshToken(Component) {
return function (props) {
return (React.createElement(AuthContextConsumer, null, function (c) {
return (React.createElement(Component, __assign({}, props, { refreshToken: new RefreshToken(c) })));
}));
};
}
/**
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

@@ -743,2 +871,3 @@ *@fileoverview Authentication status

exports.useIsAuthenticated = useIsAuthenticated;
exports.useRefreshToken = useRefreshToken;
exports.useSignIn = useSignIn;

@@ -749,3 +878,4 @@ exports.useSignOut = useSignOut;

exports.withIsAuthenticated = withIsAuthenticated;
exports.withRefreshToken = withRefreshToken;
exports.withSignIn = withSignIn;
exports.withSignOut = withSignOut;

@@ -557,3 +557,110 @@ import { createContext, useState, useEffect, createElement, useContext } from 'react';

/*
* Copyright 2020 Arkadip Bhattacharya
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @class RefreshToken
*
* Refreshes Token
*/
var RefreshToken = /** @class */ (function () {
/**
* @param context
* @constructor
*/
function RefreshToken(context) {
this.context = context;
}
/**
* Get the Current Auth State
* @returns a object with
* authState: The Auth Token,
* authTokenType: type of auth token,
* expireAt: expire time
*/
RefreshToken.prototype.getCurrentAuthState = function () {
return {
authToken: this.context.authState.authTokenType,
authTokenType: this.context.authState.authToken,
expireAt: this.context.authState.expireAt,
};
};
/**
* Get the Current User State
* @returns User State {object}
*/
RefreshToken.prototype.getCurrentUserState = function () {
return this.context.authState.authState;
};
/**
* updates the AuthState
* @param authToken - The Updated authToken
* @param authTokenType - The updated authType (optional)
* @param expiresIn - The updated expiresIn in minutes. (optional)
*
* If the new authToken has different expire time,
* then you must have to update the expiresIn param
*/
RefreshToken.prototype.updateAuthState = function (authToken, authTokenType, expiresIn) {
var o = { authToken: authToken };
if (authTokenType !== undefined) {
Object.assign(o, { authTokenType: authTokenType });
}
if (expiresIn !== undefined) {
var expireAt = new Date(new Date().getTime() + expiresIn * 60 * 1000);
Object.assign(o, { expireAt: expireAt });
}
this.context.setAuthState(function (prevState) { return (__assign(__assign({}, prevState), o)); });
};
/**
* Updates the Auth User's state
* @param userState
*/
RefreshToken.prototype.updateUserState = function (userState) {
this.context.setAuthState(function (prevState) {
return (__assign(__assign({}, prevState), { authState: userState }));
});
};
return RefreshToken;
}());
/*
* Copyright 2020 Arkadip Bhattacharya
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
*@function
*@name useRefreshToken
*@description Refresh Token Hook
*@returns - RefreshToken object
*/
function useRefreshToken() {
var _context = useContext(AuthContext);
return new RefreshToken(_context);
}
/**
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

@@ -692,2 +799,23 @@ *@fileoverview Check User is authenticated or not

/**
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>
*@fileoverview Authentication header
*@copyright Arkadip Bhattacharya 2020
*@license Apache-2.0
*/
/**
* @public
* @function
* @name withAuthHeader
* @description Inject Authentication Header inside the Component's Prop
* @param Component - React Component
*/
function withRefreshToken(Component) {
return function (props) {
return (createElement(AuthContextConsumer, null, function (c) {
return (createElement(Component, __assign({}, props, { refreshToken: new RefreshToken(c) })));
}));
};
}
/**
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

@@ -729,2 +857,2 @@ *@fileoverview Authentication status

export { AuthProvider, PrivateRoute, useAuth, useAuthHeader, useAuthUser, useIsAuthenticated, useSignIn, useSignOut, withAuthHeader, withAuthUser, withIsAuthenticated, withSignIn, withSignOut };
export { AuthProvider, PrivateRoute, useAuth, useAuthHeader, useAuthUser, useIsAuthenticated, useRefreshToken, useSignIn, useSignOut, withAuthHeader, withAuthUser, withIsAuthenticated, withRefreshToken, withSignIn, withSignOut };

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

/*! react-auth-kit v1.3.4 | Apache-2.0 */
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("js-cookie"),require("react-router-dom")):"function"==typeof define&&define.amd?define(["exports","react","js-cookie","react-router-dom"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).ReactAuthKit={},t.React,t.Cookies,t.reactRouterDom)}(this,(function(t,e,a,n){"use strict";function u(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var o=u(a),r=function(){function t(t){var e=t.authStorageName,a=t.authStorageType,n=t.authTimeStorageName,u=t.stateStorageName,o=t.cookieDomain,r=t.cookieSecure;this.authStorageType=a,this.authStorageName=e,this.authTimeStorageName=n,this.stateStorageName=u,this.cookieDomain=o,this.cookieSecure=r,this.authStorageTypeName=this.authStorageName+"_type"}return t.prototype.initialToken=function(){return"cookie"===this.authStorageType?this.initialCookieToken():this.initialLSToken()},t.prototype.initialCookieToken=function(){var t=o.default.get(this.authStorageName),e=o.default.get(this.authStorageTypeName),a=o.default.get(this.authTimeStorageName),n=o.default.get(this.stateStorageName);return this.checkTokenExist(t,e,a,n)},t.prototype.initialLSToken=function(){var t=localStorage.getItem(this.authStorageName),e=localStorage.getItem(this.authStorageTypeName),a=localStorage.getItem(this.authTimeStorageName),n=localStorage.getItem(this.stateStorageName);return this.checkTokenExist(t,e,a,n)},t.prototype.checkTokenExist=function(t,e,a,n){if(!(t&&e&&a&&n))return{authToken:null,authTokenType:null,expireAt:null,authState:null};var u=new Date(a);try{return{authToken:t,authTokenType:e,expireAt:u,authState:JSON.parse(n)}}catch(t){return{authToken:null,authTokenType:null,expireAt:null,authState:null}}},t.prototype.syncTokens=function(t){void 0===t.authToken||null===t.authTokenType||null===t.authToken||null===t.expireAt||null===t.authState?this.removeToken():this.setToken(t.authToken,t.authTokenType,t.expireAt,t.authState)},t.prototype.setToken=function(t,e,a,n){"cookie"===this.authStorageType?this.setCookieToken(t,e,a,n):this.setLSToken(t,e,a,n)},t.prototype.setCookieToken=function(t,e,a,n){o.default.set(this.authStorageName,t,{expires:a,domain:this.cookieDomain,secure:this.cookieSecure}),o.default.set(this.authStorageTypeName,e,{expires:a,domain:this.cookieDomain,secure:this.cookieSecure}),o.default.set(this.authTimeStorageName,a,{expires:a,domain:this.cookieDomain,secure:this.cookieSecure}),o.default.set(this.stateStorageName,n,{expires:a,domain:this.cookieDomain,secure:this.cookieSecure})},t.prototype.setLSToken=function(t,e,a,n){localStorage.setItem(this.authStorageName,t),localStorage.setItem(this.authStorageTypeName,e),localStorage.setItem(this.authTimeStorageName,a.toString()),localStorage.setItem(this.stateStorageName,JSON.stringify(n))},t.prototype.removeToken=function(){"cookie"===this.authStorageType?this.removeCookieToken():this.removeLSToken()},t.prototype.removeCookieToken=function(){o.default.remove(this.authStorageName),o.default.remove(this.authTimeStorageName),o.default.remove(this.stateStorageName)},t.prototype.removeLSToken=function(){localStorage.removeItem(this.authStorageName),localStorage.removeItem(this.authTimeStorageName),localStorage.removeItem(this.stateStorageName)},t}(),i=e.createContext({authState:{authTokenType:null,authState:null,authToken:null,expireAt:null},setAuthState:function(){}}),h=function(t){var a=t.children,n=t.authStorageType,u=t.authStorageName,o=t.authTimeStorageName,h=t.stateStorageName,l=t.cookieDomain,c=t.cookieSecure;if("cookie"===n&&!l)throw new Error("authStorageType 'cookie' requires 'cookieDomain' and 'cookieSecure' in AuthProvider");var s=new r({authTimeStorageName:o,authStorageType:n,authStorageName:u,cookieDomain:l,cookieSecure:c,stateStorageName:h}),S=e.useState(s.initialToken()),T=S[0],m=S[1];return e.useEffect((function(){s.syncTokens(T)}),[T]),e.createElement(i.Provider,{value:{authState:T,setAuthState:m}},a)};h.defaultProps={authStorageType:"cookie",authStorageName:"_auth_token",authTimeStorageName:"_auth_time",stateStorageName:"_auth_state",cookieSecure:!0};var l=i.Consumer,c=function(){return(c=Object.assign||function(t){for(var e,a=1,n=arguments.length;a<n;a++)for(var u in e=arguments[a])Object.prototype.hasOwnProperty.call(e,u)&&(t[u]=e[u]);return t}).apply(this,arguments)};t.AuthProvider=h,t.PrivateRoute=function(t){var a=e.useContext(i),u=t.component,o=t.loginPath,r=t.strict,h=t.sensitive,l=t.exact,c=t.path,s=t.location,S=t.render;return e.createElement(n.Route,{location:s,path:c,exact:l,sensitive:h,strict:r,render:function(t){return(null==a?void 0:a.authState.authToken)&&(null==a?void 0:a.authState.expireAt)&&(new Date(a.authState.expireAt)>new Date||(a.setAuthState({authToken:null,authTokenType:null,expireAt:null,authState:null}),0))?u?e.createElement(u,t):S?S(t):null:e.createElement(n.Redirect,{to:o})}})},t.useAuth=
/*! react-auth-kit v1.4.0 | Apache-2.0 */
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("js-cookie"),require("react-router-dom")):"function"==typeof define&&define.amd?define(["exports","react","js-cookie","react-router-dom"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).ReactAuthKit={},t.React,t.Cookies,t.reactRouterDom)}(this,(function(t,e,n,a){"use strict";function u(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var o=u(n),r=function(){function t(t){var e=t.authStorageName,n=t.authStorageType,a=t.authTimeStorageName,u=t.stateStorageName,o=t.cookieDomain,r=t.cookieSecure;this.authStorageType=n,this.authStorageName=e,this.authTimeStorageName=a,this.stateStorageName=u,this.cookieDomain=o,this.cookieSecure=r,this.authStorageTypeName=this.authStorageName+"_type"}return t.prototype.initialToken=function(){return"cookie"===this.authStorageType?this.initialCookieToken():this.initialLSToken()},t.prototype.initialCookieToken=function(){var t=o.default.get(this.authStorageName),e=o.default.get(this.authStorageTypeName),n=o.default.get(this.authTimeStorageName),a=o.default.get(this.stateStorageName);return this.checkTokenExist(t,e,n,a)},t.prototype.initialLSToken=function(){var t=localStorage.getItem(this.authStorageName),e=localStorage.getItem(this.authStorageTypeName),n=localStorage.getItem(this.authTimeStorageName),a=localStorage.getItem(this.stateStorageName);return this.checkTokenExist(t,e,n,a)},t.prototype.checkTokenExist=function(t,e,n,a){if(!(t&&e&&n&&a))return{authToken:null,authTokenType:null,expireAt:null,authState:null};var u=new Date(n);try{return{authToken:t,authTokenType:e,expireAt:u,authState:JSON.parse(a)}}catch(t){return{authToken:null,authTokenType:null,expireAt:null,authState:null}}},t.prototype.syncTokens=function(t){void 0===t.authToken||null===t.authTokenType||null===t.authToken||null===t.expireAt||null===t.authState?this.removeToken():this.setToken(t.authToken,t.authTokenType,t.expireAt,t.authState)},t.prototype.setToken=function(t,e,n,a){"cookie"===this.authStorageType?this.setCookieToken(t,e,n,a):this.setLSToken(t,e,n,a)},t.prototype.setCookieToken=function(t,e,n,a){o.default.set(this.authStorageName,t,{expires:n,domain:this.cookieDomain,secure:this.cookieSecure}),o.default.set(this.authStorageTypeName,e,{expires:n,domain:this.cookieDomain,secure:this.cookieSecure}),o.default.set(this.authTimeStorageName,n,{expires:n,domain:this.cookieDomain,secure:this.cookieSecure}),o.default.set(this.stateStorageName,a,{expires:n,domain:this.cookieDomain,secure:this.cookieSecure})},t.prototype.setLSToken=function(t,e,n,a){localStorage.setItem(this.authStorageName,t),localStorage.setItem(this.authStorageTypeName,e),localStorage.setItem(this.authTimeStorageName,n.toString()),localStorage.setItem(this.stateStorageName,JSON.stringify(a))},t.prototype.removeToken=function(){"cookie"===this.authStorageType?this.removeCookieToken():this.removeLSToken()},t.prototype.removeCookieToken=function(){o.default.remove(this.authStorageName),o.default.remove(this.authTimeStorageName),o.default.remove(this.stateStorageName)},t.prototype.removeLSToken=function(){localStorage.removeItem(this.authStorageName),localStorage.removeItem(this.authTimeStorageName),localStorage.removeItem(this.stateStorageName)},t}(),i=e.createContext({authState:{authTokenType:null,authState:null,authToken:null,expireAt:null},setAuthState:function(){}}),h=function(t){var n=t.children,a=t.authStorageType,u=t.authStorageName,o=t.authTimeStorageName,h=t.stateStorageName,l=t.cookieDomain,c=t.cookieSecure;if("cookie"===a&&!l)throw new Error("authStorageType 'cookie' requires 'cookieDomain' and 'cookieSecure' in AuthProvider");var s=new r({authTimeStorageName:o,authStorageType:a,authStorageName:u,cookieDomain:l,cookieSecure:c,stateStorageName:h}),S=e.useState(s.initialToken()),T=S[0],p=S[1];return e.useEffect((function(){s.syncTokens(T)}),[T]),e.createElement(i.Provider,{value:{authState:T,setAuthState:p}},n)};h.defaultProps={authStorageType:"cookie",authStorageName:"_auth_token",authTimeStorageName:"_auth_time",stateStorageName:"_auth_state",cookieSecure:!0};var l=i.Consumer,c=function(){return(c=Object.assign||function(t){for(var e,n=1,a=arguments.length;n<a;n++)for(var u in e=arguments[n])Object.prototype.hasOwnProperty.call(e,u)&&(t[u]=e[u]);return t}).apply(this,arguments)};var s=function(){function t(t){this.context=t}return t.prototype.getCurrentAuthState=function(){return{authToken:this.context.authState.authTokenType,authTokenType:this.context.authState.authToken,expireAt:this.context.authState.expireAt}},t.prototype.getCurrentUserState=function(){return this.context.authState.authState},t.prototype.updateAuthState=function(t,e,n){var a={authToken:t};if(void 0!==e&&Object.assign(a,{authTokenType:e}),void 0!==n){var u=new Date((new Date).getTime()+60*n*1e3);Object.assign(a,{expireAt:u})}this.context.setAuthState((function(t){return c(c({},t),a)}))},t.prototype.updateUserState=function(t){this.context.setAuthState((function(e){return c(c({},e),{authState:t})}))},t}();t.AuthProvider=h,t.PrivateRoute=function(t){var n=e.useContext(i),u=t.component,o=t.loginPath,r=t.strict,h=t.sensitive,l=t.exact,c=t.path,s=t.location,S=t.render;return e.createElement(a.Route,{location:s,path:c,exact:l,sensitive:h,strict:r,render:function(t){return(null==n?void 0:n.authState.authToken)&&(null==n?void 0:n.authState.expireAt)&&(new Date(n.authState.expireAt)>new Date||(n.setAuthState({authToken:null,authTokenType:null,expireAt:null,authState:null}),0))?u?e.createElement(u,t):S?S(t):null:e.createElement(a.Redirect,{to:o})}})},t.useAuth=
/**

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

*/
function(){var t=e.useContext(i);return{authHeader:function(){return(null==t?void 0:t.authState)?t.authState.authTokenType+" "+t.authState.authToken:"Bearer "},isAuthenticated:function(){return!(!(null==t?void 0:t.authState.authToken)||!(null==t?void 0:t.authState.expireAt))&&(new Date(t.authState.expireAt)>new Date||(t.setAuthState({authToken:null,authTokenType:null,expireAt:null,authState:null}),!1))},authUser:function(){return t.authState.authState},signOut:function(){try{return!!(null==t?void 0:t.authState.authToken)&&(t.setAuthState((function(t){return c(c({},t),{authToken:null,authTokenType:null,expireAt:null,authState:null})})),console.log("RAJ :: Signing Out"),!0)}catch(t){return!1}},signIn:function(e){var a=e.token,n=e.tokenType,u=e.authState,o=e.expiresIn,r=new Date((new Date).getTime()+60*o*1e3);try{return!!t&&(t.setAuthState((function(t){return c(c({},t),{authToken:a,authTokenType:n,expireAt:r,authState:u})})),!0)}catch(t){return console.error(t),!1}}}}
function(){var t=e.useContext(i);return{authHeader:function(){return(null==t?void 0:t.authState)?t.authState.authTokenType+" "+t.authState.authToken:"Bearer "},isAuthenticated:function(){return!(!(null==t?void 0:t.authState.authToken)||!(null==t?void 0:t.authState.expireAt))&&(new Date(t.authState.expireAt)>new Date||(t.setAuthState({authToken:null,authTokenType:null,expireAt:null,authState:null}),!1))},authUser:function(){return t.authState.authState},signOut:function(){try{return!!(null==t?void 0:t.authState.authToken)&&(t.setAuthState((function(t){return c(c({},t),{authToken:null,authTokenType:null,expireAt:null,authState:null})})),console.log("RAJ :: Signing Out"),!0)}catch(t){return!1}},signIn:function(e){var n=e.token,a=e.tokenType,u=e.authState,o=e.expiresIn,r=new Date((new Date).getTime()+60*o*1e3);try{return!!t&&(t.setAuthState((function(t){return c(c({},t),{authToken:n,authTokenType:a,expireAt:r,authState:u})})),!0)}catch(t){return console.error(t),!1}}}}
/**

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

*@license Apache-2.0
*/,t.useAuthHeader=function(){var t=e.useContext(i);return function(){return(null==t?void 0:t.authState)?t.authState.authTokenType+" "+t.authState.authToken:"Bearer "}}
*/,t.useAuthHeader=function(){var t=e.useContext(i);return function(){return(null==t?void 0:t.authState)?t.authState.authTokenType+" "+t.authState.authToken:"Bearer "}},t.useAuthUser=function(){var t=e.useContext(i);return function(){return t.authState.authState}},t.useIsAuthenticated=
/**

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

*@license Apache-2.0
*/,t.useAuthUser=function(){var t=e.useContext(i);return function(){return t.authState.authState}},t.useIsAuthenticated=function(){var t=e.useContext(i);return function(){return!(!(null==t?void 0:t.authState.authToken)||!(null==t?void 0:t.authState.expireAt))&&(new Date(t.authState.expireAt)>new Date||(t.setAuthState({authToken:null,authTokenType:null,expireAt:null,authState:null}),!1))}},t.useSignIn=function(){var t=e.useContext(i);return function(e){var a=e.token,n=e.tokenType,u=e.authState,o=e.expiresIn,r=new Date((new Date).getTime()+60*o*1e3);try{return!!t&&(t.setAuthState((function(t){return c(c({},t),{authToken:a,authTokenType:n,expireAt:r,authState:u})})),!0)}catch(t){return console.error(t),!1}}}
*/
function(){var t=e.useContext(i);return function(){return!(!(null==t?void 0:t.authState.authToken)||!(null==t?void 0:t.authState.expireAt))&&(new Date(t.authState.expireAt)>new Date||(t.setAuthState({authToken:null,authTokenType:null,expireAt:null,authState:null}),!1))}},t.useRefreshToken=function(){var t=e.useContext(i);return new s(t)},t.useSignIn=function(){var t=e.useContext(i);return function(e){var n=e.token,a=e.tokenType,u=e.authState,o=e.expiresIn,r=new Date((new Date).getTime()+60*o*1e3);try{return!!t&&(t.setAuthState((function(t){return c(c({},t),{authToken:n,authTokenType:a,expireAt:r,authState:u})})),!0)}catch(t){return console.error(t),!1}}}
/**

@@ -37,4 +38,10 @@ *@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

*/
function(t){return function(a){return e.createElement(l,null,(function(n){return(null==n?void 0:n.authState)?e.createElement(t,c({},a,{authHeader:n.authState.authTokenType+" "+n.authState.authToken})):e.createElement(t,c({},a,{authHeader:null}))}))}}
function(t){return function(n){return e.createElement(l,null,(function(a){return(null==a?void 0:a.authState)?e.createElement(t,c({},n,{authHeader:a.authState.authTokenType+" "+a.authState.authToken})):e.createElement(t,c({},n,{authHeader:null}))}))}}
/**
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>
*@fileoverview Authentication header
*@copyright Arkadip Bhattacharya 2020
*@license Apache-2.0
*/,t.withAuthUser=function(t){return function(n){return e.createElement(l,null,(function(a){return e.createElement(t,c({},n,{authState:null==a?void 0:a.authState.authState}))}))}},t.withIsAuthenticated=
/**
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com>

@@ -44,2 +51,3 @@ *@fileoverview Authentication status

*@license Apache-2.0
*/,t.withAuthUser=function(t){return function(a){return e.createElement(l,null,(function(n){return e.createElement(t,c({},a,{authState:null==n?void 0:n.authState.authState}))}))}},t.withIsAuthenticated=function(t){return function(a){return e.createElement(l,null,(function(n){return(null==n?void 0:n.authState.authToken)&&(null==n?void 0:n.authState.expireAt)?new Date(n.authState.expireAt)>new Date?e.createElement(t,c({},a,{isAuth:!0})):(n.setAuthState({authToken:null,authTokenType:null,expireAt:null,authState:null}),e.createElement(t,c({},a,{isAuth:!1}))):e.createElement(t,c({},a,{isAuth:!1}))}))}},t.withSignIn=function(t){return function(a){return e.createElement(l,null,(function(n){return e.createElement(t,c({},a,{signIn:function(t){var e=t.token,a=t.tokenType,u=t.authState,o=t.expiresIn,r=new Date((new Date).getTime()+60*o*1e3);try{return!!n&&(n.setAuthState((function(t){return c(c({},t),{authToken:e,authTokenType:a,expireAt:r,authState:u})})),!0)}catch(t){return console.error(t),!1}}}))}))}},t.withSignOut=function(t){return function(a){return e.createElement(l,null,(function(n){return e.createElement(t,c({},a,{signOut:function(){try{return!!(null==n?void 0:n.authState.authToken)&&(n.setAuthState((function(t){return c(c({},t),{authToken:null,authTokenType:null,expireAt:null,authState:null})})),!0)}catch(t){return!1}}}))}))}},Object.defineProperty(t,"__esModule",{value:!0})}));
*/
function(t){return function(n){return e.createElement(l,null,(function(a){return(null==a?void 0:a.authState.authToken)&&(null==a?void 0:a.authState.expireAt)?new Date(a.authState.expireAt)>new Date?e.createElement(t,c({},n,{isAuth:!0})):(a.setAuthState({authToken:null,authTokenType:null,expireAt:null,authState:null}),e.createElement(t,c({},n,{isAuth:!1}))):e.createElement(t,c({},n,{isAuth:!1}))}))}},t.withRefreshToken=function(t){return function(n){return e.createElement(l,null,(function(a){return e.createElement(t,c({},n,{refreshToken:new s(a)}))}))}},t.withSignIn=function(t){return function(n){return e.createElement(l,null,(function(a){return e.createElement(t,c({},n,{signIn:function(t){var e=t.token,n=t.tokenType,u=t.authState,o=t.expiresIn,r=new Date((new Date).getTime()+60*o*1e3);try{return!!a&&(a.setAuthState((function(t){return c(c({},t),{authToken:e,authTokenType:n,expireAt:r,authState:u})})),!0)}catch(t){return console.error(t),!1}}}))}))}},t.withSignOut=function(t){return function(n){return e.createElement(l,null,(function(a){return e.createElement(t,c({},n,{signOut:function(){try{return!!(null==a?void 0:a.authState.authToken)&&(a.setAuthState((function(t){return c(c({},t),{authToken:null,authTokenType:null,expireAt:null,authState:null})})),!0)}catch(t){return!1}}}))}))}},Object.defineProperty(t,"__esModule",{value:!0})}));
{
"name": "react-auth-kit",
"version": "1.3.4",
"version": "1.4.0",
"description": "Authentication Library for React",

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

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