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

react-auth-kit

Package Overview
Dependencies
Maintainers
1
Versions
200
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-auth-kit - npm Package Compare versions

Comparing version 1.1.6 to 1.1.7

8

CHANGELOG.md
# Changelog
All notable changes to this project will be documented in this file.
## [1.1.7] - 2020-09-14
### Added
- `useIsAuthenticated` and `withIsAuthenticated` added. Now check if your user is logged in or not.
### Changed
- ⚠ `useAuth` is changed to `useAuthUser`
- ⚠ `withAuth` is changed to `withAuthUser`
## [1.1.6] - 2020-09-12

@@ -5,0 +13,0 @@ ### Fixed

125

dist/index.js

@@ -218,3 +218,11 @@ 'use strict';

var AuthContext = React.createContext(null);
var AuthContext = React.createContext({
authState: {
authTokenType: null,
authState: null,
authToken: null,
expireAt: null
},
setAuthState: function () { }
});
/**

@@ -379,6 +387,6 @@ * AuthProvider - The Authentication Context Provider

*/
function useAuth() {
function useAuthUser() {
var c = React.useContext(AuthContext);
return function () {
return c === null || c === void 0 ? void 0 : c.authState.authState;
return c.authState.authState;
};

@@ -399,20 +407,39 @@ }

function withAuth(Component) {
return function (props) {
return (React.createElement(AuthContextConsumer, null, function (value) { return (React.createElement(Component, __assign({}, props, { authState: value === null || value === void 0 ? void 0 : value.authState.authState }))); }));
};
}
function withAuthHeader(Component) {
return function (props) {
return (React.createElement(AuthContextConsumer, null, function (c) {
if (c === null || c === void 0 ? void 0 : c.authState) {
return (React.createElement(Component, __assign({}, props, { authHeader: c.authState.authTokenType + " " + c.authState.authToken })));
/*
* 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.
*/
var useIsAuthenticated = function () {
var context = React.useContext(AuthContext);
return function () {
if ((context === null || context === void 0 ? void 0 : context.authState.authToken) && (context === null || context === void 0 ? void 0 : context.authState.expireAt)) {
if (new Date(context.authState.expireAt) > new Date()) {
return true;
}
else {
return React.createElement(Component, __assign({}, props, { authHeader: null }));
context.setAuthState({
authToken: null,
authTokenType: null,
expireAt: null,
authState: null
});
return false;
}
}));
}
else {
return false;
}
};
}
};

@@ -466,11 +493,71 @@ function withSignIn(Component) {

function withAuthUser(Component) {
return function (props) {
return (React.createElement(AuthContextConsumer, null, function (value) { return (React.createElement(Component, __assign({}, props, { authState: value === null || value === void 0 ? void 0 : value.authState.authState }))); }));
};
}
function withAuthHeader(Component) {
return function (props) {
return (React.createElement(AuthContextConsumer, null, function (c) {
if (c === null || c === void 0 ? void 0 : c.authState) {
return (React.createElement(Component, __assign({}, props, { authHeader: c.authState.authTokenType + " " + c.authState.authToken })));
}
else {
return React.createElement(Component, __assign({}, props, { authHeader: null }));
}
}));
};
}
/*
* 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 withIsAuthenticated(Component) {
return function (props) {
return (React.createElement(AuthContextConsumer, null, function (c) {
if ((c === null || c === void 0 ? void 0 : c.authState.authToken) && (c === null || c === void 0 ? void 0 : c.authState.expireAt)) {
if (new Date(c.authState.expireAt) > new Date()) {
return React.createElement(Component, __assign({}, props, { isAuth: true }));
}
else {
c.setAuthState({
authToken: null,
authTokenType: null,
expireAt: null,
authState: null
});
return React.createElement(Component, __assign({}, props, { isAuth: false }));
}
}
else {
return React.createElement(Component, __assign({}, props, { isAuth: false }));
}
}));
};
}
exports.AuthProvider = AuthProvider;
exports.PrivateRoute = PrivateRoute;
exports.useAuth = useAuth;
exports.useAuthHeader = useAuthHeader;
exports.useAuthUser = useAuthUser;
exports.useIsAuthenticated = useIsAuthenticated;
exports.useSignIn = useSignIn;
exports.useSignOut = useSignOut;
exports.withAuth = withAuth;
exports.withAuthHeader = withAuthHeader;
exports.withAuthUser = withAuthUser;
exports.withIsAuthenticated = withIsAuthenticated;
exports.withSignIn = withSignIn;
exports.withSignOut = withSignOut;

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

var AuthContext = createContext(null);
var AuthContext = createContext({
authState: {
authTokenType: null,
authState: null,
authToken: null,
expireAt: null
},
setAuthState: function () { }
});
/**

@@ -371,6 +379,6 @@ * AuthProvider - The Authentication Context Provider

*/
function useAuth() {
function useAuthUser() {
var c = useContext(AuthContext);
return function () {
return c === null || c === void 0 ? void 0 : c.authState.authState;
return c.authState.authState;
};

@@ -391,20 +399,39 @@ }

function withAuth(Component) {
return function (props) {
return (createElement(AuthContextConsumer, null, function (value) { return (createElement(Component, __assign({}, props, { authState: value === null || value === void 0 ? void 0 : value.authState.authState }))); }));
};
}
function withAuthHeader(Component) {
return function (props) {
return (createElement(AuthContextConsumer, null, function (c) {
if (c === null || c === void 0 ? void 0 : c.authState) {
return (createElement(Component, __assign({}, props, { authHeader: c.authState.authTokenType + " " + c.authState.authToken })));
/*
* 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.
*/
var useIsAuthenticated = function () {
var context = useContext(AuthContext);
return function () {
if ((context === null || context === void 0 ? void 0 : context.authState.authToken) && (context === null || context === void 0 ? void 0 : context.authState.expireAt)) {
if (new Date(context.authState.expireAt) > new Date()) {
return true;
}
else {
return createElement(Component, __assign({}, props, { authHeader: null }));
context.setAuthState({
authToken: null,
authTokenType: null,
expireAt: null,
authState: null
});
return false;
}
}));
}
else {
return false;
}
};
}
};

@@ -458,2 +485,60 @@ function withSignIn(Component) {

export { AuthProvider, PrivateRoute, useAuth, useAuthHeader, useSignIn, useSignOut, withAuth, withAuthHeader, withSignIn, withSignOut };
function withAuthUser(Component) {
return function (props) {
return (createElement(AuthContextConsumer, null, function (value) { return (createElement(Component, __assign({}, props, { authState: value === null || value === void 0 ? void 0 : value.authState.authState }))); }));
};
}
function withAuthHeader(Component) {
return function (props) {
return (createElement(AuthContextConsumer, null, function (c) {
if (c === null || c === void 0 ? void 0 : c.authState) {
return (createElement(Component, __assign({}, props, { authHeader: c.authState.authTokenType + " " + c.authState.authToken })));
}
else {
return createElement(Component, __assign({}, props, { authHeader: null }));
}
}));
};
}
/*
* 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 withIsAuthenticated(Component) {
return function (props) {
return (createElement(AuthContextConsumer, null, function (c) {
if ((c === null || c === void 0 ? void 0 : c.authState.authToken) && (c === null || c === void 0 ? void 0 : c.authState.expireAt)) {
if (new Date(c.authState.expireAt) > new Date()) {
return createElement(Component, __assign({}, props, { isAuth: true }));
}
else {
c.setAuthState({
authToken: null,
authTokenType: null,
expireAt: null,
authState: null
});
return createElement(Component, __assign({}, props, { isAuth: false }));
}
}
else {
return createElement(Component, __assign({}, props, { isAuth: false }));
}
}));
};
}
export { AuthProvider, PrivateRoute, useAuthHeader, useAuthUser, useIsAuthenticated, useSignIn, useSignOut, withAuthHeader, withAuthUser, withIsAuthenticated, withSignIn, withSignOut };

4

dist/index.umd.js

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

/*! react-auth-kit v1.1.6 | Apache-2.0 */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("js-cookie"),require("react-router-dom")):"function"==typeof define&&define.amd?define(["exports","react","js-cookie","react-router-dom"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactAuthKit={},e.React,e.Cookies,e.reactRouterDom)}(this,(function(e,t,a,o){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=n(a),r=function(){function e(e){var t=e.authStorageName,a=e.authStorageType,o=e.authTimeStorageName,n=e.stateStorageName,u=e.cookieDomain,r=e.cookieSecure;this.authStorageType=a,this.authStorageName=t,this.authTimeStorageName=o,this.stateStorageName=n,this.cookieDomain=u,this.cookieSecure=r,this.authStorageTypeName=this.authStorageName+"_type"}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),a=u.default.get(this.authTimeStorageName),o=u.default.get(this.stateStorageName);return this.checkTokenExist(e,t,a,o)},e.prototype.initialLSToken=function(){var e=localStorage.getItem(this.authStorageName),t=localStorage.getItem(this.authStorageTypeName),a=localStorage.getItem(this.authTimeStorageName),o=localStorage.getItem(this.stateStorageName);return this.checkTokenExist(e,t,a,o)},e.prototype.checkTokenExist=function(e,t,a,o){if(!(e&&t&&a&&o))return{authToken:null,authTokenType:null,expireAt:null,authState:null};var n=new Date(a);try{return{authToken:e,authTokenType:t,expireAt:n,authState:JSON.parse(o)}}catch(e){return{authToken:null,authTokenType:null,expireAt:null,authState:null}}},e.prototype.syncTokens=function(e){void 0===e.authToken||null===e.authTokenType||null===e.authToken||null===e.expireAt||null===e.authState?this.removeToken():this.setToken(e.authToken,e.authTokenType,e.expireAt,e.authState)},e.prototype.setToken=function(e,t,a,o){"cookie"===this.authStorageType?this.setCookieToken(e,t,a,o):this.setLSToken(e,t,a,o)},e.prototype.setCookieToken=function(e,t,a,o){u.default.set(this.authStorageName,e,{expires:a,domain:this.cookieDomain,secure:this.cookieSecure}),u.default.set(this.authStorageTypeName,t,{expires:a,domain:this.cookieDomain,secure:this.cookieSecure}),u.default.set(this.authTimeStorageName,a,{expires:a,domain:this.cookieDomain,secure:this.cookieSecure}),u.default.set(this.stateStorageName,o,{expires:a,domain:this.cookieDomain,secure:this.cookieSecure})},e.prototype.setLSToken=function(e,t,a,o){localStorage.setItem(this.authStorageName,e),localStorage.setItem(this.authStorageTypeName,t),localStorage.setItem(this.authTimeStorageName,a.toString()),localStorage.setItem(this.stateStorageName,JSON.stringify(o))},e.prototype.removeToken=function(){"cookie"===this.authStorageType?this.removeCookieToken():this.removeLSToken()},e.prototype.removeCookieToken=function(){u.default.remove(this.authStorageName),u.default.remove(this.authTimeStorageName),u.default.remove(this.stateStorageName)},e.prototype.removeLSToken=function(){localStorage.removeItem(this.authStorageName),localStorage.removeItem(this.authTimeStorageName),localStorage.removeItem(this.stateStorageName)},e}(),i=t.createContext(null),h=function(e){var a=e.children,o=e.authStorageType,n=e.authStorageName,u=e.authTimeStorageName,h=e.stateStorageName,c=e.cookieDomain,l=e.cookieSecure;if(!("cookie"!==o||l&&c))throw new Error("authStorageType 'cookie' requires 'cookieDomain' and 'cookieSecure' in AuthProvider");var s=new r({authTimeStorageName:u,authStorageType:o,authStorageName:n,cookieDomain:c,cookieSecure:l,stateStorageName:h}),S=t.useState(s.initialToken()),m=S[0],T=S[1];return t.useEffect((function(){s.syncTokens(m)}),[m]),t.createElement(i.Provider,{value:{authState:m,setAuthState:T}},a)};h.defaultProps={authStorageType:"cookie",authStorageName:"_auth_token",authTimeStorageName:"_auth_time",stateStorageName:"_auth_state",cookieSecure:!0};var c=i.Consumer,l=function(){return(l=Object.assign||function(e){for(var t,a=1,o=arguments.length;a<o;a++)for(var n in t=arguments[a])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e}).apply(this,arguments)};e.AuthProvider=h,e.PrivateRoute=function(e){var a=t.useContext(i),n=e.component,u=e.loginPath,r=e.strict,h=e.sensitive,c=e.exact,l=e.path,s=e.location,S=e.render;return t.createElement(o.Route,{location:s,path:l,exact:c,sensitive:h,strict:r,render:function(e){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))?n?t.createElement(n,e):S?S(e):null:t.createElement(o.Redirect,{to:u})}})},e.useAuth=function(){var e=t.useContext(i);return function(){return null==e?void 0:e.authState.authState}},e.useAuthHeader=function(){var e=t.useContext(i);return function(){return(null==e?void 0:e.authState)?e.authState.authTokenType+" "+e.authState.authToken:"Bearer "}},e.useSignIn=function(){var e=t.useContext(i);return function(t){var a=t.token,o=t.authState,n=t.expiresIn,u=t.tokenType,r=new Date((new Date).getTime()+60*n*1e3);try{return!!e&&(e.setAuthState((function(e){return l(l({},e),{authToken:a,authTokenType:u,expireAt:r,authState:o})})),!0)}catch(e){return console.error(e),!1}}},e.useSignOut=function(){var e=t.useContext(i);return function(){try{return!!(null==e?void 0:e.authState.authToken)&&(e.setAuthState((function(e){return l(l({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null})})),console.log("RAJ :: Signing Out"),!0)}catch(e){return!1}}},e.withAuth=function(e){return function(a){return t.createElement(c,null,(function(o){return t.createElement(e,l({},a,{authState:null==o?void 0:o.authState.authState}))}))}},e.withAuthHeader=function(e){return function(a){return t.createElement(c,null,(function(o){return(null==o?void 0:o.authState)?t.createElement(e,l({},a,{authHeader:o.authState.authTokenType+" "+o.authState.authToken})):t.createElement(e,l({},a,{authHeader:null}))}))}},e.withSignIn=function(e){return function(a){return t.createElement(c,null,(function(o){return t.createElement(e,l({},a,{signIn:function(e){var t=e.token,a=e.tokenType,n=e.expiresIn,u=e.authState,r=new Date((new Date).getTime()+60*n*1e3);try{return!!o&&(o.setAuthState((function(e){return l(l({},e),{authToken:t,authTokenType:a,expireAt:r,authState:u})})),!0)}catch(e){return console.error(e),!1}}}))}))}},e.withSignOut=function(e){return function(a){return t.createElement(c,null,(function(o){return t.createElement(e,l({},a,{signOut:function(){try{return!!(null==o?void 0:o.authState.authToken)&&(o.setAuthState((function(e){return l(l({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null})})),!0)}catch(e){return!1}}}))}))}},Object.defineProperty(e,"__esModule",{value:!0})}));
/*! react-auth-kit v1.1.7 | 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,a,n){"use strict";function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=o(a),r=function(){function e(e){var t=e.authStorageName,a=e.authStorageType,n=e.authTimeStorageName,o=e.stateStorageName,u=e.cookieDomain,r=e.cookieSecure;this.authStorageType=a,this.authStorageName=t,this.authTimeStorageName=n,this.stateStorageName=o,this.cookieDomain=u,this.cookieSecure=r,this.authStorageTypeName=this.authStorageName+"_type"}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),a=u.default.get(this.authTimeStorageName),n=u.default.get(this.stateStorageName);return this.checkTokenExist(e,t,a,n)},e.prototype.initialLSToken=function(){var e=localStorage.getItem(this.authStorageName),t=localStorage.getItem(this.authStorageTypeName),a=localStorage.getItem(this.authTimeStorageName),n=localStorage.getItem(this.stateStorageName);return this.checkTokenExist(e,t,a,n)},e.prototype.checkTokenExist=function(e,t,a,n){if(!(e&&t&&a&&n))return{authToken:null,authTokenType:null,expireAt:null,authState:null};var o=new Date(a);try{return{authToken:e,authTokenType:t,expireAt:o,authState:JSON.parse(n)}}catch(e){return{authToken:null,authTokenType:null,expireAt:null,authState:null}}},e.prototype.syncTokens=function(e){void 0===e.authToken||null===e.authTokenType||null===e.authToken||null===e.expireAt||null===e.authState?this.removeToken():this.setToken(e.authToken,e.authTokenType,e.expireAt,e.authState)},e.prototype.setToken=function(e,t,a,n){"cookie"===this.authStorageType?this.setCookieToken(e,t,a,n):this.setLSToken(e,t,a,n)},e.prototype.setCookieToken=function(e,t,a,n){u.default.set(this.authStorageName,e,{expires:a,domain:this.cookieDomain,secure:this.cookieSecure}),u.default.set(this.authStorageTypeName,t,{expires:a,domain:this.cookieDomain,secure:this.cookieSecure}),u.default.set(this.authTimeStorageName,a,{expires:a,domain:this.cookieDomain,secure:this.cookieSecure}),u.default.set(this.stateStorageName,n,{expires:a,domain:this.cookieDomain,secure:this.cookieSecure})},e.prototype.setLSToken=function(e,t,a,n){localStorage.setItem(this.authStorageName,e),localStorage.setItem(this.authStorageTypeName,t),localStorage.setItem(this.authTimeStorageName,a.toString()),localStorage.setItem(this.stateStorageName,JSON.stringify(n))},e.prototype.removeToken=function(){"cookie"===this.authStorageType?this.removeCookieToken():this.removeLSToken()},e.prototype.removeCookieToken=function(){u.default.remove(this.authStorageName),u.default.remove(this.authTimeStorageName),u.default.remove(this.stateStorageName)},e.prototype.removeLSToken=function(){localStorage.removeItem(this.authStorageName),localStorage.removeItem(this.authTimeStorageName),localStorage.removeItem(this.stateStorageName)},e}(),i=t.createContext({authState:{authTokenType:null,authState:null,authToken:null,expireAt:null},setAuthState:function(){}}),h=function(e){var a=e.children,n=e.authStorageType,o=e.authStorageName,u=e.authTimeStorageName,h=e.stateStorageName,l=e.cookieDomain,c=e.cookieSecure;if(!("cookie"!==n||c&&l))throw new Error("authStorageType 'cookie' requires 'cookieDomain' and 'cookieSecure' in AuthProvider");var s=new r({authTimeStorageName:u,authStorageType:n,authStorageName:o,cookieDomain:l,cookieSecure:c,stateStorageName:h}),S=t.useState(s.initialToken()),m=S[0],T=S[1];return t.useEffect((function(){s.syncTokens(m)}),[m]),t.createElement(i.Provider,{value:{authState:m,setAuthState:T}},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(e){for(var t,a=1,n=arguments.length;a<n;a++)for(var o in t=arguments[a])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};e.AuthProvider=h,e.PrivateRoute=function(e){var a=t.useContext(i),o=e.component,u=e.loginPath,r=e.strict,h=e.sensitive,l=e.exact,c=e.path,s=e.location,S=e.render;return t.createElement(n.Route,{location:s,path:c,exact:l,sensitive:h,strict:r,render:function(e){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))?o?t.createElement(o,e):S?S(e):null:t.createElement(n.Redirect,{to:u})}})},e.useAuthHeader=function(){var e=t.useContext(i);return function(){return(null==e?void 0:e.authState)?e.authState.authTokenType+" "+e.authState.authToken:"Bearer "}},e.useAuthUser=function(){var e=t.useContext(i);return function(){return e.authState.authState}},e.useIsAuthenticated=function(){var e=t.useContext(i);return function(){return!(!(null==e?void 0:e.authState.authToken)||!(null==e?void 0:e.authState.expireAt))&&(new Date(e.authState.expireAt)>new Date||(e.setAuthState({authToken:null,authTokenType:null,expireAt:null,authState:null}),!1))}},e.useSignIn=function(){var e=t.useContext(i);return function(t){var a=t.token,n=t.authState,o=t.expiresIn,u=t.tokenType,r=new Date((new Date).getTime()+60*o*1e3);try{return!!e&&(e.setAuthState((function(e){return c(c({},e),{authToken:a,authTokenType:u,expireAt:r,authState:n})})),!0)}catch(e){return console.error(e),!1}}},e.useSignOut=function(){var e=t.useContext(i);return function(){try{return!!(null==e?void 0:e.authState.authToken)&&(e.setAuthState((function(e){return c(c({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null})})),console.log("RAJ :: Signing Out"),!0)}catch(e){return!1}}},e.withAuthHeader=function(e){return function(a){return t.createElement(l,null,(function(n){return(null==n?void 0:n.authState)?t.createElement(e,c({},a,{authHeader:n.authState.authTokenType+" "+n.authState.authToken})):t.createElement(e,c({},a,{authHeader:null}))}))}},e.withAuthUser=function(e){return function(a){return t.createElement(l,null,(function(n){return t.createElement(e,c({},a,{authState:null==n?void 0:n.authState.authState}))}))}},e.withIsAuthenticated=function(e){return function(a){return t.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?t.createElement(e,c({},a,{isAuth:!0})):(n.setAuthState({authToken:null,authTokenType:null,expireAt:null,authState:null}),t.createElement(e,c({},a,{isAuth:!1}))):t.createElement(e,c({},a,{isAuth:!1}))}))}},e.withSignIn=function(e){return function(a){return t.createElement(l,null,(function(n){return t.createElement(e,c({},a,{signIn:function(e){var t=e.token,a=e.tokenType,o=e.expiresIn,u=e.authState,r=new Date((new Date).getTime()+60*o*1e3);try{return!!n&&(n.setAuthState((function(e){return c(c({},e),{authToken:t,authTokenType:a,expireAt:r,authState:u})})),!0)}catch(e){return console.error(e),!1}}}))}))}},e.withSignOut=function(e){return function(a){return t.createElement(l,null,(function(n){return t.createElement(e,c({},a,{signOut:function(){try{return!!(null==n?void 0:n.authState.authToken)&&(n.setAuthState((function(e){return c(c({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null})})),!0)}catch(e){return!1}}}))}))}},Object.defineProperty(e,"__esModule",{value:!0})}));
{
"name": "react-auth-kit",
"version": "1.1.6",
"version": "1.1.7",
"description": "Authentication Library for React",

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

"ts-jest": "^26.3.0",
"typedoc": "^0.19.1",
"typescript": "^4.0.2",

@@ -66,0 +67,0 @@ "utility-types": "^3.10.0"

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