react-auth-kit
Advanced tools
Comparing version 3.1.3 to 3.1.4-alpha.0
import type { Context } from 'react'; | ||
import TokenObject from './RxTokenObject'; | ||
declare const AuthKitContext: Context<TokenObject<unknown>>; | ||
import Router from './route'; | ||
interface ReactAuthKitContext<T> { | ||
token: TokenObject<T>; | ||
router?: Router; | ||
} | ||
declare const AuthKitContext: Context<ReactAuthKitContext<unknown>>; | ||
/** | ||
@@ -14,2 +19,3 @@ * | ||
export declare function useReactAuthKit(): TokenObject<unknown>; | ||
export declare function useReactAuthKitRouter(): Router | undefined; | ||
export default AuthKitContext; |
@@ -9,2 +9,3 @@ "use strict"; | ||
exports.useReactAuthKit = useReactAuthKit; | ||
exports.useReactAuthKitRouter = useReactAuthKitRouter; | ||
var _react = require("react"); | ||
@@ -25,4 +26,11 @@ var _errors = require("./errors"); | ||
} | ||
return context; | ||
return context.token; | ||
} | ||
function useReactAuthKitRouter() { | ||
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.router; | ||
} | ||
var _default = exports.default = AuthKitContext; |
import * as React from 'react'; | ||
import type { createStoreReturn } from './createStore'; | ||
import Router from './route'; | ||
/** | ||
@@ -14,2 +15,8 @@ * Props of the AuthProvider Component | ||
/** | ||
* Auth Kit Router. | ||
* | ||
* Internally used to redirect after signin and token expiration | ||
*/ | ||
router?: Router; | ||
/** | ||
* React Component. | ||
@@ -44,3 +51,3 @@ * Effectively your entine application | ||
*/ | ||
declare function AuthProvider<T>({ store, children, }: AuthProviderProps<T>): ReturnType<React.FC>; | ||
declare function AuthProvider<T>({ store, router, children, }: AuthProviderProps<T>): ReturnType<React.FC>; | ||
export default AuthProvider; |
@@ -19,2 +19,3 @@ "use strict"; | ||
var store = _ref.store, | ||
router = _ref.router, | ||
children = _ref.children; | ||
@@ -40,3 +41,6 @@ var tokenObject = store.tokenObject, | ||
return (0, _jsxRuntime.jsx)(_AuthContext.default.Provider, { | ||
value: tokenObject, | ||
value: { | ||
token: tokenObject, | ||
router: router | ||
}, | ||
children: children | ||
@@ -43,0 +47,0 @@ }); |
@@ -13,2 +13,14 @@ "use strict"; | ||
var context = (0, _AuthContext.useReactAuthKit)(); | ||
var router = (0, _AuthContext.useReactAuthKitRouter)(); | ||
var redirectAfterSignin = function redirectAfterSignin(to) { | ||
if (to) { | ||
if (router) { | ||
router.useNavigate({ | ||
to: to | ||
}); | ||
} else { | ||
throw new _errors.AuthError('Auth Provider is missing. Make sure, you' + ' are using this component inside the auth provider.'); | ||
} | ||
} | ||
}; | ||
return function (signInConfig) { | ||
@@ -26,2 +38,3 @@ if (context.value.isUsingRefreshToken) { | ||
context.set((0, _reducers.doSignIn)(signInConfig)); | ||
redirectAfterSignin(signInConfig.navigateTo); | ||
return true; | ||
@@ -28,0 +41,0 @@ } |
@@ -37,3 +37,5 @@ /** | ||
*/ | ||
declare function useSignOut(): () => void; | ||
declare function useSignOut(): ({ navigateTo }: { | ||
navigateTo?: string; | ||
}) => void; | ||
export default useSignOut; |
@@ -9,9 +9,21 @@ "use strict"; | ||
var _AuthContext = require("../AuthContext"); | ||
var _errors = require("../errors"); | ||
var _reducers = require("../utils/reducers"); | ||
function useSignOut() { | ||
var context = (0, _AuthContext.useReactAuthKit)(); | ||
return function () { | ||
var router = (0, _AuthContext.useReactAuthKitRouter)(); | ||
return function (_ref) { | ||
var navigateTo = _ref.navigateTo; | ||
context.set((0, _reducers.doSignOut)()); | ||
if (navigateTo) { | ||
if (router) { | ||
router.useNavigate({ | ||
to: navigateTo | ||
}); | ||
} else { | ||
throw new _errors.AuthError('Auth Provider is missing. Make sure, you' + ' are using this component inside the auth provider.'); | ||
} | ||
} | ||
}; | ||
} | ||
var _default = exports.default = useSignOut; |
{ | ||
"name": "react-auth-kit", | ||
"version": "3.1.3", | ||
"version": "3.1.4-alpha.0+0b0c0d01", | ||
"description": "Authentication Library for React, which makes Token based auth very easy", | ||
@@ -74,3 +74,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "0b3c26dd93193b01e03e28e2cfbd76e625d45035" | ||
"gitHead": "0b0c0d01b3ea74c548fbd907a1a31a32d4b85a34" | ||
} |
@@ -32,2 +32,6 @@ /** | ||
userState?: T; | ||
/** | ||
* Path to Redirect after logging in | ||
*/ | ||
navigateTo?: string; | ||
} | ||
@@ -34,0 +38,0 @@ /** |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
62985
1903
1
1