Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-auth-kit

Package Overview
Dependencies
Maintainers
1
Versions
200
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-auth-kit - npm Package Compare versions

Comparing version 3.0.0-alpha.37 to 3.0.0-alpha.39

12

.eslintrc.js

@@ -15,7 +15,6 @@ module.exports = {

'parserOptions': {
'ecmaFeatures': {
'jsx': true,
},
'ecmaVersion': 12,
'sourceType': 'module',
'project': './tsconfig.test.json',
'tsconfigRootDir': __dirname,
'ecmaVersion': 2018,
'sourceType': 'module'
},

@@ -25,2 +24,3 @@ 'plugins': [

'@typescript-eslint',
'eslint-plugin-tsdoc'
],

@@ -32,3 +32,5 @@ 'settings': {

},
'rules': {
'tsdoc/syntax': 'warn',
'react/prop-types': 0,

@@ -35,0 +37,0 @@ 'react/display-name': 0,

@@ -1,11 +0,4 @@

/**
*
* @author Arkadip Bhattacharya <hi@arkadip.dev>
* @fileoverview Auth Store
* @copyright Arkadip Bhattacharya 2020
*
*/
import * as React from 'react';
import type { Context } from 'react';
import TokenObject from './RxTokenObject';
export declare const AuthKitContext: React.Context<TokenObject<unknown>>;
export declare const AuthKitContext: Context<TokenObject<unknown>>;
export default AuthKitContext;
"use strict";
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {

@@ -8,7 +7,5 @@ value: true

exports.default = exports.AuthKitContext = void 0;
var React = _interopRequireWildcard(require("react"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var _react = require("react");
function getContext() {
var context = React.createContext(null);
var context = (0, _react.createContext)(null);
if (process.env.NODE_ENV !== 'production') {

@@ -15,0 +12,0 @@ context.displayName = 'ReactAuthKit';

@@ -1,8 +0,1 @@

/**
*
* @author Arkadip Bhattacharya <hi@arkadip.dev>
* @fileoverview Auth Context Provider
* @copyright Arkadip Bhattacharya 2020
*
*/
import * as React from 'react';

@@ -15,7 +8,9 @@ import type { createStoreReturn } from './createStore';

/**
* Auth Kit Store
* Auth Kit Store.
*
* Create the store using the `createStore` function
*/
store: createStoreReturn<T>;
/**
* React Component
* React Component.
* Effectively your entine application

@@ -27,4 +22,18 @@ */

*
* @param param0
* @returns
* React Provider that includes React Auth Kit functionility in your React
* Application.
*
* @remarks
* Make sure you wrap your application as well as your router components in AuthProvider.
*
* AuthProvider should be your Top Most element so that if can work effectively
* throughout the application.
*
* @example
* ```jsx
*
* ```
*
*
* @returns React Functional component with React Auth Kit Recharged.
*/

@@ -31,0 +40,0 @@ declare function AuthProvider<T extends object>({ store, children, }: AuthProviderProps<T>): ReturnType<React.FC>;

@@ -14,4 +14,4 @@ "use strict";

var _jsxRuntime = require("react/jsx-runtime");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function AuthProvider(_ref) {

@@ -22,3 +22,3 @@ var store = _ref.store,

refresh = store.refresh;
if (!!refresh) {
if (refresh) {
(0, _hooks.useInterval)(function () {

@@ -33,3 +33,5 @@ var _tokenObject$value$au, _tokenObject$value$re;

tokenObject.set((0, _reducers.doRefresh)(result));
} else {}
} else {
tokenObject.set((0, _reducers.doSignOut)());
}
}).catch(function () {});

@@ -36,0 +38,0 @@ }, tokenObject.value.isSignIn ? refresh.interval : null);

@@ -0,15 +1,13 @@

import type { createRefreshParamInterface } from './types';
/**
*
* @author Arkadip Bhattacharya <hi@arkadip.dev>
* @fileoverview Refresh Token engine
* @copyright Arkadip Bhattacharya 2020
*
*/
import { createRefreshParamInterface } from './types';
/**
* @remarks
* This function doesn't really "do anything" at runtime,
* it's just help to organize the code base
* Use this function to create the refresh token system
*
* @param param - Parameters required for the refresh engine
* @returns Same params with added layer of safety net.
*/
declare function createRefresh<T>(param: createRefreshParamInterface<T>): createRefreshParamInterface<T>;
export default createRefresh;

@@ -7,5 +7,9 @@ "use strict";

exports.default = void 0;
var _errors = require("./errors");
function createRefresh(param) {
if (param.interval < 0) {
throw new _errors.AuthError('Refresh interval is a time in seconds and can\'t be a negative(-ve)' + ' number. Make sure you are using possitive number.');
}
return param;
}
var _default = exports.default = createRefresh;

@@ -1,15 +0,44 @@

import TokenObject from "./RxTokenObject";
import { createRefreshParamInterface } from "./types";
import TokenObject from './RxTokenObject';
import type { createRefreshParamInterface } from './types';
interface createStoreParam<T> {
/**
*
*/
authName: string;
/**
*
*/
authType: 'cookie' | 'localstorage';
/**
*
*/
refresh?: createRefreshParamInterface<T>;
/**
*
*/
cookieDomain?: string;
/**
*
*/
cookieSecure?: boolean;
}
/**
*
*/
export interface createStoreReturn<T> {
/**
*
*/
tokenObject: TokenObject<T>;
/**
*
*/
refresh?: createRefreshParamInterface<T>;
}
/**
*
* @param params
* @returns
*/
export default function createStore<T>(params: createStoreParam<T>): createStoreReturn<T>;
export {};

@@ -12,4 +12,4 @@ "use strict";

if (params.authType === 'cookie') {
if (!!!params.cookieDomain && !!!params.cookieSecure) {
throw new _errors.AuthError('authType \'cookie\' ' + 'requires \'cookieDomain\' and \'cookieSecure\' ' + 'props in AuthProvider');
if (!params.cookieDomain && !params.cookieSecure) {
throw new _errors.AuthError('authType \'cookie\' requires \'cookieDomain\'' + ' and \'cookieSecure\' props in AuthProvider');
}

@@ -16,0 +16,0 @@ }

/**
*
* @author Arkadip Bhattacharya <hi@arkadip.dev>
* @fileoverview Error file
* @copyright Arkadip Bhattacharya 2023
*
* Base Error Class for all the auth kit related errors.
*/
/**
* @class
* @name AuthError
* @extends Error
*
* General Auth kit error class
*/
export declare class AuthError extends Error {
/**
* @constructor
* @param message - Error message
*/
* @param message - Error Message to be shown to the developer.
*/
constructor(message: string);
}

@@ -1,26 +0,39 @@

/**
*
* @author Arkadip Bhattacharya <hi@arkadip.dev>
* @fileoverview Authentication header <Higher Order Component>
* @copyright Arkadip Bhattacharya 2020
*
*/
import * as React from 'react';
/**
* @interface withAuthHeaderProps
* Type of the properties, that are injected to the component
*/
interface withAuthHeaderProps {
/**
* The string which contains the auth header for the network requests
*
* Format: `type token`
*/
authHeader: string;
}
/**
* @public
* @function
* @name withAuthHeader
* @description Inject Authentication Header inside the Component's Prop
* @param Component - React Component
* @deprecated Higher-order components are not commonly used in
* modern React code, use Hooks instead
*
* React {@link https://legacy.reactjs.org/docs/higher-order-components.html | HOC} that injects the auth header into
* the class based component props
*
* **Format: `type token` (authType-space-authToken)**
*
* @example
* ```tsx
* class MyComponent extends React.Component {
* render() {
* return <h1>Hello, {this.props.authHeader}</h1>;
* }
* }
* export default withAuthHeader(MyComponent);
* ```
*
* @throws AuthError
* Thrown if the Hook is used outside the Provider Scope.
*
* @param Component - React Class based Component
* @returns React Higher Order Component with injected `authHeader` proe
*/
declare function withAuthHeader<P extends withAuthHeaderProps>(Component: React.ComponentType<P>): React.FunctionComponent<P>;
/**
*@exports withAuthHeader
*/
export default withAuthHeader;

@@ -15,4 +15,4 @@ "use strict";

var _jsxRuntime = require("react/jsx-runtime");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }

@@ -23,3 +23,3 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }

if (c === null) {
throw new _errors.AuthError('Auth Provider is missing. ' + 'Please add the AuthProvider before Router');
throw new _errors.AuthError('Auth Provider is missing. ' + 'Make sure, you are using this component inside the auth provider.');
}

@@ -26,0 +26,0 @@ var value = c.value;

@@ -0,25 +1,43 @@

import * as React from 'react';
/**
* Type of the React props, that are injected to the component
*
* @author Arkadip Bhattacharya <hi@arkadip.dev>
* @fileoverview Authentication User <Higher Order Component>
* @copyright Arkadip Bhattacharya 2020
*
* @typeParam T - Type of User State Object
*/
import * as React from 'react';
/**
* @interface withAuthProps
*/
interface withAuthStateProps<T> {
/**
* State of the user provided on signin or refresh
*
* If the type is null then user may be not authenticated.
* Use `isAuthenticated` to verify
*/
authState: T | null;
}
/**
* @function
* @name withAuthUser
* @description Inject Authenticated User's state inside the Component's Prop
* @param Component
* @deprecated Higher-order components are not commonly used in
* modern React code, use Hooks instead
*
* React {@link https://legacy.reactjs.org/docs/higher-order-components.html | HOC} that injects the user state into
* the class based component props
*
* If the prop is null then user may be not authenticated.
* Use `isAuthenticated` to verify
*
* @example
* ```jsx
* class MyComponent extends React.Component {
* render() {
* return <h1>Hello, {this.props.authState}</h1>;
* }
* }
* export default withAuthUser(MyComponent);
* ```
*
* @throws AuthError
* Thrown if the Hook is used outside the Provider Scope.
*
* @param Component - React Class based Component
* @returns React Higher Order Component with injected `authState` prop
*/
declare function withAuthUser<T, P extends withAuthStateProps<T>>(Component: React.ComponentType<P>): React.FunctionComponent<P>;
/**
* @exports withAuthUser
*/
export default withAuthUser;

@@ -15,4 +15,4 @@ "use strict";

var _jsxRuntime = require("react/jsx-runtime");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }

@@ -23,3 +23,3 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }

if (c === null) {
throw new _errors.AuthError('Auth Provider is missing. ' + 'Please add the AuthProvider before Router');
throw new _errors.AuthError('Auth Provider is missing. ' + 'Make sure, you are using this component inside the auth provider.');
}

@@ -26,0 +26,0 @@ return function (props) {

@@ -1,23 +0,35 @@

/**
*
* @author Arkadip Bhattacharya <hi@arkadip.dev>
* @fileoverview Authentication Status <Higher Order Component>
* @copyright Arkadip Bhattacharya 2020
*
*/
import * as React from 'react';
/**
* @interface withAuthHeaderProps
* Type of the React props, that are injected to the component
*/
interface withAuthHeaderProps {
/**
* A boolean value indicating if the user is authenticated or not
*/
isAuth: boolean;
}
/**
* @public
* @function
* @name withIsAuthenticated
* @description Inject Authentication status inside the Component's Prop
* @param Component
* @deprecated Higher-order components are not commonly used in
* modern React code, use Hooks instead
*
* React {@link https://legacy.reactjs.org/docs/higher-order-components.html | HOC} that injects
* the authentication state into the class based component props
*
* @example
* ```jsx
* class MyComponent extends React.Component {
* render() {
* return <h1>Hello, {this.props.isAuth}</h1>;
* }
* }
* export default withIsAuthenticated(MyComponent);
* ```
*
* @throws AuthError
* Thrown if the Hook is used outside the Provider Scope.
*
* @param Component - React Class based Component
* @returns React Higher Order Component with injected `isAuth` prop
*/
declare function withIsAuthenticated<P extends withAuthHeaderProps>(Component: React.ComponentType<P>): React.FunctionComponent<P>;
export default withIsAuthenticated;

@@ -15,4 +15,4 @@ "use strict";

var _jsxRuntime = require("react/jsx-runtime");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }

@@ -23,3 +23,3 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }

if (c === null) {
throw new _errors.AuthError('Auth Provider is missing. ' + 'Please add the AuthProvider before Router');
throw new _errors.AuthError('Auth Provider is missing. ' + 'Make sure, you are using this component inside the auth provider.');
}

@@ -26,0 +26,0 @@ return function (props) {

@@ -1,24 +0,71 @@

/**
*
* @author Arkadip Bhattacharya <hi@arkadip.dev>
* @fileoverview Sign In functionality <Higher Order Component>
* @copyright Arkadip Bhattacharya 2020
*
*/
import * as React from 'react';
import { signInFunctionParams } from '../types';
/**
* @interface withSignInProps
* Type of the React props, that are injected to the component
*/
interface withSignInProps<T> {
/**
*
* Sign in Function, that signs in the user
*
* @param signInConfig - @param signInConfig - Parameters to perform sign in
* ```js
* {
* auth: {
* token: '<jwt token>'
* },
* userState: {name: 'React User', uid: 123456},
* refresh: <refresh jwt token>
* }
* ```
*/
signIn(signInConfig: signInFunctionParams<T>): boolean;
}
/**
* @public
* @function
* @name withSignIn
* @description Inject sign in functionality inside the Component's Prop
* @param Component
* @deprecated Higher-order components are not commonly used in
* modern React code, use Hooks instead
*
* React {@link https://legacy.reactjs.org/docs/higher-order-components.html | HOC} that injects
* the `signIn` function into the class based component props.
*
* Call the `signIn` function in the prop
* to sign In and authenticate the user
*
* This will authenticate the user by writing the uer state into the mamory
* Also, this will call the rx engine to store the auth into into the storage
*
* @example
* Here is an example without refresh token:
* ```jsx
* class MyComponent extends React.Component {
* this.props.signIn({
* auth: {
* token: '<jwt token>'
* },
* userState: {name: 'React User', uid: 123456}
* })
* }
* export default withSignIn(MyComponent);
* ```
*
* Here is an example with refresh token:
* ```jsx
* class MyComponent extends React.Component {
* this.props.signIn({
* auth: {
* token: '<jwt token>'
* },
* userState: {name: 'React User', uid: 123456},
* refresh: <refresh jwt token>
* }),
* }
* export default withSignIn(MyComponent);
* ```
*
* @typeParam T - Type of User State Object
*
* @param Component - React Class based Component
* @returns React Higher Order Component with injected `signIn` prop
*/
declare function withSignIn<T, P extends withSignInProps<T>>(Component: React.ComponentType<P>): React.FunctionComponent<P>;
export default withSignIn;

@@ -15,4 +15,4 @@ "use strict";

var _jsxRuntime = require("react/jsx-runtime");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }

@@ -23,15 +23,15 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }

if (context === null) {
throw new _errors.AuthError('Auth Provider is missing. ' + 'Please add the AuthProvider before Router');
throw new _errors.AuthError('Auth Provider is missing. ' + 'Make sure, you are using this component inside the auth provider.');
}
var signIn = function signIn(signInConfig) {
if (context.value.isUsingRefreshToken) {
if (!!signInConfig.refresh) {
if (signInConfig.refresh) {
context.set((0, _reducers.doSignIn)(signInConfig));
return true;
} else {
throw new _errors.AuthError('Make sure you given "refreshToken" and ' + '"refreshTokenExpireIn" parameter');
throw new _errors.AuthError('This appication is using refresh token feature.' + ' So please include `refresh` param in the parameters');
}
} else {
if (!!signInConfig.refresh) {
throw new Error('The app doesn\'t implement \'refreshToken\' ' + 'feature.\nSo you have to implement refresh token feature ' + 'from \'AuthProvider\' before using it.');
if (signInConfig.refresh) {
throw new _errors.AuthError('This appication is not using refresh token feature.' + ' So please remove the `refresh` param in the parameters.' + ' In Case you want to use refresh token feature,' + ' make sure you added that while creating the store.');
} else {

@@ -38,0 +38,0 @@ context.set((0, _reducers.doSignIn)(signInConfig));

@@ -1,23 +0,43 @@

/**
*
* @author Arkadip Bhattacharya <hi@arkadip.dev>
* @fileoverview Sign Out functionality <Higher Order Component>
* @copyright Arkadip Bhattacharya 2020
*
*/
import * as React from 'react';
/**
* @interface withSignOutProps
* Type of the React props, that are injected to the component
*/
interface withSignOutProps {
/**
* Sign Out Function.
* Call this to signout the user
*/
signOut(): boolean;
}
/**
* @public
* @function
* @name withSignOut
* @description Inject sign Out functionality inside the Component's Prop
* @param Component
* @deprecated Higher-order components are not commonly used in
* modern React code, use Hooks instead
*
* React {@link https://legacy.reactjs.org/docs/higher-order-components.html | HOC} that injects
* the `signOut` function into the class based component props.
*
* Call the `signOut` function in the prop
* to sign out and delete all the auth state
*
* This will remove the authState from memory and
* also remove the stored data from cookie or localstorage
*
* @example
* Here's a simple example:
* ```js
* class MyComponent extends React.Component {
* this.props.signOut();
* ...
* }
* export default withSignOut(MyComponent);
* ```
* @remarks
* For Now, this hook doesn't redirects automatically.
* So one need to writw the redirect logic himself.
*
*
* @param Component - React Class based Component
* @returns React Higher Order Component with injected `signOut` prop
*/
declare function withSignOut<P extends withSignOutProps>(Component: React.ComponentType<P>): React.FunctionComponent<P>;
export default withSignOut;

@@ -15,4 +15,4 @@ "use strict";

var _jsxRuntime = require("react/jsx-runtime");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }

@@ -23,3 +23,3 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }

if (context === null) {
throw new _errors.AuthError('Auth Provider is missing. ' + 'Please add the AuthProvider before Router');
throw new _errors.AuthError('Auth Provider is missing. ' + 'Make sure, you are using this component inside the auth provider.');
}

@@ -26,0 +26,0 @@ var signOut = function signOut() {

/**
* Auth Header React Hook
*
* @author Arkadip Bhattacharya <hi@arkadip.dev>
* @fileoverview Authentication header <hook>
* @copyright Arkadip Bhattacharya 2020
* Call the hook,
* to get the auth header for network request
*
*/
/**
* **Format: `type token` (authType-space-authToken)**
*
* @example
* Here is a simple example
* ```jsx
* import useAuthHeader from 'react-auth-kit/hooks/useAuthHeader'
*
* const Component = () => {
* const authHeader = useAuthHeader();
* const headers = {
* 'Authorization': authHeader
* }
* // use the headers in the network request
* ...
* }
* ```
*
* @throws AuthError
* Thrown if the Hook is used outside the Provider Scope.
*
* @returns If the user is authenticated,
* then `'auth.type auth.token'` is returned.
* If the user is not authenticated, then `null` is ruturned.
*/
declare function useAuthHeader(): () => (string);
declare function useAuthHeader(): string | null;
export default useAuthHeader;
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {

@@ -9,22 +8,18 @@ value: true

exports.default = void 0;
var React = _interopRequireWildcard(require("react"));
var _react = require("react");
var _AuthContext = _interopRequireDefault(require("../AuthContext"));
var _errors = require("../errors");
var _utils = require("../utils/utils");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function useAuthHeader() {
var c = React.useContext(_AuthContext.default);
var c = (0, _react.useContext)(_AuthContext.default);
if (c === null) {
throw new _errors.AuthError('Auth Provider is missing. ' + 'Please add the AuthProvider before Router');
throw new _errors.AuthError('Auth Provider is missing. ' + 'Make sure, you are using this hook inside the auth provider.');
}
return function () {
var obj = c.value;
if (!!obj.auth && (0, _utils.isAuthenticated)(obj)) {
return "".concat(obj.auth.type, " ").concat(obj.auth.token);
} else {
return "";
}
};
var value = c.value;
if (!!value.auth && (0, _utils.isAuthenticated)(value)) {
return "".concat(value.auth.type, " ").concat(value.auth.token);
} else {
return null;
}
}
var _default = exports.default = useAuthHeader;
/**
* Auth User Data React Hook
*
* @author Arkadip Bhattacharya <hi@arkadip.dev>
* @fileoverview Authentication User <hook>
* @copyright Arkadip Bhattacharya 2020
* Call the hook,
* to get the authenticated user data into your React Component
*
*/
/**
* Auth State Hook
* This uses the context data to determine get the user data
*
* @returns - Auth State Function
* @typeParam T - Type of User State Object
*
* @example
* Here is the example for JavaScript
* ```js
* import useAuthUser from 'react-auth-kit/hooks/useAuthUser'
*
* const Component = () => {
* const authUser = useAuthUser()
* const name = authUser.name;
* const uuid = authUser.uuid;
* ...
* }
* ```
* Here is the example for TypeScript
* ```tsx
* import useAuthUser from 'react-auth-kit/hooks/useAuthUser'
*
* interface IUserData {
* name: string;
* uuid: string;
* };
*
* const Component = () => {
* const authUser = useAuthUser<IUserData>()
* const name = authUser.name;
* const uuid = authUser.uuid;
* ...
* }
* ```
*
* @throws AuthError
* Thrown if the Hook is used outside the Provider Scope.
*
* @returns React Hook with user state functionility.
* If the user is authenticated, then user data is returned.
* If the user is not authenticated, then `null` is ruturned.
*/
declare function useAuthUser<T>(): () => T | null;
declare function useAuthUser<T>(): T | null;
export default useAuthUser;
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {

@@ -9,21 +8,17 @@ value: true

exports.default = void 0;
var React = _interopRequireWildcard(require("react"));
var _react = require("react");
var _AuthContext = _interopRequireDefault(require("../AuthContext"));
var _errors = require("../errors");
var _utils = require("../utils/utils");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function useAuthUser() {
var context = React.useContext(_AuthContext.default);
var context = (0, _react.useContext)(_AuthContext.default);
if (context === null) {
throw new _errors.AuthError('Auth Provider is missing. ' + 'Please add the AuthProvider before Router');
throw new _errors.AuthError('Auth Provider is missing. ' + 'Make sure, you are using this hook inside the auth provider.');
}
return function () {
if ((0, _utils.isAuthenticated)(context.value)) {
return context.value.userState;
} else {
return null;
}
};
if ((0, _utils.isAuthenticated)(context.value)) {
return context.value.userState;
} else {
return null;
}
}
var _default = exports.default = useAuthUser;
/**
* Is Authenticated React Hook
*
* @author Arkadip Bhattacharya <hi@arkadip.dev>
* @fileoverview Authentication status <hook>
* @copyright Arkadip Bhattacharya 2020
* Call the hook to know if the user is authenticated or not
*
* This uses the context data to determine whether the user is authenticated
* or not.
*
* @example
* ```js
* import useSignIn from 'react-auth-kit/hooks/useSignIn'
*
* const Component = () => {
* const isAuthenticated = useIsAuthenticated()
* if (isAuthenticated()) {
* // user authenticated - do somthing
* }
* else {
* // user not authenticated
* }
* ```
*
* @throws AuthError
* Thrown if the Hook is used outside the Provider Scope.
*
* @returns React Hook with Authtication status Functionility.
*/
/**
*@function
*@name useIsAuthenticated
*@description check weather user is authenticated or not
*/
declare function useIsAuthenticated(): () => boolean;
/**
*@exports useIsAuthenticated
*/
export default useIsAuthenticated;
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {

@@ -9,12 +8,10 @@ value: true

exports.default = void 0;
var React = _interopRequireWildcard(require("react"));
var _react = require("react");
var _AuthContext = _interopRequireDefault(require("../AuthContext"));
var _errors = require("../errors");
var _utils = require("../utils/utils");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function useIsAuthenticated() {
var context = React.useContext(_AuthContext.default);
var context = (0, _react.useContext)(_AuthContext.default);
if (context === null) {
throw new _errors.AuthError('Auth Provider is missing. ' + 'Please add the AuthProvider before Router');
throw new _errors.AuthError('Auth Provider is missing. ' + 'Make sure, you are using this hook inside the auth provider.');
}

@@ -21,0 +18,0 @@ return function () {

@@ -0,20 +1,61 @@

import { signInFunctionParams } from '../types';
/**
* Sign In React Hook
*
* @author Arkadip Bhattacharya <hi@arkadip.dev>
* @fileoverview Sign In functionality <hook>
* @copyright Arkadip Bhattacharya 2020
* @license MIT
* Call the hook to sign In and authenticate the user
*
* This will authenticate the user by writing the uer state into the mamory
* Also, this will call the rx engine to store the auth into into the storage
*
* @typeParam T - Type of User State Object
*
* @example
* Here's a an example without refresh token:
* ```js
* import useSignIn from 'react-auth-kit/hooks/useSignIn'
*
* const LoginComponent = () => {
* const signIn = useSignIn()
* signIn({
* auth: {
* token: '<jwt token>'
* },
* userState: {name: 'React User', uid: 123456}
* })
* }
* ```
*
* Here's a an example with refresh token:
* ```js
* import useSignIn from 'react-auth-kit/hooks/useSignIn'
*
* const LoginComponent = () => {
* const signIn = useSignIn()
* signIn({
* auth: {
* token: '<jwt token>'
* },
* userState: {name: 'React User', uid: 123456},
* refresh: <refresh jwt token>
* })
* }
* ```
*
* @remarks
* If you are using refresh token, make sure you add that in the parameter,
* else it throws AuthError
*
* If you are not using refresh token, make sure you don't include
* that in the parameter, else it throws AuthError.
*
* @throws AuthError
* Thrown if the Hook is used outside the Provider Scope.
*
* Thrown if refresh token is added, in spite not used.
*
* Thrown if refresh token is not added, is spite used.
*
* @returns React Hook with SignIn Functionility
*/
import { signInFunctionParams } from '../types';
/**
*@function
*@name useSignIn
*@description Authentication SignIn Hook
*@returns - Sign In function
*/
declare function useSignIn<T>(): (signInConfig: signInFunctionParams<T>) => boolean;
/**
*@exports useSignIn
*/
export default useSignIn;
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {

@@ -9,31 +8,22 @@ value: true

exports.default = void 0;
var React = _interopRequireWildcard(require("react"));
var _react = require("react");
var _AuthContext = _interopRequireDefault(require("../AuthContext"));
var _reducers = require("../utils/reducers");
var _errors = require("../errors");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
/**
*
* @author Arkadip Bhattacharya <hi@arkadip.dev>
* @fileoverview Sign In functionality <hook>
* @copyright Arkadip Bhattacharya 2020
* @license MIT
*
*/function useSignIn() {
var context = React.useContext(_AuthContext.default);
function useSignIn() {
var context = (0, _react.useContext)(_AuthContext.default);
if (context === null) {
throw new _errors.AuthError('Auth Provider is missing. ' + 'Please add the AuthProvider before Router');
throw new _errors.AuthError('Auth Provider is missing. ' + 'Make sure, you are using this hook inside the auth provider.');
}
return function (signInConfig) {
if (context.value.isUsingRefreshToken) {
if (!!signInConfig.refresh) {
if (signInConfig.refresh) {
context.set((0, _reducers.doSignIn)(signInConfig));
return true;
} else {
throw new _errors.AuthError('Make sure you given "refreshToken" and ' + '"refreshTokenExpireIn" parameter');
throw new _errors.AuthError('This appication is using refresh token feature.' + ' So please include `refresh` param in the parameters');
}
} else {
if (!!signInConfig.refresh) {
throw new Error('The app doesn\'t implement \'refreshToken\' ' + 'feature.\nSo you have to implement refresh token feature ' + 'from \'AuthProvider\' before using it.');
if (signInConfig.refresh) {
throw new _errors.AuthError('This appication is not using refresh token feature.' + ' So please remove the `refresh` param in the parameters.' + ' In Case you want to use refresh token feature,' + ' make sure you added that while creating the store.');
} else {

@@ -40,0 +30,0 @@ context.set((0, _reducers.doSignIn)(signInConfig));

/**
* Sign Out React Hook
*
* @author Arkadip Bhattacharya <hi@arkadip.dev>
* @fileoverview Sign Out functionality <Hook>
* @copyright Arkadip Bhattacharya 2020
* Call the hook to sign out and delete all the auth state
*
* This will remove the authState from memory and
* also remove the stored data from cookie or localstorage
*
* @example
* Here's a simple example:
* ```js
* import useSignOut from 'react-auth-kit/hooks/useSignOut'
*
* const SecureComponent = () => {
* const signOut = useSignOut()
* return (
* <button onClick={() => signOut()}>Sign Out!</button>
* )
* }
* ```
* @remarks
* For Now, this hook doesn't redirects automatically.
* So one need to writw the redirect logic himself.
*
* ```js
* const signOut = useSignOut()
* signOut()
* navigate('/login')
* ```
*
* @throws AuthError
* Thrown if the Hook is used outside the Provider Scope
*
* @returns React Hook with SignOut Functionility
*/
/**
*@public
*@function
*@name useSignOut
*@description Sign out Hook
*/
declare function useSignOut(): () => (boolean);
/**
*@exports useSignOut
*/
export default useSignOut;
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {

@@ -9,12 +8,10 @@ value: true

exports.default = void 0;
var React = _interopRequireWildcard(require("react"));
var _react = require("react");
var _AuthContext = _interopRequireDefault(require("../AuthContext"));
var _errors = require("../errors");
var _reducers = require("../utils/reducers");
var _errors = require("../errors");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function useSignOut() {
var context = React.useContext(_AuthContext.default);
var context = (0, _react.useContext)(_AuthContext.default);
if (context === null) {
throw new _errors.AuthError('Auth Provider is missing. ' + 'Please add the AuthProvider before Router');
throw new _errors.AuthError('Auth Provider is missing. ' + 'Make sure, you are using this hook inside the auth provider.');
}

@@ -21,0 +18,0 @@ return function () {

/**
*
* @author Arkadip Bhattacharya <hi@arkadip.dev>
* @fileoverview Index (Main entry point)
* @copyright Arkadip Bhattacharya 2020
*
* Entry point of the Library.
*/

@@ -8,0 +4,0 @@ export type * from './types';

@@ -38,3 +38,3 @@ "use strict";

});
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
{
"name": "react-auth-kit",
"version": "3.0.0-alpha.37",
"version": "3.0.0-alpha.39",
"description": "Authentication Library for React, which makes Token based auth very easy",

@@ -50,3 +50,3 @@ "keywords": [

"test:unit": "jest --config ./config/jest.config.js",
"test:lint": "eslint src/**/*.ts src/**/*.tsx --fix",
"test:lint": "eslint src",
"test:unit:watch": "jest --watch"

@@ -68,9 +68,9 @@ },

"@types/js-cookie": "3.0.4",
"@types/node": "18.18.3",
"@types/react": "18.2.23",
"@types/react-dom": "18.2.8",
"@types/node": "20.9.0",
"@types/react": "18.2.28",
"@types/react-dom": "18.2.13",
"@types/react-router-dom": "5.3.3",
"@typescript-eslint/eslint-plugin": "6.7.4",
"@typescript-eslint/parser": "6.7.4",
"eslint": "8.50.0",
"@typescript-eslint/eslint-plugin": "6.8.0",
"@typescript-eslint/parser": "6.8.0",
"eslint": "8.53.0",
"eslint-config-google": "0.14.0",

@@ -92,3 +92,3 @@ "eslint-plugin-jest": "27.4.2",

},
"gitHead": "00001e54b177809bbd0e050f273428b8e087091b"
"gitHead": "4800976ec3d29d8b9ae6ed3c079f7359468406b9"
}

@@ -16,4 +16,4 @@ "use strict";

var _jsxRuntime = require("react/jsx-runtime");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
var RequireAuth = function RequireAuth(_ref) {

@@ -20,0 +20,0 @@ var children = _ref.children,

@@ -26,6 +26,6 @@ "use strict";

complete: () => {
console.log("Token Synced");
console.log('Token Synced');
},
error: err => {
console.error("Error Occured while syncing token");
console.error('Error Occured while syncing token');
console.log(err);

@@ -46,3 +46,3 @@ }

let obj = this.value;
if (!!data.auth) {
if (data.auth) {
let userState = obj.userState;

@@ -71,3 +71,3 @@ if (data.userState !== undefined) {

if (this.isUsingRefreshToken) {
if (!!data.refresh) {
if (data.refresh) {
obj = {

@@ -164,3 +164,3 @@ ...obj,

}
if (!!refresh) {
if (refresh) {
if (!!auth && !!authState) {

@@ -232,3 +232,3 @@ return {

syncTokens = authState => {
if (!!authState.auth) {
if (authState.auth) {
this.setAuthToken(authState.auth.token, authState.auth.type, authState.userState);

@@ -257,3 +257,3 @@ } else {

});
if (!!authState) {
if (authState) {
_jsCookie.default.set(this.stateStorageName, JSON.stringify(authState), {

@@ -268,3 +268,3 @@ expires: expiresAt,

window.localStorage.setItem(this.authStorageTypeName, authTokenType);
if (!!authState) {
if (authState) {
window.localStorage.setItem(this.stateStorageName, JSON.stringify(authState));

@@ -271,0 +271,0 @@ }

@@ -1,12 +0,13 @@

import * as React from 'react';
import type { MutableRefObject } from 'react';
/**
* React useInterval Hook
* Used to integrate the power of setInterval seamlessly
*
* @param callback - The callback function
* @param delay - The amount of delay in minutes.
* React Hook to use the `setInterval` in the component
*
* @returns the ref of setInterval
* @internal
*
* @param callback - The function that will be called on each interval
* @param delay - The delay on which the callback function is called
* @returns - The Reference of the `setInterval` function
*/
declare function useInterval(callback: () => void, delay: number | null): React.MutableRefObject<number | null>;
declare function useInterval(callback: () => void, delay: number | null): MutableRefObject<number | null>;
export { useInterval };

@@ -7,12 +7,10 @@ "use strict";

exports.useInterval = useInterval;
var React = _interopRequireWildcard(require("react"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var _react = require("react");
function useInterval(callback, delay) {
const savedCallback = React.useRef(callback);
const intervalRef = React.useRef(null);
React.useEffect(() => {
const savedCallback = (0, _react.useRef)(callback);
const intervalRef = (0, _react.useRef)(null);
(0, _react.useEffect)(() => {
savedCallback.current = callback;
}, [callback]);
React.useEffect(() => {
(0, _react.useEffect)(() => {
const tick = () => savedCallback.current();

@@ -19,0 +17,0 @@ if (typeof delay === 'number') {

@@ -0,15 +1,83 @@

/**
* @packageDocumentation
*
* Reducer Module
*
* It contains all the reducers
*
* @remarks
* A reducer is a function that takes input from the user
* and converts to the actual state object,
* that can be processed by React Auth Kit state system.
*
*/
import { AuthKitSetState, SignInActionPayload, RefreshTokenActionPayload } from '../types';
/**
* used to make sign in
* @param signInParams
* Do Sign In reducer.
* It is used to convert the incoming payload into
* the specified format for the auth state.
* It doesn't contains any important buisness logic.
*
* @remarks
* - If the `auth.type` is not set, then by default it is set as `Bearer`
* - If the `userState` is not set, then by default it is `{}` (an empty object)
*
* @param signInParams - Sign in parameters
* @returns Object that is modified to auth state to used further
*
* @internal
*
* @typeParam T - Type of User State Object
*
*/
export declare function doSignIn<T>(signInParams: SignInActionPayload<T>): AuthKitSetState<T>;
/**
* used to refresh the Token
* @param refreshTokenParam
* Do refresh reducer
* When the token is refrshed,
* this reducer is used to convert the incoming data from
* the refresh token functionality.
*
* @remarks
*
* Here is the internal decision graph
* ```
* refreshTokenParam
* |
* |-- new auth token -------------------------> Update the auth data
* | |
* | |
* | |-- new user state -----> Add user state in
* | | the updated auth data
* | |
* | |-- new refresh token --> Add new refresh token in
* | the updated auth state
* |
* |-- No auth token only refresh token -------> Update the refresh token
* |
* |
* --- No auth token and refresh token --------> Make everything Null
* ```
*
* @param refreshTokenParam - Parameters set by the
* refresh token called
* @returns Object that is modified to auth state to used
* further to set the refreshed auth states
*
* @internal
*
* @typeParam T - Type of User State Object
*/
export declare function doRefresh<T>(refreshTokenParam: RefreshTokenActionPayload<T>): AuthKitSetState<T>;
/**
* Used to make sign out
* Do sign out reducer
* Called Internally to make the auth state signed out
*
* @returns Object that is modified to be used further to
* update the auth state to make it signed out
*
* @internal
*
* @typeParam T - Type of User State Object
*
*/
export declare function doSignOut<T>(): AuthKitSetState<T>;

@@ -10,3 +10,3 @@ "use strict";

function doSignIn(signInParams) {
const authType = !!signInParams.auth.type ? signInParams.auth.type : 'Bearer';
const authType = signInParams.auth.type ? signInParams.auth.type : 'Bearer';
const authToken = signInParams.auth.token;

@@ -23,10 +23,10 @@ return {

function doRefresh(refreshTokenParam) {
if (!!refreshTokenParam.newAuthToken) {
if (refreshTokenParam.newAuthToken) {
let ret = {
auth: {
token: refreshTokenParam.newAuthToken,
type: !!refreshTokenParam.newAuthTokenType ? refreshTokenParam.newAuthTokenType : 'Bearer'
type: refreshTokenParam.newAuthTokenType ? refreshTokenParam.newAuthTokenType : 'Bearer'
}
};
if (!!refreshTokenParam.newAuthUserState) {
if (refreshTokenParam.newAuthUserState) {
ret = {

@@ -37,3 +37,3 @@ ...ret,

}
if (!!refreshTokenParam.newRefreshToken) {
if (refreshTokenParam.newRefreshToken) {
ret = {

@@ -45,4 +45,4 @@ ...ret,

return ret;
} else if (!!refreshTokenParam.newRefreshToken) {
let ret = {
} else if (refreshTokenParam.newRefreshToken) {
const ret = {
refresh: refreshTokenParam.newRefreshToken

@@ -49,0 +49,0 @@ };

@@ -0,13 +1,20 @@

/**
* @packageDocumentation
*
* Utility Module
*
* It contains all the utility functions
*
*/
import { AuthKitStateInterface } from '../types';
/**
*@function
*@name isAuthenticated
*@description A utility function to check
* weather the auth state is justified as athenticated
* or not
*
* It checks if the state in null or not,
* It the state is not NULL, it checks the expires time.
*/
*
* @param auth - The Auth Object
* @returns A boolean value indicting if currently authenticated or not
*
* @internal
*
* @typeParam T - Type of User State Object
*/
declare function isAuthenticated<T>(auth: AuthKitStateInterface<T>): boolean;
export { isAuthenticated };

@@ -8,3 +8,3 @@ "use strict";

function isAuthenticated(auth) {
if (!!auth.auth) {
if (auth.auth) {
return new Date(auth.auth.expiresAt) > new Date();

@@ -11,0 +11,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc