react-auth-kit
Advanced tools
Comparing version 1.4.16-0 to 1.4.16
@@ -7,3 +7,3 @@ # Changelog | ||
## [Unreleased] | ||
## [1.4.16] - 2021-08-03 | ||
### Fix: | ||
@@ -10,0 +10,0 @@ - On page refresh, the cookies are removed automatically ([#473](#473))([676f68b](676f68bc68de07e078b4e1ea6a28040abc2989dc)) |
@@ -1,2 +0,2 @@ | ||
/*! react-auth-kit v1.4.16-0 | Apache-2.0 */ | ||
/*! react-auth-kit v1.4.16 | Apache-2.0 */ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("js-cookie"),require("react-router-dom")):"function"==typeof define&&define.amd?define(["exports","react","js-cookie","react-router-dom"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactAuthKit={},e.React,e.Cookies,e.ReactRouterDOM)}(this,(function(e,t,r,o){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function i(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var a,s=i(t),u=n(r),h=s.createContext(null),l=h.Consumer,f=function(){function e(e,t,r,o,n){this.authStorageType=t,this.authStorageName=e,this.authTimeStorageName=e+"_storage",this.stateStorageName=e+"_state",this.refreshTokenName=r,this.cookieDomain=o,this.cookieSecure=n,this.authStorageTypeName=this.authStorageName+"_type",this.isUsingRefreshToken=!!this.refreshTokenName,this.refreshTokenTimeName=this.refreshTokenName?this.refreshTokenName+"_time":null}return e.prototype.initialToken=function(){return"cookie"===this.authStorageType?this.initialCookieToken_():this.initialLSToken_()},e.prototype.initialCookieToken_=function(){var e=u.default.get(this.authStorageName),t=u.default.get(this.authStorageTypeName),r=u.default.get(this.authTimeStorageName),o=u.default.get(this.stateStorageName),n=this.isUsingRefreshToken&&null!=this.refreshTokenName?u.default.get(this.refreshTokenName):null,i=this.isUsingRefreshToken&&null!=this.refreshTokenTimeName?u.default.get(this.refreshTokenTimeName):null;return this.checkTokenExist(e,t,r,o,n,i)},e.prototype.initialLSToken_=function(){var e=localStorage.getItem(this.authStorageName),t=localStorage.getItem(this.authStorageTypeName),r=localStorage.getItem(this.authTimeStorageName),o=localStorage.getItem(this.stateStorageName),n=this.isUsingRefreshToken&&null!=this.refreshTokenName?localStorage.getItem(this.refreshTokenName):null,i=this.isUsingRefreshToken&&null!=this.refreshTokenTimeName?localStorage.getItem(this.refreshTokenTimeName):null;return this.checkTokenExist(e,t,r,o,n,i)},e.prototype.checkTokenExist=function(e,t,r,o,n,i){if(!(e&&t&&r&&o))return{authToken:null,authTokenType:null,isUsingRefreshToken:this.isUsingRefreshToken,refreshToken:null,expireAt:null,authState:null,refreshTokenExpireAt:null,isSignIn:!1};var a=new Date(r);try{var s=JSON.parse(o);return{authToken:e,authTokenType:t,isUsingRefreshToken:this.isUsingRefreshToken,refreshToken:this.isUsingRefreshToken&&n?n:null,refreshTokenExpireAt:this.isUsingRefreshToken&&i?new Date(i):null,expireAt:a,authState:s,isSignIn:!0}}catch(e){return{authToken:null,authTokenType:null,isUsingRefreshToken:this.isUsingRefreshToken,refreshToken:null,expireAt:null,authState:null,refreshTokenExpireAt:null,isSignIn:!1}}},e.prototype.syncTokens=function(e){void 0===e.authToken||null===e.authTokenType||null===e.authToken||null===e.expireAt||null===e.authState?this.removeToken():this.setToken(e.authToken,e.authTokenType,e.refreshToken,e.refreshTokenExpireAt,e.expireAt,e.authState)},e.prototype.setToken=function(e,t,r,o,n,i){"cookie"===this.authStorageType?this.setCookieToken_(e,t,r,n,o,i):this.setLSToken_(e,t,r,n,o,i)},e.prototype.setCookieToken_=function(e,t,r,o,n,i){u.default.set(this.authStorageName,e,{expires:o,domain:this.cookieDomain,secure:this.cookieSecure}),u.default.set(this.authStorageTypeName,t,{expires:o,domain:this.cookieDomain,secure:this.cookieSecure}),u.default.set(this.authTimeStorageName,o.toISOString(),{expires:o,domain:this.cookieDomain,secure:this.cookieSecure}),u.default.set(this.stateStorageName,JSON.stringify(i),{expires:o,domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenName&&r&&u.default.set(this.refreshTokenName,r,{expires:o,domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenTimeName&&n&&u.default.set(this.refreshTokenTimeName,n.toISOString(),{expires:o,domain:this.cookieDomain,secure:this.cookieSecure})},e.prototype.setLSToken_=function(e,t,r,o,n,i){localStorage.setItem(this.authStorageName,e),localStorage.setItem(this.authStorageTypeName,t),localStorage.setItem(this.authTimeStorageName,o.toISOString()),localStorage.setItem(this.stateStorageName,JSON.stringify(i)),this.isUsingRefreshToken&&this.refreshTokenName&&r&&localStorage.setItem(this.refreshTokenName,r),this.isUsingRefreshToken&&this.refreshTokenTimeName&&n&&localStorage.setItem(this.refreshTokenTimeName,n.toISOString())},e.prototype.removeToken=function(){"cookie"===this.authStorageType?this.removeCookieToken_():this.removeLSToken_()},e.prototype.removeCookieToken_=function(){u.default.remove(this.authStorageName,{domain:this.cookieDomain,secure:this.cookieSecure}),u.default.remove(this.authTimeStorageName,{domain:this.cookieDomain,secure:this.cookieSecure}),u.default.remove(this.authStorageTypeName,{domain:this.cookieDomain,secure:this.cookieSecure}),u.default.remove(this.stateStorageName,{domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenName&&u.default.remove(this.refreshTokenName,{domain:this.cookieDomain,secure:this.cookieSecure}),this.isUsingRefreshToken&&this.refreshTokenTimeName&&u.default.remove(this.refreshTokenTimeName,{domain:this.cookieDomain,secure:this.cookieSecure})},e.prototype.removeLSToken_=function(){localStorage.removeItem(this.authStorageName),localStorage.removeItem(this.authTimeStorageName),localStorage.removeItem(this.authStorageTypeName),localStorage.removeItem(this.stateStorageName),this.isUsingRefreshToken&&this.refreshTokenName&&localStorage.removeItem(this.refreshTokenName),this.isUsingRefreshToken&&this.refreshTokenTimeName&&localStorage.removeItem(this.refreshTokenTimeName)},e}(),c=function(){return(c=Object.assign||function(e){for(var t,r=1,o=arguments.length;r<o;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e}).apply(this,arguments)};function m(e,t){switch(t.type){case a.SignIn:return t.payload.refresh?c(c({},e),{authToken:t.payload.auth.token,authTokenType:t.payload.auth.type,expireAt:t.payload.auth.expiresAt,authState:t.payload.userState,refreshToken:t.payload.refresh.token,refreshTokenExpireAt:t.payload.refresh.expiresAt,isSignIn:!0}):c(c({},e),{authToken:t.payload.auth.token,authTokenType:t.payload.auth.type,expireAt:t.payload.auth.expiresAt,authState:t.payload.userState,refreshToken:null,refreshTokenExpireAt:null,isSignIn:!0});case a.SignOut:return c(c({},e),{authToken:null,authTokenType:null,expireAt:null,authState:null,refreshToken:null,refreshTokenExpireAt:null,isSignIn:!1});default:return e}}function k(e){return{type:a.SignIn,payload:e}}function T(){return{type:a.SignOut}}!function(e){e[e.SignIn=0]="SignIn",e[e.SignOut=1]="SignOut"}(a||(a={}));var p=function(e){var t=e.children,r=e.authType,o=e.authName,n=e.refreshToken,i=e.cookieDomain,a=e.cookieSecure;if("cookie"===r&&!i)throw new Error("authType 'cookie' requires 'cookieDomain' and 'cookieSecure' props in AuthProvider");var u=new f(o,r,n?o+"_refresh":null,i,a),l=s.useReducer(m,u.initialToken()),c=l[0],k=l[1];return s.useEffect((function(){u.syncTokens(c)}),[c]),s.createElement(h.Provider,{value:{authState:c,dispatch:k}},t)};var d=function(e){if(this.context=e,!this.context.authState.isUsingRefreshToken)throw new Error("The app doesn't implement 'refreshToken' feature.\nSo you have to implement refresh token feature from 'AuthProvider' before using it.")};p.defaultProps={cookieDomain:window.location.hostname,cookieSecure:"https:"===window.location.protocol},e.AuthProvider=p,e.PrivateRoute=function(e){var t=s.useContext(h);if(null===t)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");var r=e.component,n=e.loginPath,i=e.strict,a=e.sensitive,u=e.exact,l=e.path,f=e.location,c=e.render;return s.createElement(o.Route,{location:f,path:l,exact:u,sensitive:a,strict:i,render:function(e){return t.authState.authToken&&t.authState.expireAt&&(new Date(t.authState.expireAt)>new Date||(t.dispatch(T()),0))?r?s.createElement(r,e):c?c(e):null:s.createElement(o.Redirect,{to:n})}})},e.useAuthHeader=function(){var e=s.useContext(h);if(null===e)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return function(){return(null==e?void 0:e.authState)?e.authState.authTokenType+" "+e.authState.authToken:""}},e.useAuthUser=function(){var e=s.useContext(h);if(null===e)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return function(){return e.authState.authState}},e.useIsAuthenticated=function(){var e=s.useContext(h);if(null===e)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return function(){return!(!(null==e?void 0:e.authState.authToken)||!(null==e?void 0:e.authState.expireAt))&&(new Date(e.authState.expireAt)>new Date||(e.dispatch(T()),!1))}},e.useRefreshToken=function(){var e=s.useContext(h);if(null===e)throw new Error("Auth Provider is missing. Please add the AuthProvider before Router");return new d(e)},e.useSignIn= | ||
@@ -3,0 +3,0 @@ /** |
{ | ||
"name": "react-auth-kit", | ||
"version": "1.4.16-0", | ||
"version": "1.4.16", | ||
"description": "Authentication Library for React, which makes Token based auth very easy", | ||
@@ -54,3 +54,3 @@ "source": "src/index.tsx", | ||
"@types/js-cookie": "^2.2.7", | ||
"@types/node": "^16.4.7", | ||
"@types/node": "^16.4.10", | ||
"@types/react": "^17.0.15", | ||
@@ -62,3 +62,3 @@ "@types/react-dom": "^17.0.9", | ||
"codecov": "^3.8.3", | ||
"eslint": "^7.31.0", | ||
"eslint": "^7.32.0", | ||
"eslint-config-google": "^0.14.0", | ||
@@ -80,3 +80,3 @@ "eslint-plugin-jest": "^24.4.0", | ||
"tslib": "^2.3.0", | ||
"typedoc": "^0.21.4", | ||
"typedoc": "^0.21.5", | ||
"typescript": "^4.3.5", | ||
@@ -83,0 +83,0 @@ "utility-types": "^3.10.0" |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
400879
2