whodis-react
Version:
React hooks and components for secure, best practices authentication in seconds
21 lines • 961 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.useAuthenticationClaims = void 0;
const react_1 = require("react");
const AuthenticationContext_1 = require("./AuthenticationContext");
/**
* react hook which exposes the unauthenticated claims of the users authenticatable token
*
* for imperative usage - see the `getAuthentication` method
*/
const useAuthenticationClaims = () => {
// grab the token from the context
const context = (0, react_1.useContext)(AuthenticationContext_1.AuthenticationContext);
if (!context)
throw new Error('AuthenticationContext was not initialized. Was the AuthenticationProvider used?'); // fail fast, to help in dev - since this is an issue that would only arise in dev
const { claims } = context;
// expose the public contract
return claims;
};
exports.useAuthenticationClaims = useAuthenticationClaims;
//# sourceMappingURL=useAuthenticationClaims.js.map