react-auth-kit
Advanced tools
Comparing version 1.2.2 to 1.3.0
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
## [1.3.0] - 2020-12-17 | ||
### Added: | ||
- Code base documentation. ([Hardik0307](https://github.com/Hardik0307)) | ||
- Guideline for Contribution added on project website ([dotslash21](https://github.com/dotslash21)) | ||
### Fixed: | ||
- Eslint Linting issue | ||
- Contributing.md typo fix. ([dotslash21](https://github.com/dotslash21)) | ||
## [1.2.2] - 2020-09-21 | ||
@@ -51,3 +63,3 @@ ### Fixed | ||
### Changed | ||
- Size decreased from 2.12 KB to 1.81 KB | ||
- Size decreased from 2.12 KB to 1.81 KB | ||
@@ -59,3 +71,3 @@ ## [1.1.2] - 2020-09-10 | ||
## [1.1.1] - 2020-09-08 | ||
### Added | ||
### Added | ||
- Documentation [https://authkit.arkadip.co](https://authkit.arkadip.co) | ||
@@ -62,0 +74,0 @@ - Default props for `AuthProvider` |
@@ -13,2 +13,7 @@ 'use strict'; | ||
/** | ||
* @class TokenObject | ||
* | ||
* Stores and retrieve Token | ||
*/ | ||
var TokenObject = /** @class */ (function () { | ||
@@ -39,6 +44,6 @@ /** | ||
* | ||
* @returns TokenInterface | ||
* @return TokenInterface | ||
*/ | ||
TokenObject.prototype.initialToken = function () { | ||
if (this.authStorageType === "cookie") { | ||
if (this.authStorageType === 'cookie') { | ||
return this.initialCookieToken(); | ||
@@ -52,7 +57,7 @@ } | ||
* Get the Initial Token from Cookie | ||
* If the React App uses Cookie for storing Auth info, this Function is called | ||
* If the React App uses Cookie for storing Auth info | ||
* | ||
* Called from this.initialToken | ||
* | ||
* @returns TokenInterface | ||
* @return TokenInterface | ||
*/ | ||
@@ -68,7 +73,8 @@ TokenObject.prototype.initialCookieToken = function () { | ||
* Get the Initial Token from LocalStorage | ||
* If the React App uses LocalStorage for storing Auth info, this Function is called | ||
* If the React App uses LocalStorage for storing Auth info, | ||
* this Function is called | ||
* | ||
* Called from this.initialToken | ||
* | ||
* @returns TokenInterface | ||
* @return TokenInterface | ||
*/ | ||
@@ -85,3 +91,4 @@ TokenObject.prototype.initialLSToken = function () { | ||
* | ||
* If the tokens are valid, then it response TokenObject with auth Information | ||
* If the tokens are valid, | ||
* then it response TokenObject with auth Information | ||
* Else it response TokenObject with null | ||
@@ -94,3 +101,3 @@ * | ||
* | ||
* @returns TokenInterface | ||
* @return TokenInterface | ||
* | ||
@@ -103,10 +110,25 @@ */ | ||
var authState = JSON.parse(stateCookie); | ||
return { authToken: authToken, authTokenType: authTokenType, expireAt: expiresAt, authState: authState }; | ||
return { | ||
authToken: authToken, | ||
authTokenType: authTokenType, | ||
expireAt: expiresAt, | ||
authState: authState | ||
}; | ||
} | ||
catch (e) { | ||
return { authToken: null, authTokenType: null, expireAt: null, authState: null }; | ||
return { | ||
authToken: null, | ||
authTokenType: null, | ||
expireAt: null, | ||
authState: null, | ||
}; | ||
} | ||
} | ||
else { | ||
return { authToken: null, authTokenType: null, expireAt: null, authState: null }; | ||
return { | ||
authToken: null, | ||
authTokenType: null, | ||
expireAt: null, | ||
authState: null, | ||
}; | ||
} | ||
@@ -143,3 +165,3 @@ }; | ||
TokenObject.prototype.setToken = function (authToken, authTokenType, expiresAt, authState) { | ||
if (this.authStorageType === "cookie") { | ||
if (this.authStorageType === 'cookie') { | ||
this.setCookieToken(authToken, authTokenType, expiresAt, authState); | ||
@@ -164,3 +186,3 @@ } | ||
domain: this.cookieDomain, | ||
secure: this.cookieSecure | ||
secure: this.cookieSecure, | ||
}); | ||
@@ -170,3 +192,3 @@ Cookies__default['default'].set(this.authStorageTypeName, authTokenType, { | ||
domain: this.cookieDomain, | ||
secure: this.cookieSecure | ||
secure: this.cookieSecure, | ||
}); | ||
@@ -176,3 +198,3 @@ Cookies__default['default'].set(this.authTimeStorageName, expiresAt, { | ||
domain: this.cookieDomain, | ||
secure: this.cookieSecure | ||
secure: this.cookieSecure, | ||
}); | ||
@@ -182,3 +204,3 @@ Cookies__default['default'].set(this.stateStorageName, authState, { | ||
domain: this.cookieDomain, | ||
secure: this.cookieSecure | ||
secure: this.cookieSecure, | ||
}); | ||
@@ -204,3 +226,3 @@ }; | ||
TokenObject.prototype.removeToken = function () { | ||
if (this.authStorageType === "cookie") { | ||
if (this.authStorageType === 'cookie') { | ||
this.removeCookieToken(); | ||
@@ -236,5 +258,5 @@ } | ||
authToken: null, | ||
expireAt: null | ||
expireAt: null, | ||
}, | ||
setAuthState: function () { } | ||
setAuthState: function () { }, | ||
}); | ||
@@ -251,8 +273,11 @@ /** | ||
* @param stateStorageName | ||
* | ||
* @return Functional Component | ||
*/ | ||
var AuthProvider = function (_a) { | ||
var children = _a.children, authStorageType = _a.authStorageType, authStorageName = _a.authStorageName, authTimeStorageName = _a.authTimeStorageName, stateStorageName = _a.stateStorageName, cookieDomain = _a.cookieDomain, cookieSecure = _a.cookieSecure; | ||
if (authStorageType === "cookie") { | ||
if (authStorageType === 'cookie') { | ||
if (!cookieDomain) { | ||
throw new Error("authStorageType 'cookie' requires 'cookieDomain' and 'cookieSecure' in AuthProvider"); | ||
throw new Error('authStorageType \'cookie\' ' + | ||
'requires \'cookieDomain\' and \'cookieSecure\' in AuthProvider'); | ||
} | ||
@@ -266,3 +291,3 @@ } | ||
cookieSecure: cookieSecure, | ||
stateStorageName: stateStorageName | ||
stateStorageName: stateStorageName, | ||
}); | ||
@@ -276,7 +301,7 @@ var _b = React.useState(tokenObject.initialToken()), authState = _b[0], setAuthState = _b[1]; | ||
AuthProvider.defaultProps = { | ||
authStorageType: "cookie", | ||
authStorageName: "_auth_token", | ||
authTimeStorageName: "_auth_time", | ||
stateStorageName: "_auth_state", | ||
cookieSecure: true | ||
authStorageType: 'cookie', | ||
authStorageName: '_auth_token', | ||
authTimeStorageName: '_auth_time', | ||
stateStorageName: '_auth_state', | ||
cookieSecure: true, | ||
}; | ||
@@ -306,3 +331,3 @@ var AuthContextConsumer = AuthContext.Consumer; | ||
expireAt: null, | ||
authState: null | ||
authState: null, | ||
}); | ||
@@ -319,8 +344,8 @@ return false; | ||
return isAuth() ? | ||
component | ||
? React.createElement(component, renderProps) | ||
: render | ||
? render(renderProps) | ||
: null | ||
: React.createElement(reactRouterDom.Redirect, { to: loginPath }); | ||
component ? | ||
React.createElement(component, renderProps) : | ||
render ? | ||
render(renderProps) : | ||
null : | ||
React.createElement(reactRouterDom.Redirect, { to: loginPath }); | ||
} })); | ||
@@ -355,24 +380,24 @@ }; | ||
/* | ||
* 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. | ||
*/ | ||
/** | ||
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com> | ||
*@fileoverview Authentication | ||
*@copyright Arkadip Bhattacharya 2020 | ||
*@license Apache-2.0 | ||
*/ | ||
/** | ||
*@public | ||
*@function | ||
*@name useAuth | ||
*/ | ||
function useAuth() { | ||
/** | ||
*A constant c. | ||
*@kind constant | ||
*/ | ||
var c = React.useContext(AuthContext); | ||
/** | ||
* Get Auth header | ||
* | ||
* @returns authheader AuthHeader | null | ||
*/ | ||
/** @function | ||
* @name authHeader | ||
* @description Get Auth header | ||
* @returns authheader AuthHeader | ||
*/ | ||
var authHeader = function () { | ||
@@ -383,10 +408,10 @@ if (c === null || c === void 0 ? void 0 : c.authState) { | ||
else { | ||
return null; | ||
return "Bearer "; | ||
} | ||
}; | ||
/** | ||
* Get Auth user State | ||
* | ||
* @returns authuser state | ||
*/ | ||
/** @function | ||
*@name authUser | ||
*@description Get Auth user State | ||
*@returns authuser state | ||
*/ | ||
var authUser = function () { | ||
@@ -396,6 +421,7 @@ return c.authState.authState; | ||
/** | ||
* Get If the user is Authenticated | ||
* | ||
* @returns true | false | ||
*/ | ||
*@function | ||
*@name isAuthenticated | ||
*@description Get If the user is Authenticated | ||
*@returns true | false | ||
*/ | ||
var isAuthenticated = function () { | ||
@@ -411,3 +437,3 @@ if ((c === null || c === void 0 ? void 0 : c.authState.authToken) && (c === null || c === void 0 ? void 0 : c.authState.expireAt)) { | ||
expireAt: null, | ||
authState: null | ||
authState: null, | ||
}); | ||
@@ -422,8 +448,7 @@ return false; | ||
/** | ||
* Sign In Function | ||
* | ||
* @param signInConfig | ||
* | ||
* @returns true if sign-in else false | ||
*/ | ||
*@function | ||
*@name signIn | ||
*@param signInConfig | ||
*@returns true if sign-in else false | ||
*/ | ||
var signIn = function (signInConfig) { | ||
@@ -447,6 +472,6 @@ var token = signInConfig.token, tokenType = signInConfig.tokenType, authState = signInConfig.authState, expiresIn = signInConfig.expiresIn; | ||
/** | ||
* Sign Out Function | ||
* | ||
* @returns true | false | ||
*/ | ||
*@function | ||
*@name signOut | ||
*@returns true | false | ||
*/ | ||
var signOut = function () { | ||
@@ -471,6 +496,13 @@ try { | ||
/** | ||
* Authentication SignIn Hook | ||
* | ||
* @returns - Sign In function | ||
*/ | ||
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com> | ||
*@fileoverview Sign In functionality | ||
*@copyright Arkadip Bhattacharya 2020 | ||
*@license Apache-2.0 | ||
*/ | ||
/** | ||
*@function | ||
*@name useSignIn | ||
*@description Authentication SignIn Hook | ||
*@returns - Sign In function | ||
*/ | ||
function useSignIn() { | ||
@@ -497,3 +529,19 @@ var context = React.useContext(AuthContext); | ||
/** | ||
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com> | ||
*@fileoverview Sign Out functionality | ||
*@copyright Arkadip Bhattacharya 2020 | ||
*@license Apache-2.0 | ||
*/ | ||
/** | ||
*@public | ||
*@function | ||
*@name useSignOut | ||
*@description Signout Hook | ||
*/ | ||
function useSignOut() { | ||
/** | ||
*A constant c. | ||
*@kind constant | ||
*/ | ||
var c = React.useContext(AuthContext); | ||
@@ -529,2 +577,5 @@ return function () { | ||
/** | ||
* | ||
*/ | ||
function useAuthHeader() { | ||
@@ -542,17 +593,13 @@ var c = React.useContext(AuthContext); | ||
/* | ||
* 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. | ||
*/ | ||
/** | ||
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com> | ||
*@fileoverview Check User is authenticated or not | ||
*@copyright Arkadip Bhattacharya 2020 | ||
*@license Apache-2.0 | ||
*/ | ||
/** | ||
*@function | ||
*@name useIsAuthenticated | ||
*@description check weather user is authenticated or not | ||
*/ | ||
function useIsAuthenticated() { | ||
@@ -570,3 +617,3 @@ var context = React.useContext(AuthContext); | ||
expireAt: null, | ||
authState: null | ||
authState: null, | ||
}); | ||
@@ -582,2 +629,9 @@ return false; | ||
/** | ||
* @public | ||
* @function | ||
* @name withSignIn | ||
* @description Inject sign in functionality inside the Component's Prop | ||
* @param Component | ||
*/ | ||
function withSignIn(Component) { | ||
@@ -608,2 +662,9 @@ return function (props) { | ||
/** | ||
* @public | ||
* @function | ||
* @name withSignOut | ||
* @description Inject sign Out functionality inside the Component's Prop | ||
* @param Component | ||
*/ | ||
function withSignOut(Component) { | ||
@@ -631,2 +692,8 @@ return function (props) { | ||
/** | ||
* @function | ||
* @name withAuthUser | ||
* @description Inject Authenticated User's state inside the Component's Prop | ||
* @param Component | ||
*/ | ||
function withAuthUser(Component) { | ||
@@ -638,2 +705,15 @@ return function (props) { | ||
/** | ||
*@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 withAuthHeader(Component) { | ||
@@ -652,16 +732,14 @@ return function (props) { | ||
/* | ||
* 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. | ||
/** | ||
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com> | ||
*@fileoverview Authentication status | ||
*@copyright Arkadip Bhattacharya 2020 | ||
*@license Apache-2.0 | ||
*/ | ||
/** | ||
* @public | ||
* @function | ||
* @name withIsAuthenticated | ||
* @description Inject Authentication status inside the Component's Prop | ||
* @param Component | ||
*/ | ||
@@ -680,3 +758,3 @@ function withIsAuthenticated(Component) { | ||
expireAt: null, | ||
authState: null | ||
authState: null, | ||
}); | ||
@@ -683,0 +761,0 @@ return React.createElement(Component, __assign({}, props, { isAuth: false })); |
@@ -5,2 +5,7 @@ import { createContext, useState, useEffect, createElement, useContext } from 'react'; | ||
/** | ||
* @class TokenObject | ||
* | ||
* Stores and retrieve Token | ||
*/ | ||
var TokenObject = /** @class */ (function () { | ||
@@ -31,6 +36,6 @@ /** | ||
* | ||
* @returns TokenInterface | ||
* @return TokenInterface | ||
*/ | ||
TokenObject.prototype.initialToken = function () { | ||
if (this.authStorageType === "cookie") { | ||
if (this.authStorageType === 'cookie') { | ||
return this.initialCookieToken(); | ||
@@ -44,7 +49,7 @@ } | ||
* Get the Initial Token from Cookie | ||
* If the React App uses Cookie for storing Auth info, this Function is called | ||
* If the React App uses Cookie for storing Auth info | ||
* | ||
* Called from this.initialToken | ||
* | ||
* @returns TokenInterface | ||
* @return TokenInterface | ||
*/ | ||
@@ -60,7 +65,8 @@ TokenObject.prototype.initialCookieToken = function () { | ||
* Get the Initial Token from LocalStorage | ||
* If the React App uses LocalStorage for storing Auth info, this Function is called | ||
* If the React App uses LocalStorage for storing Auth info, | ||
* this Function is called | ||
* | ||
* Called from this.initialToken | ||
* | ||
* @returns TokenInterface | ||
* @return TokenInterface | ||
*/ | ||
@@ -77,3 +83,4 @@ TokenObject.prototype.initialLSToken = function () { | ||
* | ||
* If the tokens are valid, then it response TokenObject with auth Information | ||
* If the tokens are valid, | ||
* then it response TokenObject with auth Information | ||
* Else it response TokenObject with null | ||
@@ -86,3 +93,3 @@ * | ||
* | ||
* @returns TokenInterface | ||
* @return TokenInterface | ||
* | ||
@@ -95,10 +102,25 @@ */ | ||
var authState = JSON.parse(stateCookie); | ||
return { authToken: authToken, authTokenType: authTokenType, expireAt: expiresAt, authState: authState }; | ||
return { | ||
authToken: authToken, | ||
authTokenType: authTokenType, | ||
expireAt: expiresAt, | ||
authState: authState | ||
}; | ||
} | ||
catch (e) { | ||
return { authToken: null, authTokenType: null, expireAt: null, authState: null }; | ||
return { | ||
authToken: null, | ||
authTokenType: null, | ||
expireAt: null, | ||
authState: null, | ||
}; | ||
} | ||
} | ||
else { | ||
return { authToken: null, authTokenType: null, expireAt: null, authState: null }; | ||
return { | ||
authToken: null, | ||
authTokenType: null, | ||
expireAt: null, | ||
authState: null, | ||
}; | ||
} | ||
@@ -135,3 +157,3 @@ }; | ||
TokenObject.prototype.setToken = function (authToken, authTokenType, expiresAt, authState) { | ||
if (this.authStorageType === "cookie") { | ||
if (this.authStorageType === 'cookie') { | ||
this.setCookieToken(authToken, authTokenType, expiresAt, authState); | ||
@@ -156,3 +178,3 @@ } | ||
domain: this.cookieDomain, | ||
secure: this.cookieSecure | ||
secure: this.cookieSecure, | ||
}); | ||
@@ -162,3 +184,3 @@ Cookies.set(this.authStorageTypeName, authTokenType, { | ||
domain: this.cookieDomain, | ||
secure: this.cookieSecure | ||
secure: this.cookieSecure, | ||
}); | ||
@@ -168,3 +190,3 @@ Cookies.set(this.authTimeStorageName, expiresAt, { | ||
domain: this.cookieDomain, | ||
secure: this.cookieSecure | ||
secure: this.cookieSecure, | ||
}); | ||
@@ -174,3 +196,3 @@ Cookies.set(this.stateStorageName, authState, { | ||
domain: this.cookieDomain, | ||
secure: this.cookieSecure | ||
secure: this.cookieSecure, | ||
}); | ||
@@ -196,3 +218,3 @@ }; | ||
TokenObject.prototype.removeToken = function () { | ||
if (this.authStorageType === "cookie") { | ||
if (this.authStorageType === 'cookie') { | ||
this.removeCookieToken(); | ||
@@ -228,5 +250,5 @@ } | ||
authToken: null, | ||
expireAt: null | ||
expireAt: null, | ||
}, | ||
setAuthState: function () { } | ||
setAuthState: function () { }, | ||
}); | ||
@@ -243,8 +265,11 @@ /** | ||
* @param stateStorageName | ||
* | ||
* @return Functional Component | ||
*/ | ||
var AuthProvider = function (_a) { | ||
var children = _a.children, authStorageType = _a.authStorageType, authStorageName = _a.authStorageName, authTimeStorageName = _a.authTimeStorageName, stateStorageName = _a.stateStorageName, cookieDomain = _a.cookieDomain, cookieSecure = _a.cookieSecure; | ||
if (authStorageType === "cookie") { | ||
if (authStorageType === 'cookie') { | ||
if (!cookieDomain) { | ||
throw new Error("authStorageType 'cookie' requires 'cookieDomain' and 'cookieSecure' in AuthProvider"); | ||
throw new Error('authStorageType \'cookie\' ' + | ||
'requires \'cookieDomain\' and \'cookieSecure\' in AuthProvider'); | ||
} | ||
@@ -258,3 +283,3 @@ } | ||
cookieSecure: cookieSecure, | ||
stateStorageName: stateStorageName | ||
stateStorageName: stateStorageName, | ||
}); | ||
@@ -268,7 +293,7 @@ var _b = useState(tokenObject.initialToken()), authState = _b[0], setAuthState = _b[1]; | ||
AuthProvider.defaultProps = { | ||
authStorageType: "cookie", | ||
authStorageName: "_auth_token", | ||
authTimeStorageName: "_auth_time", | ||
stateStorageName: "_auth_state", | ||
cookieSecure: true | ||
authStorageType: 'cookie', | ||
authStorageName: '_auth_token', | ||
authTimeStorageName: '_auth_time', | ||
stateStorageName: '_auth_state', | ||
cookieSecure: true, | ||
}; | ||
@@ -298,3 +323,3 @@ var AuthContextConsumer = AuthContext.Consumer; | ||
expireAt: null, | ||
authState: null | ||
authState: null, | ||
}); | ||
@@ -311,8 +336,8 @@ return false; | ||
return isAuth() ? | ||
component | ||
? createElement(component, renderProps) | ||
: render | ||
? render(renderProps) | ||
: null | ||
: createElement(Redirect, { to: loginPath }); | ||
component ? | ||
createElement(component, renderProps) : | ||
render ? | ||
render(renderProps) : | ||
null : | ||
createElement(Redirect, { to: loginPath }); | ||
} })); | ||
@@ -347,24 +372,24 @@ }; | ||
/* | ||
* 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. | ||
*/ | ||
/** | ||
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com> | ||
*@fileoverview Authentication | ||
*@copyright Arkadip Bhattacharya 2020 | ||
*@license Apache-2.0 | ||
*/ | ||
/** | ||
*@public | ||
*@function | ||
*@name useAuth | ||
*/ | ||
function useAuth() { | ||
/** | ||
*A constant c. | ||
*@kind constant | ||
*/ | ||
var c = useContext(AuthContext); | ||
/** | ||
* Get Auth header | ||
* | ||
* @returns authheader AuthHeader | null | ||
*/ | ||
/** @function | ||
* @name authHeader | ||
* @description Get Auth header | ||
* @returns authheader AuthHeader | ||
*/ | ||
var authHeader = function () { | ||
@@ -375,10 +400,10 @@ if (c === null || c === void 0 ? void 0 : c.authState) { | ||
else { | ||
return null; | ||
return "Bearer "; | ||
} | ||
}; | ||
/** | ||
* Get Auth user State | ||
* | ||
* @returns authuser state | ||
*/ | ||
/** @function | ||
*@name authUser | ||
*@description Get Auth user State | ||
*@returns authuser state | ||
*/ | ||
var authUser = function () { | ||
@@ -388,6 +413,7 @@ return c.authState.authState; | ||
/** | ||
* Get If the user is Authenticated | ||
* | ||
* @returns true | false | ||
*/ | ||
*@function | ||
*@name isAuthenticated | ||
*@description Get If the user is Authenticated | ||
*@returns true | false | ||
*/ | ||
var isAuthenticated = function () { | ||
@@ -403,3 +429,3 @@ if ((c === null || c === void 0 ? void 0 : c.authState.authToken) && (c === null || c === void 0 ? void 0 : c.authState.expireAt)) { | ||
expireAt: null, | ||
authState: null | ||
authState: null, | ||
}); | ||
@@ -414,8 +440,7 @@ return false; | ||
/** | ||
* Sign In Function | ||
* | ||
* @param signInConfig | ||
* | ||
* @returns true if sign-in else false | ||
*/ | ||
*@function | ||
*@name signIn | ||
*@param signInConfig | ||
*@returns true if sign-in else false | ||
*/ | ||
var signIn = function (signInConfig) { | ||
@@ -439,6 +464,6 @@ var token = signInConfig.token, tokenType = signInConfig.tokenType, authState = signInConfig.authState, expiresIn = signInConfig.expiresIn; | ||
/** | ||
* Sign Out Function | ||
* | ||
* @returns true | false | ||
*/ | ||
*@function | ||
*@name signOut | ||
*@returns true | false | ||
*/ | ||
var signOut = function () { | ||
@@ -463,6 +488,13 @@ try { | ||
/** | ||
* Authentication SignIn Hook | ||
* | ||
* @returns - Sign In function | ||
*/ | ||
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com> | ||
*@fileoverview Sign In functionality | ||
*@copyright Arkadip Bhattacharya 2020 | ||
*@license Apache-2.0 | ||
*/ | ||
/** | ||
*@function | ||
*@name useSignIn | ||
*@description Authentication SignIn Hook | ||
*@returns - Sign In function | ||
*/ | ||
function useSignIn() { | ||
@@ -489,3 +521,19 @@ var context = useContext(AuthContext); | ||
/** | ||
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com> | ||
*@fileoverview Sign Out functionality | ||
*@copyright Arkadip Bhattacharya 2020 | ||
*@license Apache-2.0 | ||
*/ | ||
/** | ||
*@public | ||
*@function | ||
*@name useSignOut | ||
*@description Signout Hook | ||
*/ | ||
function useSignOut() { | ||
/** | ||
*A constant c. | ||
*@kind constant | ||
*/ | ||
var c = useContext(AuthContext); | ||
@@ -521,2 +569,5 @@ return function () { | ||
/** | ||
* | ||
*/ | ||
function useAuthHeader() { | ||
@@ -534,17 +585,13 @@ var c = useContext(AuthContext); | ||
/* | ||
* 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. | ||
*/ | ||
/** | ||
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com> | ||
*@fileoverview Check User is authenticated or not | ||
*@copyright Arkadip Bhattacharya 2020 | ||
*@license Apache-2.0 | ||
*/ | ||
/** | ||
*@function | ||
*@name useIsAuthenticated | ||
*@description check weather user is authenticated or not | ||
*/ | ||
function useIsAuthenticated() { | ||
@@ -562,3 +609,3 @@ var context = useContext(AuthContext); | ||
expireAt: null, | ||
authState: null | ||
authState: null, | ||
}); | ||
@@ -574,2 +621,9 @@ return false; | ||
/** | ||
* @public | ||
* @function | ||
* @name withSignIn | ||
* @description Inject sign in functionality inside the Component's Prop | ||
* @param Component | ||
*/ | ||
function withSignIn(Component) { | ||
@@ -600,2 +654,9 @@ return function (props) { | ||
/** | ||
* @public | ||
* @function | ||
* @name withSignOut | ||
* @description Inject sign Out functionality inside the Component's Prop | ||
* @param Component | ||
*/ | ||
function withSignOut(Component) { | ||
@@ -623,2 +684,8 @@ return function (props) { | ||
/** | ||
* @function | ||
* @name withAuthUser | ||
* @description Inject Authenticated User's state inside the Component's Prop | ||
* @param Component | ||
*/ | ||
function withAuthUser(Component) { | ||
@@ -630,2 +697,15 @@ return function (props) { | ||
/** | ||
*@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 withAuthHeader(Component) { | ||
@@ -644,16 +724,14 @@ return function (props) { | ||
/* | ||
* 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. | ||
/** | ||
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com> | ||
*@fileoverview Authentication status | ||
*@copyright Arkadip Bhattacharya 2020 | ||
*@license Apache-2.0 | ||
*/ | ||
/** | ||
* @public | ||
* @function | ||
* @name withIsAuthenticated | ||
* @description Inject Authentication status inside the Component's Prop | ||
* @param Component | ||
*/ | ||
@@ -672,3 +750,3 @@ function withIsAuthenticated(Component) { | ||
expireAt: null, | ||
authState: null | ||
authState: null, | ||
}); | ||
@@ -675,0 +753,0 @@ return createElement(Component, __assign({}, props, { isAuth: false })); |
@@ -1,2 +0,40 @@ | ||
/*! react-auth-kit v1.2.2 | 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=function(){var t=e.useContext(i);return{authHeader:function(){return(null==t?void 0:t.authState)?t.authState.authTokenType+" "+t.authState.authToken:null},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}}}},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=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}}},t.useSignOut=function(){var t=e.useContext(i);return 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}}},t.withAuthHeader=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}))}))}},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})})); | ||
/*! react-auth-kit v1.3.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,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= | ||
/** | ||
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com> | ||
*@fileoverview Authentication | ||
*@copyright Arkadip Bhattacharya 2020 | ||
*@license Apache-2.0 | ||
*/ | ||
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}}}} | ||
/** | ||
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com> | ||
*@fileoverview Sign In functionality | ||
*@copyright Arkadip Bhattacharya 2020 | ||
*@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 "}} | ||
/** | ||
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com> | ||
*@fileoverview Check User is authenticated or not | ||
*@copyright Arkadip Bhattacharya 2020 | ||
*@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}}} | ||
/** | ||
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com> | ||
*@fileoverview Sign Out functionality | ||
*@copyright Arkadip Bhattacharya 2020 | ||
*@license Apache-2.0 | ||
*/,t.useSignOut=function(){var t=e.useContext(i);return 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}}},t.withAuthHeader= | ||
/** | ||
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com> | ||
*@fileoverview Authentication header | ||
*@copyright Arkadip Bhattacharya 2020 | ||
*@license Apache-2.0 | ||
*/ | ||
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}))}))}} | ||
/** | ||
*@author Arkadip Bhattacharya <in2arkadipb13@gmail.com> | ||
*@fileoverview Authentication status | ||
*@copyright Arkadip Bhattacharya 2020 | ||
*@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})})); |
{ | ||
"name": "react-auth-kit", | ||
"version": "1.2.2", | ||
"version": "1.3.0", | ||
"description": "Authentication Library for React", | ||
@@ -25,4 +25,4 @@ "source": "src/index.tsx", | ||
"test:unit": "jest", | ||
"test:lint": "eslint .", | ||
"fix": "eslint --fix" | ||
"test:lint": "eslint src/**/*.ts src/**/*.tsx", | ||
"fix": "eslint src/**/*.ts src/**/*.tsx --fix" | ||
}, | ||
@@ -47,13 +47,13 @@ "keywords": [ | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^15.0.0", | ||
"@rollup/plugin-node-resolve": "^9.0.0", | ||
"@rollup/plugin-commonjs": "^17.0.0", | ||
"@rollup/plugin-node-resolve": "^11.0.0", | ||
"@types/jest": "^26.0.10", | ||
"@types/js-cookie": "^2.2.6", | ||
"@types/node": "^14.6.2", | ||
"@types/react": "^16.9.48", | ||
"@types/react-dom": "^16.9.8", | ||
"@types/react": "^17.0.0", | ||
"@types/react-dom": "^17.0.0", | ||
"@types/react-router-dom": "^5.1.5", | ||
"@typescript-eslint/eslint-plugin": "^4.1.0", | ||
"@typescript-eslint/parser": "^4.1.0", | ||
"eslint": "^7.7.0", | ||
"@typescript-eslint/eslint-plugin": "^4.1.1", | ||
"@typescript-eslint/parser": "^4.1.1", | ||
"eslint": "^7.9.0", | ||
"eslint-config-google": "^0.14.0", | ||
@@ -70,3 +70,3 @@ "eslint-plugin-jest": "^24.0.0", | ||
"rollup-plugin-terser": "^7.0.0", | ||
"rollup-plugin-typescript2": "^0.27.2", | ||
"rollup-plugin-typescript2": "^0.29.0", | ||
"ts-jest": "^26.3.0", | ||
@@ -73,0 +73,0 @@ "typedoc": "^0.19.1", |
@@ -6,3 +6,3 @@ <p align="center"> | ||
<p align="center"> | ||
<em>🔑 Authenticate users in React app with Json Web Token(JWT)🔑</em> | ||
<em>🔑 Authentication Library for React Js for Token Based Auth with Json Web Token(JWT) 🔑</em> | ||
</p> | ||
@@ -34,3 +34,3 @@ | ||
* 1.98 KB Gzipped | ||
* 1.95 KB Gzipped | ||
* Build for React | ||
@@ -56,7 +56,5 @@ * Easy to Implementation | ||
Visit [https://authkit.arkadip.co](https://authkit.arkadip.co) for the complete documentation | ||
Visit [https://authkit.arkadip.me](https://authkit.arkadip.me) for the complete documentation | ||
[![ko-fi](https://www.ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/P5P61YJOH) | ||
<p align="center">— 🔑 —</p> | ||
<p align="center"><i>React Auth Kit is <a href="https://github.com/react-auth-kit/react-auth-kit/blob/master/LICENSE">Apache 2.0 License</a> code</i></p> | ||
<p align="center"><i>React Auth Kit is <a href="https://github.com/react-auth-kit/react-auth-kit/blob/master/LICENSE">Apache 2.0 License</a> code</i></p> |
77643
1502
58