diff --git a/redux-auth-wrapper/index.d.ts b/redux-auth-wrapper/index.d.ts new file mode 100644 index 0000000000..ffde27da52 --- /dev/null +++ b/redux-auth-wrapper/index.d.ts @@ -0,0 +1,33 @@ +// Type definitions for redux-auth-wrapper 1.0 +// Project: https://github.com/mjrussell/redux-auth-wrapper +// Definitions by: Karol Janyst +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +import { ComponentClass, StatelessComponent, ReactType } from "react"; +import { Action } from "redux"; +import { Location } from "history"; + +type ComponentConstructor

= ComponentClass

| StatelessComponent

; + +interface InjectedProps { + authData?: AuthData; +} + +export interface AuthWrapperConfig { + allowRedirectBack?: boolean | ((location: Location, redirectPath: string) => boolean); + authenticatingSelector?: (state: State, ownProps?: Props) => boolean; + authSelector: (state: State, ownProps?: Props) => AuthData; + FailureComponent?: ReactType; + failureRedirectPath?: string | ((state: State, ownProps?: Props) => string); + LoadingComponent?: ReactType; + redirectQueryParamName?: string; + wrapperDisplayName?: string; + predicate?: (authData: AuthData) => boolean; + propMapper?: (ownProps: Props) => InjectedProps & Props; + redirectAction?: (...args: any[]) => Action; +} + +type AuthDecorator = (component: ComponentConstructor) => ComponentClass; + +export function UserAuthWrapper(config: AuthWrapperConfig): AuthDecorator; diff --git a/redux-auth-wrapper/package.json b/redux-auth-wrapper/package.json new file mode 100644 index 0000000000..36ce503807 --- /dev/null +++ b/redux-auth-wrapper/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "redux": "^3.6.0" + } +} diff --git a/redux-auth-wrapper/redux-auth-wrapper-tests.tsx b/redux-auth-wrapper/redux-auth-wrapper-tests.tsx new file mode 100644 index 0000000000..a6d363dc06 --- /dev/null +++ b/redux-auth-wrapper/redux-auth-wrapper-tests.tsx @@ -0,0 +1,28 @@ +import * as React from "react"; +import { StatelessComponent } from "react"; +import { UserAuthWrapper } from "redux-auth-wrapper"; + +const Auth = UserAuthWrapper({ + allowRedirectBack: true, + authenticatingSelector(state: any) { + return state.auth.loading + }, + authSelector(state: any) { + return state.auth + }, + FailureComponent: () => (

), + failureRedirectPath: "/401", + LoadingComponent: () => (
), + redirectAction: () => ({ type : "redirect" }), + redirectQueryParamName: "next", + predicate(authData: any) { + return authData.authorized + }, + wrapperDisplayName: "TestAuth" +}); + +export const TestAuthComponent: StatelessComponent = () => { + return (
); +}; + +const TestAuth = Auth(TestAuthComponent); diff --git a/redux-auth-wrapper/tsconfig.json b/redux-auth-wrapper/tsconfig.json new file mode 100644 index 0000000000..5aae706c27 --- /dev/null +++ b/redux-auth-wrapper/tsconfig.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": ["../"], + "paths": { + "history": ["history/v3"], + "history/*": ["history/v3/*"] + }, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "jsx": "react" + }, + "files": [ + "index.d.ts", + "redux-auth-wrapper-tests.tsx" + ] +} diff --git a/redux-auth-wrapper/tslint.json b/redux-auth-wrapper/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/redux-auth-wrapper/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" }