react-auth-kit
Advanced tools
Comparing version 3.1.4-alpha.57 to 3.1.4-alpha.59
@@ -10,5 +10,4 @@ "use strict"; | ||
var React = _interopRequireWildcard(require("react")); | ||
var _Refresh = _interopRequireDefault(require("./Refresh")); | ||
var _AuthContext = _interopRequireDefault(require("./AuthContext")); | ||
var _hooks = require("./utils/hooks"); | ||
var _reducers = require("./utils/reducers"); | ||
var _jsxRuntime = require("react/jsx-runtime"); | ||
@@ -25,18 +24,2 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
refresh = store.refresh; | ||
if (refresh) { | ||
(0, _hooks.useInterval)(function () { | ||
var _tokenObject$value$au, _tokenObject$value$re; | ||
refresh.refreshApiCallback({ | ||
authToken: (_tokenObject$value$au = tokenObject.value.auth) === null || _tokenObject$value$au === void 0 ? void 0 : _tokenObject$value$au.token, | ||
authUserState: tokenObject.value.userState, | ||
refreshToken: (_tokenObject$value$re = tokenObject.value.refresh) === null || _tokenObject$value$re === void 0 ? void 0 : _tokenObject$value$re.token | ||
}).then(function (result) { | ||
if (result.isSuccess) { | ||
tokenObject.set((0, _reducers.doRefresh)(result)); | ||
} else { | ||
tokenObject.set((0, _reducers.doSignOut)()); | ||
} | ||
}).catch(function () {}); | ||
}, tokenObject.value.isSignIn ? refresh.interval : null); | ||
} | ||
return (0, _jsxRuntime.jsx)(_AuthContext.default.Provider, { | ||
@@ -50,5 +33,9 @@ value: { | ||
}, | ||
children: children | ||
children: refresh ? (0, _jsxRuntime.jsx)(_Refresh.default, { | ||
refresh: refresh, | ||
store: tokenObject, | ||
children: children | ||
}) : children | ||
}); | ||
} | ||
var _default = exports.default = AuthProvider; |
import type React from 'react'; | ||
/** | ||
* Payload for Refresh token | ||
* Payload for Refresh token False | ||
*/ | ||
export interface RefreshTokenActionPayload<T> { | ||
type RefreshTokenActionPayloadFalse = { | ||
/** | ||
* If the refresh operation is successful or not | ||
* | ||
* If the isSuceess is `true`, then the `token` and other items will be | ||
* replaced with the new network response | ||
* | ||
* If the isSuceess is `false`, then everything will be wiped and user will | ||
* be sgined out | ||
*/ | ||
isSuccess: false; | ||
}; | ||
/** | ||
* Payload for Refresh token Success True | ||
*/ | ||
export type RefreshTokenActionPayloadTrue<T> = { | ||
/** | ||
* New Auth token from the network response | ||
@@ -22,7 +37,2 @@ */ | ||
newAuthUserState?: T | null; | ||
} | ||
/** | ||
* Refresh Token Callback Response | ||
*/ | ||
interface RefreshTokenCallbackResponse<T> extends RefreshTokenActionPayload<T> { | ||
/** | ||
@@ -35,7 +45,11 @@ * If the refresh operation is successful or not | ||
* If the isSuceess is `false`, then everything will be wiped and user will | ||
* be sgined out | ||
* be signed out | ||
*/ | ||
isSuccess: boolean; | ||
} | ||
}; | ||
/** | ||
* Response type by the refrsh token | ||
*/ | ||
type RefreshTokenCallbackResponse<T> = RefreshTokenActionPayloadTrue<T> | RefreshTokenActionPayloadFalse; | ||
/** | ||
* | ||
@@ -42,0 +56,0 @@ */ |
@@ -8,4 +8,4 @@ "use strict"; | ||
exports.default = createStore; | ||
var _errors = require("./errors"); | ||
var _RxTokenObject = _interopRequireDefault(require("./RxTokenObject")); | ||
var _errors = require("./errors"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -12,0 +12,0 @@ function createStore(params) { |
@@ -20,3 +20,2 @@ "use strict"; | ||
return function () { | ||
console.log("React Auth Kit - useIsAuthenticated called"); | ||
if (value.auth && new Date(value.auth.expiresAt) > new Date()) { | ||
@@ -23,0 +22,0 @@ return true; |
@@ -8,5 +8,5 @@ "use strict"; | ||
exports.default = void 0; | ||
var _errors = require("../errors"); | ||
var _reducers = require("../utils/reducers"); | ||
var _AuthContext = require("../AuthContext"); | ||
var _reducers = require("../utils/reducers"); | ||
var _errors = require("../errors"); | ||
function useSignIn() { | ||
@@ -31,2 +31,3 @@ var context = (0, _AuthContext.useReactAuthKit)(); | ||
context.set((0, _reducers.doSignIn)(signInConfig)); | ||
redirectAfterSignin(signInConfig.navigateTo); | ||
return true; | ||
@@ -33,0 +34,0 @@ } else { |
@@ -8,5 +8,5 @@ "use strict"; | ||
exports.default = void 0; | ||
var _AuthContext = require("../AuthContext"); | ||
var _errors = require("../errors"); | ||
var _reducers = require("../utils/reducers"); | ||
var _AuthContext = require("../AuthContext"); | ||
function useSignOut() { | ||
@@ -13,0 +13,0 @@ var context = (0, _AuthContext.useReactAuthKit)(); |
{ | ||
"name": "react-auth-kit", | ||
"version": "3.1.4-alpha.57+f862ddc5", | ||
"version": "3.1.4-alpha.59+c0a3b210", | ||
"description": "Authentication Library for React, which makes Token based auth very easy", | ||
@@ -75,3 +75,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "f862ddc5f472ff3ca5b5c1c693048c634c0e3e7c" | ||
"gitHead": "c0a3b210faae45877697161014e45452a6bcfd81" | ||
} |
@@ -9,4 +9,4 @@ "use strict"; | ||
var _jsCookie = _interopRequireDefault(require("js-cookie")); | ||
var _deepEqual = _interopRequireDefault(require("deep-equal")); | ||
var _rxjs = require("rxjs"); | ||
var _deepEqual = _interopRequireDefault(require("deep-equal")); | ||
var _errors = require("./errors"); | ||
@@ -49,3 +49,3 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
if (value.auth === null) { | ||
callback(value); | ||
callback(); | ||
} | ||
@@ -57,3 +57,5 @@ }); | ||
this.log(`Set Function Old Data`, this.value); | ||
let obj = this.value; | ||
let obj = { | ||
...this.value | ||
}; | ||
if (data.userState !== undefined) { | ||
@@ -116,3 +118,4 @@ obj.userState = data.userState; | ||
'expiresAt': refreshExpireTime | ||
} | ||
}, | ||
isUsingRefreshToken: true | ||
}; | ||
@@ -148,3 +151,3 @@ } else { | ||
if (!(0, _deepEqual.default)(this.value, obj)) { | ||
this.log("Updating the value in the Set Function"); | ||
this.log('Updating the value in the Set Function'); | ||
this.authValue = obj; | ||
@@ -253,3 +256,3 @@ this.authSubject.next(obj); | ||
} | ||
if (refresh) { | ||
if (this.isUsingRefreshToken && refresh) { | ||
if (!!auth && !!authState) { | ||
@@ -268,3 +271,3 @@ this.log('checkTokenExist - Returning auth and refrsh'); | ||
userState: authState, | ||
isUsingRefreshToken: this.isUsingRefreshToken, | ||
isUsingRefreshToken: !!this.isUsingRefreshToken, | ||
isSignIn: true | ||
@@ -271,0 +274,0 @@ }; |
@@ -71,3 +71,3 @@ /** | ||
*/ | ||
userState: T; | ||
userState: T | null; | ||
/** | ||
@@ -98,3 +98,3 @@ * Boolean value to know if the user is signed in or not | ||
}; | ||
type AuthKitStateInterfaceSignedInAuthToken<T> = AuthKitStateInterfaceSignedIn<T> | AuthKitStateInterfaceSignedOut; | ||
export type AuthKitStateInterfaceAuthToken<T> = AuthKitStateInterfaceSignedIn<T> | AuthKitStateInterfaceSignedOut; | ||
/** | ||
@@ -145,3 +145,3 @@ * Auth State Object | ||
*/ | ||
export type AuthKitStateInterface<T> = AuthKitStateInterfaceSignedInAuthToken<T> & AuthKitStateInterfaceRefresh; | ||
export type AuthKitStateInterface<T> = AuthKitStateInterfaceAuthToken<T> & AuthKitStateInterfaceRefresh; | ||
export {}; |
@@ -15,3 +15,3 @@ /** | ||
import type { SignInActionPayload } from '../types'; | ||
import type { RefreshTokenActionPayload } from '../createRefresh'; | ||
import type { RefreshTokenActionPayloadTrue } from '../createRefresh'; | ||
import type { AuthKitSetState } from '../RxTokenObject'; | ||
@@ -72,3 +72,3 @@ /** | ||
*/ | ||
export declare function doRefresh<T>(refreshTokenParam: RefreshTokenActionPayload<T>): AuthKitSetState<T>; | ||
export declare function doRefresh<T>(refreshTokenParam: RefreshTokenActionPayloadTrue<T>): AuthKitSetState<T>; | ||
/** | ||
@@ -75,0 +75,0 @@ * Do sign out reducer |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
68448
38
2041