Added react-auth-kit (#47368)

* Added react-auth-kit

* fix: Not used file error

Signed-off-by: Arkadip Bhattacharya <in2arkadipb13@gmail.com>

* fix: TokenObject.d.ts not found

* del: Unused Test file

Signed-off-by: Arkadip Bhattacharya <in2arkadipb13@gmail.com>

* fix: Error of import

Signed-off-by: Arkadip Bhattacharya <in2arkadipb13@gmail.com>

* fix: Errors on AuthProvier and HOCs

Signed-off-by: Arkadip Bhattacharya <in2arkadipb13@gmail.com>

* fix:  prefer-declare-function errors

Signed-off-by: Arkadip Bhattacharya <in2arkadipb13@gmail.com>

* removed: utility types

Signed-off-by: Arkadip Bhattacharya <in2arkadipb13@gmail.com>

* fix: Higher order components errors

Signed-off-by: Arkadip Bhattacharya <in2arkadipb13@gmail.com>

* fix: New line

Signed-off-by: Arkadip Bhattacharya <in2arkadipb13@gmail.com>

* deleted: not needed files and test file

Signed-off-by: Arkadip Bhattacharya <in2arkadipb13@gmail.com>

* fix: tsconfig error

Signed-off-by: Arkadip Bhattacharya <in2arkadipb13@gmail.com>
This commit is contained in:
Arkadip Bhattacharya 2020-09-11 21:22:58 +05:30 committed by GitHub
parent 7e6e8a9284
commit 8f5c2db8f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 151 additions and 0 deletions

31
types/react-auth-kit/AuthProvider.d.ts vendored Normal file
View File

@ -0,0 +1,31 @@
import * as React from 'react';
import { TokenInterface, TokenObjectParamsInterface } from "./types";
interface AuthProviderProps extends TokenObjectParamsInterface {
children: React.ReactChildren;
}
/**
* AuthContextInterface
*
* authState - Stores the value of authentication State
* setAuthState - Sets the authState Value
*/
interface AuthContextInterface {
authState: TokenInterface;
setAuthState: React.Dispatch<React.SetStateAction<TokenInterface>>;
}
declare const AuthContext: React.Context<AuthContextInterface | null>;
/**
* AuthProvider - The Authentication Context Provider
*
* @param children
* @param authStorageName
* @param authStorageType
* @param authTimeStorageName
* @param cookieDomain
* @param cookieSecure
* @param stateStorageName
*/
declare const AuthProvider: React.FunctionComponent<AuthProviderProps>;
export default AuthProvider;
declare const AuthContextConsumer: React.Consumer<AuthContextInterface | null>;
export { AuthContext, AuthContextConsumer };

16
types/react-auth-kit/PrivateRoute.d.ts vendored Normal file
View File

@ -0,0 +1,16 @@
import * as React from 'react';
import { RouteProps } from 'react-router-dom';
interface PrivateRouteProps extends RouteProps {
loginPath: string;
}
/**
* Private Route for Components
*
* @remarks
* This Component is based on {@link https://reactrouter.com/web/api/Route | reactrouter.Route}.
* So you need to install react-route-dom before use it
*
* @param props
*/
declare const PrivateRoute: React.FunctionComponent<PrivateRouteProps>;
export default PrivateRoute;

View File

@ -0,0 +1,6 @@
import * as React from 'react';
interface withAuthProps {
authState: object | null;
}
declare function withAuth<P extends withAuthProps>(Component: React.ComponentType<P>): React.FC<P>;
export default withAuth;

View File

@ -0,0 +1,6 @@
import * as React from 'react';
interface withAuthHeaderProps {
authHeader: string;
}
declare function withAuthHeader<P extends withAuthHeaderProps>(Component: React.ComponentType<P>): React.FC<P>;
export default withAuthHeader;

View File

@ -0,0 +1,7 @@
import * as React from 'react';
import { signInFunctionParams } from "../types";
interface withSignInProps {
signIn(params: signInFunctionParams): boolean;
}
declare function withSignIn<P extends withSignInProps>(Component: React.ComponentType<P>): React.FC<P>;
export default withSignIn;

View File

@ -0,0 +1,6 @@
import * as React from 'react';
interface withSignOutProps {
signOut(): boolean;
}
declare function withSignOut<P extends withSignOutProps>(Component: React.ComponentType<P>): React.FC<P>;
export default withSignOut;

View File

@ -0,0 +1,8 @@
import { TokenInterface } from "../types";
/**
* Auth State Hook
*
* @returns - Auth State Function
*/
declare function useAuth(): () => TokenInterface;
export default useAuth;

View File

@ -0,0 +1,2 @@
declare function useAuthHeader(): () => (string);
export default useAuthHeader;

View File

@ -0,0 +1,8 @@
import { signInFunctionParams } from "../types";
/**
* Authentication SignIn Hook
*
* @returns - Sign In function
*/
declare function useSignIn(): ({ token, authState, expiresIn, tokenType }: signInFunctionParams) => boolean;
export default useSignIn;

View File

@ -0,0 +1,2 @@
declare function useSignOut(): () => (boolean);
export default useSignOut;

16
types/react-auth-kit/index.d.ts vendored Normal file
View File

@ -0,0 +1,16 @@
// Type definitions for react-auth-kit 1.1
// Project: https://github.com/react-auth-kit/react-auth-kit#readme
// Definitions by: Arkadip Bhattacharya <https://github.com/darkmatter18>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import AuthProvider from './AuthProvider';
import PrivateRoute from './PrivateRoute';
import useSignIn from './hooks/useSignIn';
import useSignOut from './hooks/useSignOut';
import useAuth from './hooks/useAuth';
import useAuthHeader from './hooks/useAuthHeader';
import withAuth from './higherOrderComponents/withAuth';
import withAuthHeader from './higherOrderComponents/withAuthHeader';
import withSignIn from './higherOrderComponents/withSignIn';
import withSignOut from './higherOrderComponents/withSignOut';
export { AuthProvider, PrivateRoute, useSignIn, useSignOut, useAuth, useAuthHeader, withAuth, withAuthHeader, withSignIn, withSignOut };

View File

@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

20
types/react-auth-kit/types.d.ts vendored Normal file
View File

@ -0,0 +1,20 @@
export interface TokenInterface {
authToken: string | null;
authTokenType: string | null;
expireAt: Date | null;
authState: object | null;
}
export interface signInFunctionParams {
token: string;
tokenType: string | 'Bearer';
expiresIn: number;
authState: object;
}
export interface TokenObjectParamsInterface {
authStorageType: 'cookie' | 'localstorage';
authStorageName: string;
authTimeStorageName: string;
stateStorageName: string;
cookieDomain?: string;
cookieSecure?: boolean;
}