react-auth-kit
Advanced tools
Comparing version 3.1.4-alpha.15 to 3.1.4-alpha.16
import type { Context } from 'react'; | ||
import TokenObject from './RxTokenObject'; | ||
import Router from './route'; | ||
interface ReactAuthKitContextConfig { | ||
fallbackPath?: string; | ||
} | ||
interface ReactAuthKitContext<T> { | ||
token: TokenObject<T>; | ||
router?: Router; | ||
config: ReactAuthKitContextConfig; | ||
} | ||
@@ -19,3 +23,14 @@ declare const AuthKitContext: Context<ReactAuthKitContext<unknown>>; | ||
export declare function useReactAuthKit(): TokenObject<unknown>; | ||
/** | ||
* | ||
* @internal | ||
* @returns Router Object from the context | ||
* | ||
*/ | ||
export declare function useReactAuthKitRouter(): Router | undefined; | ||
/** | ||
* @internal | ||
* @returns React Auth Kit configurations | ||
*/ | ||
export declare function useReactAuthKitConfig(): ReactAuthKitContextConfig; | ||
export default AuthKitContext; |
@@ -9,2 +9,3 @@ "use strict"; | ||
exports.useReactAuthKit = useReactAuthKit; | ||
exports.useReactAuthKitConfig = useReactAuthKitConfig; | ||
exports.useReactAuthKitRouter = useReactAuthKitRouter; | ||
@@ -35,2 +36,9 @@ var _react = require("react"); | ||
} | ||
function useReactAuthKitConfig() { | ||
var context = (0, _react.useContext)(AuthKitContext); | ||
if (context === null) { | ||
throw new _errors.AuthError('Auth Provider is missing. ' + 'Make sure, you are using this component inside the auth provider.'); | ||
} | ||
return context.config; | ||
} | ||
var _default = exports.default = AuthKitContext; |
@@ -21,2 +21,7 @@ import * as React from 'react'; | ||
/** | ||
* Fallback Path | ||
* The path to redirect if signed out | ||
*/ | ||
fallbackPath?: string; | ||
/** | ||
* React Component. | ||
@@ -51,3 +56,3 @@ * Effectively your entine application | ||
*/ | ||
declare function AuthProvider<T>({ store, router, children, }: AuthProviderProps<T>): ReturnType<React.FC>; | ||
declare function AuthProvider<T>({ store, router, fallbackPath, children, }: AuthProviderProps<T>): ReturnType<React.FC>; | ||
export default AuthProvider; |
@@ -20,2 +20,3 @@ "use strict"; | ||
router = _ref.router, | ||
fallbackPath = _ref.fallbackPath, | ||
children = _ref.children; | ||
@@ -43,3 +44,6 @@ var tokenObject = store.tokenObject, | ||
token: tokenObject, | ||
router: router | ||
router: router, | ||
config: { | ||
fallbackPath: fallbackPath | ||
} | ||
}, | ||
@@ -46,0 +50,0 @@ children: children |
@@ -9,7 +9,9 @@ "use strict"; | ||
var _AuthContext = require("../AuthContext"); | ||
var _utils = require("../utils/utils"); | ||
var _useIsAuthenticated = _interopRequireDefault(require("./useIsAuthenticated")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function useAuthHeader() { | ||
var _useReactAuthKit = (0, _AuthContext.useReactAuthKit)(), | ||
value = _useReactAuthKit.value; | ||
if (!!value.auth && (0, _utils.isAuthenticated)(value)) { | ||
var isAuthenticated = (0, _useIsAuthenticated.default)(); | ||
if (!!value.auth && isAuthenticated) { | ||
return "".concat(value.auth.type, " ").concat(value.auth.token); | ||
@@ -16,0 +18,0 @@ } else { |
@@ -9,7 +9,9 @@ "use strict"; | ||
var _AuthContext = require("../AuthContext"); | ||
var _utils = require("../utils/utils"); | ||
var _useIsAuthenticated = _interopRequireDefault(require("./useIsAuthenticated")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function useAuthUser() { | ||
var _useReactAuthKit = (0, _AuthContext.useReactAuthKit)(), | ||
value = _useReactAuthKit.value; | ||
if ((0, _utils.isAuthenticated)(value)) { | ||
var isAuthenticated = (0, _useIsAuthenticated.default)(); | ||
if (isAuthenticated) { | ||
return value.userState; | ||
@@ -16,0 +18,0 @@ } else { |
@@ -9,8 +9,19 @@ "use strict"; | ||
var _AuthContext = require("../AuthContext"); | ||
var _utils = require("../utils/utils"); | ||
function useIsAuthenticated() { | ||
var _useReactAuthKit = (0, _AuthContext.useReactAuthKit)(), | ||
value = _useReactAuthKit.value; | ||
return (0, _utils.isAuthenticated)(value); | ||
var router = (0, _AuthContext.useReactAuthKitRouter)(); | ||
var _useReactAuthKitConfi = (0, _AuthContext.useReactAuthKitConfig)(), | ||
fallbackPath = _useReactAuthKitConfi.fallbackPath; | ||
var navigate = router ? router.useNavigate() : null; | ||
if (value.auth) { | ||
return new Date(value.auth.expiresAt) > new Date(); | ||
} | ||
if (router && navigate && fallbackPath) { | ||
navigate({ | ||
to: fallbackPath | ||
}); | ||
} | ||
return false; | ||
} | ||
var _default = exports.default = useIsAuthenticated; |
{ | ||
"name": "react-auth-kit", | ||
"version": "3.1.4-alpha.15+edfdd2f5", | ||
"version": "3.1.4-alpha.16+5eccfe99", | ||
"description": "Authentication Library for React, which makes Token based auth very easy", | ||
@@ -74,3 +74,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "edfdd2f54a3524a8f8745939d6749ee76c7e0bdc" | ||
"gitHead": "5eccfe9931e569859a2d9ad93281a6b7b7dbe2fc" | ||
} |
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
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
64684
1949